0

我知道我们可以在 Java 中像这样访问 XPages 全局对象

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
...
...

但我找不到任何等效的使用getComponent()是 Java。getComponent()Java中是否有与SSJS相似的类或方法?

4

2 回答 2

5

在 Java 中评估 SSJS 可能是最简单的。斯文的代码:

String valueExpr = "#{javascript: getComponent('xxx').getValue();}";
FacesContext fc = FacesContext.getCurrentInstance();
ExpressionEvaluatorImpl evaluator = new ExpressionEvaluatorImpl( fc );
ValueBinding vb = evaluator.createValueBinding( fc.getViewRoot(), valueExpr, null, null);
vreslt = (String) vb.getValue(fc);

如何从 Java Bean 调用临时 SSJS

这是 Karsten Lehmann 的纯 Java 解决方案:

/** 
 * Finds an UIComponent by its component identifier in the current 
 * component tree. 
 * 
 * @param compId the component identifier to search for 
 * @return found UIComponent or null 
 * 
 * @throws NullPointerException if <code>compId</code> is null 
 */ 
public static UIComponent findComponent(String compId) { 
    return findComponent(FacesContext.getCurrentInstance().getViewRoot(), compId); 
} 

/** 
 * Finds an UIComponent by its component identifier in the component tree 
 * below the specified <code>topComponent</code> top component. 
 * 
 * @param topComponent first component to be checked 
 * @param compId the component identifier to search for 
 * @return found UIComponent or null 
 * 
 * @throws NullPointerException if <code>compId</code> is null 
 */ 
public static UIComponent findComponent(UIComponent topComponent, String compId) { 
    if (compId==null) 
        throw new NullPointerException("Component identifier cannot be null"); 

    if (compId.equals(topComponent.getId())) 
        return topComponent; 

    if (topComponent.getChildCount()>0) { 
        List childComponents=topComponent.getChildren(); 

        for (UIComponent currChildComponent : childComponents) { 
            UIComponent foundComponent=findComponent(currChildComponent, compId); 
            if (foundComponent!=null) 
                return foundComponent; 
        } 
    } 
    return null; 
} 

http://www.mindoo.com/web/blog.nsf/dx/18.07.2009191738KLENAL.htm

于 2013-01-25T17:38:21.750 回答
2

在扩展库的组扩展中有一个查询包,其中包含 XspQuery 类和一些过滤器。此类旨在像 dojo.query 一样为您提供许多不同的方法来查找组件,不仅通过 id,还通过 Component Class、Client ID、Server ID 等。这是使用服务器 ID 的示例定位一个组件:

XspQuery query = new XspQuery();
query.byId("someId");
List<UIComponent> componentList = query.locate();

你可以在这里找到它:https ://svn-166.openntf.org/svn/xpages/extlib/eclipse/plugins/com.ibm.xsp.extlib.group/src/com/ibm/xsp/extlib/query/

Group 扩展从未与扩展库一起分发,而是在 svn 存储库中,要获得它,您必须通过 OpenNTF svn 服务器。

于 2013-01-26T15:04:12.583 回答