1
votes

I could do with some help once again...

We built our own forms in XPages. Forms are defined by a user in Notes, and they are used through XPages/web. We added several managed beans to get more grip on the data used by the page and controls that are on it. The whole thing is heavily nested, the form control can be used more than once on a page, repeat controls are used as well, and now I need to partially refresh a panel.

Some of the code:

<xp:panel id="ccAnyForm">
    <xp:this.dataContexts>
        <xp:dataContext var="formulaire">
            <xp:this.value><![CDATA[#{javascript:compositeData.formName || compositeData.dataSource.getItemValueString("Formulaire")}]]></xp:this.value>
        </xp:dataContext>
        <xp:dataContext var="formdata">
            <xp:this.value><![CDATA[#{javascript:PageData.getForm(formulaire, compositeData.dataSource)}]]></xp:this.value>
        </xp:dataContext>
    </xp:this.dataContexts>
    <xp:panel id="aFormulaire${javascript:compositeData.name}">
        <xe:switchFacet id="switchFacet1">
            <xe:this.selectedFacet><![CDATA[#{javascript:formdata.isTabbed()? "tabbed": "flat"}]]></xe:this.selectedFacet>

PageData is a Java bean, and I lose formdata when doing a partial refresh. If I set partial execution mode in the EventHandler (data validation is disabled), I get the error that says formdata not found on the last line of the snippet. If I clear partial execution mode, I get nothing at all: no error, no Java error, no SSJS error, nothing.

It must be my lack of understanding the life-cycle of objects and variables, for I prbably have to use ValueBindings or so, but I don't know how.

Help...

1
Just a little (not answer-related) advice: It's better not to use DYNAMICALLY bound dataContexts because they are frequently recalculated, even when using partial execution mode. For more information, check out this post by Sven Hasselbach: hasselba.ch/blog/?p=1112xpages-noob
Seen that, thanks. I don't care much too for the recalculations, for the time being, because I cache the result of the first call in my code and return the same value each subsequent call. What makes this more difficult (to understand) for me is that the content can change every partial refresh.D.Bugger
Where are you caching the result of the first call? The dataContext is a dynamic binding so recalculates during each partial refresh. The partial refresh itself comprises a number of phases, so properties (like getValue() of a component) may change in different phases.Paul Stephen Withers

1 Answers

0
votes

I've seen dataContexts recalculate as null, particularly when dependent on other dataContexts. I think in Apply Request Values phase. When I had that I changed the code to only calculate in Render Response phase.

However, I don't think that work for you, because the Switch control will need the value before Render Response, and there's no easy way to get hold of which other phase is running.

The approach I'd take is to have a property in your bean (e.g. showTabbed) that holds which Switch facet to show. Call a bean method to set that property on page load. Then in your partial refresh, call the method again, checking whether the Formulaire field has changed to determine whether or not to call setShowTabbed(boolean) again. That will minimise the number of calls even more and should prevent the problem.