Florin M.
Florin M.

Reputation: 2169

xpages 2 partial refreshes from a required field

I have an inputText which is a required field on my Document.

<xp:inputText value="#{Cdoc.txt_NumeCompanie}" id="txt_NumeCompanie"
                        required="true" defaultValue="#{javascript:param.value}">
        <xp:this.validators>
                <xp:validateRequired message="Numele companiei este obligatoriu." loaded="true">
                </xp:validateRequired>
        </xp:this.validators>
        <xp:eventHandler event="onchange" submit="false" disableValidators="true">
            <xp:this.script><![CDATA[   XSP.partialRefreshPost("#{id:scrollDiv}", {
                        onComplete: function() {
                            XSP.partialRefreshPost("#{id:pers}");
                        }
                    });
                ]]></xp:this.script>
        </xp:eventHandler>
</xp:inputText>

I also checked the Process data without validation ( from the Server tab ... ). But still no refresh is taking place.

Upvotes: 1

Views: 574

Answers (3)

Per Henrik Lausten
Per Henrik Lausten

Reputation: 21709

You do not include the required second parameter on your second partialRefreshPost. Try this:

XSP.partialRefreshPost("#{id:scrollDiv}", {
    onComplete: function() {
        XSP.partialRefreshPost("#{id:pers}", {});
    }
});

Update: you can use the onComplete event of the eventHandler to run your 2nd partial refresh. So use the traditional partial refresh of the first component and then run your 2nd partial refresh through the onComplete event:

<xp:inputText value="#{Cdoc.txt_NumeCompanie}" id="txt_NumeCompanie" required="true" defaultValue="#{javascript:param.value}">
    <xp:this.validators>
            <xp:validateRequired message="Numele companiei este obligatoriu." loaded="true">
            </xp:validateRequired>
    </xp:this.validators>
    <xp:eventHandler event="onchange" submit="true" refreshMode="partial" refreshId="scrollDiv">
        <xp:this.onComplete><![CDATA[XSP.partialRefreshPost("#{id:pers}", {});]]></xp:this.onComplete>
    </xp:eventHandler>
</xp:inputText>

Upvotes: 4

Paul Stephen Withers
Paul Stephen Withers

Reputation: 15729

By setting submit="false", you're preventing any server-side processing from being triggered by the eventHandler itself. That means disableValidators="true" is irrelevant, because the XPages lifecycle is not being processed from the eventHandler.

Instead the refresh is being generated from the client-side code, the XSP.partialRefreshPost. That doesn't have an option to disable validation, as covered here How to disable validators using the XSP.partialRefreshPost method?. disableValidators="true" doesn't and cannot influence the processing of the partialRefreshPost. So chances are your validation is still running. To confirm that, add an errors panel into the initial refresh area.

partialRefreshGet may work, I'm not sure.

My usual approach in these scenarios is to refresh a single area that comprises both areas you wish to refresh. Then set submit="true" and disableValidators="true". But bear in mind that even if validation is disabled, data conversion is still checked so if you enter a text value in a number field, the partial refresh would still fail.

Upvotes: 3

John Dalsgaard
John Dalsgaard

Reputation: 2807

Ok, first thing to do is open your toolbox and look at the network traffic. This will help you to understand what is going on. You can use FireBug in FireFox or Developer tools in Google Chrome.

What network traffic occurs for the above snippet?

Edit:

Still waiting to hear what network traffic is generated...

But just looking at your code... - try set submit="true". I had a look at some of the code I have, and I am not sure that the extra empty param is required :-)

Could you explain what you are trying to obtain?

Edit

Ok, I see what you want. I had a quick view in some code. I am not doing exactly the same that you are. However, when I nest the partial refreshes I typically do it this way:

<xp:button id="button1"
    styleClass="btn btn-danger btn-lg#{FishingTripEdit.typeInput eq '1' ? ' inActive' : ''}">
    <xp:eventHandler event="onclick" submit="true" refreshMode="partial"
        refreshId="inputTypeSelected" disableValidators="true">
        <xp:this.action>
            <xp:executeScript>
                <xp:this.script><![CDATA[#{javascript:MyBean.setData('0')}]]></xp:this.script>
            </xp:executeScript>
        </xp:this.action>
        <xp:this.onComplete><![CDATA[XSP.partialRefreshGet("#{id:buttonTopHolder}")]]></xp:this.onComplete>
        <xp:this.script><![CDATA[return document.getElementById("#{id:triggerAsk}").value!=='1' ? true : confirm("Sure?")]]></xp:this.script>
    </xp:eventHandler>
</xp:button>

So for the "first" refresh I use the builtin markup - and onComplete I add the second as plain JavaScript. I know this is an example with a partialRefreshGet (which I prefer to use if at all possible due to less overhead). But perhaps it can give you an idea....

Upvotes: 0

Related Questions