SSJS中getComponent()的Java等价物
我知道我们可以在Java中访问像这样的XPages全局对象SSJS中getComponent()的Java等价物,java,xpages,Java,Xpages,我知道我们可以在Java中访问像这样的XPages全局对象 FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); ... ... 但我找不到使用getComponent的任何等价物是Java。Java中是否有类似于SSJS中getComponent的类或方法?在Java中评估SSJS可能
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
...
...
但我找不到使用getComponent的任何等价物是Java。Java中是否有类似于SSJS中getComponent的类或方法?在Java中评估SSJS可能最简单。来自Sven的代码:
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);
下面是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;
}
在扩展库的组扩展中,有一个包含XspQuery类和一些过滤器的查询包。该类的功能类似于dojo.query,为您提供多种查找组件的方法,不仅通过id,还可以通过组件类、客户机id、服务器id等。下面是使用服务器id查找组件的示例:
XspQuery query = new XspQuery();
query.byId("someId");
List<UIComponent> componentList = query.locate();
你可以在这里找到它:
组扩展从未随扩展库一起分发,而是在svn存储库中,要获得它,您必须通过OpenNTF svn服务器。Karsten的代码和SSJS中的GetCompent方法之间存在不同的行为:Karsten的代码从顶部组件向下搜索组件,SSJS中的“getComponent*方法”是否执行从当前组件向上的搜索。这可能会导致不同的结果。我不确定如果在方面中使用该方法会发生什么,我会选择在Java中评估SSJS,因为它更好,并且只需要几行代码就可以完成这项工作。谢谢你,保罗@SvenHasselbach:我在XPage的querySaveDocument事件中使用getComponent等价物,并在该场景中评估Paul在Java中的SSJS选项。也许在某些领域使用它可能会产生不同的结果。但我还没试过。谢谢你的建议。我如何在我的Lotus Notes中安装组扩展?不幸的是,你必须通过OpenNTF SVN服务器才能获得整个插件。或者,如果您只需要XspQuery类,则可以从XBlog模板或。我还致力于将组插件的好部分放入Tim Tripcony的OpenNTF扩展库,而不是IBM扩展库。那里的大多数组件已经添加到IBMExtLib中,但是XspQuery从未添加回产品中。谢谢!我会研究: