I have a page where I want to have expandable sections, so when a user clicks on a section title, the relevant section will be shown.
I planned on doing this by setting a viewScope variable and having my section within a panel rendered if that viewScope variable is set. By clearing all viewScope variables, I can also instantly ‘collapse’ the other sections. Part of my source code is shown below, so you can see I’m setting viewScope.Links, refreshing the whole panel, so my Links panel becomes visible.
<xp:panel id=“travelDocs”>
<xp:link text="Links" styleClass="SectionTitle">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="travelDocs">
<xp:this.action><![CDATA[#{javascript:viewScope.entrySet().clear();viewScope.Links = true;}]]></xp:this.action>
</xp:eventHandler>
</xp:link>
<xp:br />
<xp:panel rendered="#{javascript:viewScope.Links == true}">
This works fine for the Links section, which is included in the source. However, further down I have a repeat panel of sections based on a lookup of categories in a view. So here I need to set the viewScpe variable based on the repeat’s ‘var’ property. Again, a portion of the code is below.
<xp:repeat id=“repeat2” rows=“30” var=“travelCat”>
<xp:panel style="padding-top:10.0px">
<xp:link text="#{javascript:travelCat}" styleClass="SectionTitle">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="travelDocs">
<xp:this.action><![CDATA[#{javascript:viewScope.entrySet().clear();
viewScope[travelCat] = true;}]]></xp:this.action>
</xp:eventHandler>
</xp:link>
<xp:panel
rendered=“#{javascript:viewScope[travelCat] == true}”>
<xp:this.value><![CDATA[#{javascript:viewScope[travelCat]}]]></xp:this.value>
</xp:text>
<xp:text value=“ME”></xp:text>
</xp:panel>
When I try to set the rendered property on-the-fly like this, the section contents (i.e. ‘ME’) is always rendered, even though no viewScope variables have been set. This is confirmed by the xp:text that shows the viewScope. When I click on the section heading, the viewScope variable is set and appears. However, it appears the rendered property doesn’t work using a variable.
Does anyone know why or how to pass in a viewScope variable name calculated on-the-fly to the rendered property?
Thanks
Paul