xpages不同数据库共享ssjs
来源:互联网 发布:淘宝效果评估 编辑:程序博客网 时间:2024/05/22 15:31
如果在xpages不同的数据库可以共享ssjs就方便了,类似于前端的js一样,这是以前的想法。最近在网上真的看到这篇类似文章,以下是做个简单的demo,有时间交流:QQ 873968102
demo下载
0)这里是原文
http://hasse
1)引用java类
package ch.hasselba.xpages.util.ssjs;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import com.ibm.xsp.util.StreamUtil;import com.ibm.xsp.page.compiled.ExpressionEvaluatorImpl;import javax.faces.context.FacesContext;import javax.faces.el.ValueBinding;public class SSJSUtil {private static final String NEWLINE = "\n"; private static final String SSJS_EXPRESSION_BEGIN = "#{javascript:"; private static final String SSJS_EXPRESSION_END = "}"; /** * Loads SSJS code from a given URL and executes it * Declared methods and objects are reachable for other SSJS code * * @param url of the SSJS code * @return Object resulting object from SSJS execution * @author Sven Hasselbach * @version 1.0.1 * @category Utility */ public static Object executeSSJSFromURL( final String url ){ return execute( loadFromURL( url ) ); } /** * loads a URL stream and converts it to a string * @param url of the resource * @return String containing the data loaded from given url * @author Sven Hasselbach * @version 1.0.1 * @category Utility */ public static String loadFromURL( final String url ){ String ret = null; try{ FacesContext fc = FacesContext.getCurrentInstance(); InputStream in = StreamUtil.getInputStream(fc, url); ret = inputStreamToString( in ); }catch(Exception e){ e.printStackTrace(); } return ret; } /** * executes given SSJS code and returns the result (if any) * functions / libraries are added to runtime * * @param ssjsCode code to execute * @return resulting object * @author Sven Hasselbach * @version 1.0.2 * @category SSJS */ public static Object execute( final String ssjsCode ){ Object ret = null; try{ String valueExpr = SSJS_EXPRESSION_BEGIN + ssjsCode + SSJS_EXPRESSION_END; FacesContext fc = FacesContext.getCurrentInstance(); ExpressionEvaluatorImpl evaluator = new ExpressionEvaluatorImpl( fc ); ValueBinding vb = evaluator.createValueBinding( fc.getViewRoot(), valueExpr, null, null); ret = vb.getValue(fc); }catch(Exception e){ e.printStackTrace(); } return ret; } /** * converts the data from a given inputstream to a string * * @param in InputStream to convert * @return String containing data from input stream * @throws IOException * @author Sven Hasselbach * @version 1.0.1 * @category Utility */ public static String inputStreamToString(final InputStream inStream) throws IOException { BufferedReader bufReader = new BufferedReader( new InputStreamReader(inStream) ); StringBuilder strBuilder = new StringBuilder(); String line = null; while ((line = bufReader.readLine()) != null) { strBuilder.append(line); strBuilder.append( NEWLINE ); } bufReader.close(); return strBuilder.toString(); }}
2)写个ssjs放到html路径下面
function test(){return "I am a ssjs test";}function hello(){return 'hello world!'}function geturl(){return context.getUrl();}
3)在xpages页面引用
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"><xp:label id="label1"><xp:this.value><![CDATA[#{javascript:importPackage( ch.hasselba.xpages.util.ssjs );var url=@Left(context.getUrl(),context.getUrl().getPath())+'/873968102.jss';SSJSUtil.executeSSJSFromURL(url);test(); }]]></xp:this.value></xp:label><xp:br></xp:br><xp:label id="label2"><xp:this.value><![CDATA[#{javascript://SSJSUtil.executeSSJSFromURL(url);hello(); }]]></xp:this.value></xp:label><xp:br></xp:br><xp:br></xp:br><xp:br></xp:br><xp:inputText id="inputText1" defaultValue="#{javascript:geturl();}"style="width:364.0px"></xp:inputText></xp:view>
0 0
- xpages不同数据库共享ssjs
- 局域网内不同主机之间实现数据库共享
- ssjs-记录-1
- 利用WebService实现远程数据库存取及不同站点间共享同一数据库
- XPages 揭秘
- 数据库共享
- 共享数据库
- 利用微软WebService技术实现远程数据库存取 利用web服务在不同站点间共享同一数据库
- 利用微软WebService技术实现远程数据库存取 利用web服务在不同站点间共享同一数据库
- 利用微软WebService技术实现远程数据库存取 利用web服务在不同站点间共享同一数据库
- 利用微软WebService技术实现远程数据库存取 利用web服务在不同站点间共享同一数据库
- 利用微软WebService技术实现远程数据库存取 利用web服务在不同站点间共享同一数据库
- 利用微软WebService技术实现远程数据库存取 利用web服务在不同站点间共享同一数据库
- 不同路由器不同局域网共享打印机
- 不同App共享KeyChain数据
- 不同App共享KeyChain数据
- 不同进程之间共享内存
- 不同网段实现打印机共享
- JavaScript
- R语言的igraph画社交关系图示例
- java多线程-常用方法
- eviews 9.5新版本——平均预测、面板效应检验
- AndroidAnnotation常用注解使用说明
- xpages不同数据库共享ssjs
- 303. Range Sum Query - Immutable
- Codeforces Round #352 (Div. 2) C D
- 白书学习之隐式图搜索之八数码问题
- 算法例题-求输入一个整数,输出对应二进制中1的个数。
- Scroller的工作原理概括
- 数据库表连接之左连接(LEFT JOIN)、右连接(RIGHT JOIN)和内连接(INNER JOIN)
- 第一次写博客,试试水吧,哈哈
- PAT乙级—1015. 德才论 (25)-native