Nested Expression Language Syntax in XPages

2019-09-07 01:18发布

I'm refactoring an XPage which mimics the Notes Client discussion database. (Don't ask)

I've created a Managed Bean which loads all the navigation information into a tree, and created a set of nested repeat controls that access the managed bean.

I'm having issues with the collapse and expand functions. The original authors use Client Side JavaScript by accessing the panel containing the entries which are one level under. They did this by hardcoding everything. 1000 lines of XML, that was.

<xp:this.script><![CDATA[collapse("#{id:repeatcontrolpanel3}]}")]]></xp:this.script>

I'm trying to make this generic; I've set up a property NameNestedRepeatControl in the custom control which contains the name of the nested repeatcontrol which I want to collapse/expand, and I was hoping that this would work:

<xp:this.script><![CDATA[collapse("#{id:#{compositeData.NameNestedRepeatControl}}")]]></xp:this.script>

but I'm getting a

javax.faces.el.MethodNotFoundException: NameNestedRepeatControl: com.ibm.xsp.binding.PropertyMap.NameNestedRepeatControl()

error.

Is there a special syntax for this, i.e. get a string value from the custom control's properties, then let that string be evaluated with #{id:}, or is there an even more elegant method that I'm missing?

thanks for the help.

标签: xpages
1条回答
Deceive 欺骗
2楼-- · 2019-09-07 02:06

I finally solved this issue by constructing the necessary script outside. Here I have a Navigation Entry Custom Control which has two String properties of script_expand and script_collapse.

<xp:view
xmlns:xp="http://www.ibm.com/xsp/core"> 
<xp:panel
    id="outerpanel"
    styleClass="NavLeftRow"
    style="#{compositeData.node.styleShowOnFirstLoad}">
    <xp:panel
        id="innerpanel">
        <xp:this.styleClass><![CDATA[#{compositeData.node.inBreadCrumbPath ?  compositeData.panelStyleWhenActive : compositeData.panelStyleWhenInactive}]]></xp:this.styleClass>
        <xp:image
            id="imgCollapsed"
            url="/xpSectionCollapsed_oneUI.gif">
            <xp:this.style><![CDATA[#{compositeData.node.styleHideIfInBreadCrumb}]]></xp:this.style>
            <xp:this.rendered><![CDATA[#{compositeData.node.hasChildren}]]></xp:this.rendered>
            <xp:eventHandler
                event="onclick"
                submit="false">
                <xp:this.script><![CDATA[#{javascript:compositeData.script_expand}]]></xp:this.script>
            </xp:eventHandler>
        </xp:image>         
    </xp:panel>
</xp:panel>

And the script function gets called from outside; I'm alleviating the problem of calculating the relevant ID by just doing it manually.

<xp:repeat
        id="repeatfourthlevelnodes"
        rows="200"
        var="fourthlevelnode"
        value="#{thirdlevelnode.children}">
    <xc:ccPanelNavigation
            node="#{fourthlevelnode}">
        <xc:this.script_expand>
            <![CDATA[expand("#{id:repeatfifthlevelnodes}");]]>
        </xc:this.script_expand>
    </xc:ccPanelNavigation>
</xp:repeat>

Not quite as elegant as I had hoped, but a lot better than the unfactored code.

It's Sven's answer Pass javascript code to Custom Control which really helped so this should really go to him!

查看更多
登录 后发表回答