How to pass var to facet in xpages and update facet?

503 views Asked by At

I want to make switchFacet for practice, but in vain. Actually dont know where to start. Can this be written only in java? Here is my code. I try to pass variable through sessionScope. Button updates value, but facet doesnt. Facet changes value if I click URL and then ENTER.

This is my Xpage:

<xc:FacetContainerCC viewPanelTest="#{sessionScope.VarTest}">       
<xp:this.facets>
    <xp:div xp:key="SecondCC"><xc:SecondCC></xc:SecondCC></xp:div>
    <xp:div xp:key="FirstCC"><xc:FirstCC></xc:FirstCC></xp:div>
</xp:this.facets>

<xp:button value="#{javascript:sessionScope.VarTest}" id="button1">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
    <xp:this.action><![CDATA[#{javascript:if (sessionScope.get("VarTest") ==  "First") 
    sessionScope.put("VarTest", "Second"); else sessionScope.put("VarTest","First");}]]>
    </xp:this.action>
</xp:eventHandler>

And my facet:

<xp:callback id="callback1">
<xp:this.facetName><![CDATA[#{javascript:
    var viewPanelTest = sessionScope.get("VarTest");
    if (viewPanelTest == "First") return "FirstCC"; 
    else return "SecondCC";}]]>
</xp:this.facetName>

I noticed there is a difference between updating page by button and re-entering URL. Button makes POST request, re-entering URL makes GET request. FirstCC and SecondCC are custom components dropped on facet. And... sessionScope variables with same name co-exists on client and server, right?

1

There are 1 answers

3
stwissel On

Facets are computed on page load. As long as your page is loaded, the facet won't get recomputed. Thus your facetName will not get updated. Works as designed. The switchFacet loads all facet names but renders out only the selected one.

When you hit enter at the URL you get a new instance of that page (with a new viewScope), while the button does a page refresh (same viewScope) and thus no recomputation of facetName.

The switchFacet was created to accommodate exactly your use case since the existing facet functionality can't cover it.