Nested Expression Language Syntax in XPages

♀尐吖头ヾ 提交于 2019-12-13 06:49:55

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/41912525/nested-expression-language-syntax-in-xpages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!