XPage extlib oneui layout - 如何动态添加placebar动作

时间:2012-08-13 17:33:15

标签: xpages xpages-extlib

我想在PlaceBar中动态添加动作(extlib oneui应用程序布局)。

我们在一些配置文档中存储了几个url。基于这些URL,我想创建其中包含Basic Child节点的Container节点。每个子节点都使用列表中的一个URL。 我如何创建容器节点并动态添加子节点?任何样本的SSJS / Java / CSJS代码?

谢谢..

4 个答案:

答案 0 :(得分:4)

查看重复节点(xe:repeatTreeNode),该页面将在XPages Extension Library一书中介绍。

这是一个非常简单的例子(直接来自本书):

<xe:repeatTreeNode var="val">
   <xe:this.value>
      <![CDATA[#{javascript:return [
        ["Home","home"],
        ["Domino","domino"],
        ["OneUI","oneui"]
      ];}]]>
   </xe:this.value>
   <xe:this.children>
      <xe:basicLeafNode>
         <xe:this.submitValue><![CDATA[#{javascript:return val[1]}]]></xe:this.submitValue>
         <xe:this.label><![CDATA[#{javascript:return val[0]}]]></xe:this.label>
      </xe:basicLeafNode>
   </xe:this.children>
</xe:repeatTreeNode>

答案 1 :(得分:1)

感谢您的快速回复。这对我来说非常有用。

我发现基于XSnippet代码和一些反向工具的另一种方式。来自xpage中的java代码如下:

var oneui = getComponent("applicationLayout1");
var uiConfig = oneui.getConfiguration();
var containerNode:com.ibm.xsp.extlib.tree.complex.ComplexContainerTreeNode = new com.ibm.xsp.extlib.tree.complex.ComplexContainerTreeNode();
containerNode.setLabel("Cluster Applications");

var docAppProfile = docColl.getFirstDocument();
while(docAppProfile != null)
{
    var children:com.ibm.xsp.extlib.tree.complex.ComplexLeafTreeNode = new com.ibm.xsp.extlib.tree.complex.ComplexLeafTreeNode();
    children.setComponent(oneui);
    children.setLabel(docAppProfile.getItemValueString("appTitle"));
    children.setHref(docAppProfile.getItemValueString("appURL"));
    children.setImage(docAppProfile.getItemValueString("appLogoThumb"));
    containerNode.addChild(children);

    children = null;
    var tempDoc = docColl.getNextDocument(docAppProfile);
    docAppProfile = null;
    docAppProfile = tempDoc;
}
uiConfig.addPlaceBarAction(containerNode);

这只是示例代码。将其转换为java代码并进行序列化以提高性能并在应用程序中仅加载一次。

再次感谢您的帮助。

答案 2 :(得分:1)

基本上与上面列出的代码相同,但是在Java中。然后是faces-config.xml文件中的这个小代码

<lifecycle>
    <phase-listener>com.company.app.phaselisteners.PlaceBarInjector</phase-listener>
</lifecycle>

package com.company.app.phaselisteners;





public class PlaceBarInjector implements PhaseListener {

      private static final long serialVersionUID = 1L;

      public PhaseId getPhaseId() {
        return PhaseId.RENDER_RESPONSE;
    }

    public void beforePhase(PhaseEvent event) {
        UIComponent oneui = JSFUtil.findComponent("applicationLayout1");
    Configruation uiconfig = oneui.getConfiguration();
    ComplexContainerTreeNode containerNode = new ComplexContainerTreeNode();
    containerNode.setLabel("Cluster Applications");

    Document docAppProfile = docColl.getFirstDocument();
    while(docAppProfile != null)
    {
            ComplexLeafTreeNode children = new ComplexLeafTreeNode();
            children.setComponent(oneui);
            children.setLabel(docAppProfile.getItemValueString("appTitle"));
        children.setHref(docAppProfile.getItemValueString("appURL"));
            children.setImage(docAppProfile.getItemValueString("appLogoThumb"));
            containerNode.addChild(children);

            Document tempDoc = docColl.getNextDocument(docAppProfile);
            docAppProfile = tempDoc;
    }
    uiConfig.addPlaceBarAction(containerNode);
    }

    public void afterPhase(PhaseEvent event) {
        System.out.println("END PHASE " + event.getPhaseId());
    }

}

答案 3 :(得分:0)

您可以做的另一件事是使用PhaseListener在呈现响应之前将Items注入Container节点。然后,您可以在一个地方为所有页面控制它。