1
votes

Below is a simple Xpage with a radiobuttongroup that is bound to a sessionScope variable. The onclick event of the radio button group sets the computed field. There is an afterPageLoad event to initialize the session scope variable.

All works great. However, if I clear the session Scope variables (using the debug custom control) then the onclick event never fires. The user can click on the radio button all they want and the computed field never changes until the page is reloaded by pressing F5. Below is my page source. Any suggestions on how to get the onclick event to fire? This would be a big usability issue if the user let the session variables time out and then starting clicking on the radio button.

Howard

            <?xml version="1.0" encoding="UTF-8"?>
                <xp:view xmlns:xp="http://www.ibm.com/xsp/core">
                <xp:this.afterPageLoad><![CDATA[#{javascript:print("starting the afterPageLoad event");
                if (sessionScope.init != true|| sessionScope.radioData == null){
                //setup default values'
                print("initing the value");
                sessionScope.init = true;
                sessionScope.radioData = "Red";
                } 
            }]]></xp:this.afterPageLoad>
                <xp:radioGroup id="radioButtons" value="#{sessionScope.radioData}">
                    <xp:selectItem itemLabel="Red"></xp:selectItem>
                    <xp:selectItem itemLabel="Green"></xp:selectItem>
                    <xp:selectItem itemLabel="Blue"></xp:selectItem>
                    <xp:eventHandler event="onclick" submit="true"
                    refreshMode="partial" refreshId="computedField1">
                    <xp:this.action><![CDATA[#{javascript:print("starting onclick event");
                if (sessionScope.init != true){
                    print("reload the page");
                context.reloadPage();
                }
                var radioval = getComponent("radioButtons").getValue();
                getComponent("computedField1").setValue(radioval); }]]></xp:this.action>
                </xp:eventHandler></xp:radioGroup>
                <xp:text escape="true" id="computedField1"></xp:text></xp:view>
1
Copied your code to a blank XPage (8.5.3, Debug Toolbar v1.3). Tested in IE 8 and FF 11. OnClick-Event is fired in both w/o problems.Sven Hasselbach
I was using the Debug Custom Control by Ferry. I load that in another browser and clear the session variables from that other page. I did try the Debug ToolBar and it does work that way. Wonder what the difference is?Howard
I wonder if this is related more to how the Debug Custom Control clears out the sessionScope variables? I created a button with the following code and after using this button on my XPage, the onclick event does fire. Using the Clear Scope button in the Debug Custom Control does not...var iter = sessionScope.keySet().iterator(); while( iter.hasNext() ){ sessionScope.remove( iter.next() ); } ... I assume this would be the same as the sessionScope variables timing out... I will let the page sit overnight to find out! thanks, HowardHoward
To replicate what I am seeing try just letting the session time out (leave the browser window with the page loaded overnight). In the morning, try clicking the radio button, the onclick event will not fire.Howard
Figured it out. The SessionID cookie was timing out, this causes the events to not fire. I added the code below to the client side JS onlick event for the radio button to reload the page if the cookie is empty. if (document.cookie==""){ //reload the page alert("The page has timed out and will reload"); location.reload(); }Howard

1 Answers

0
votes

I've seen this same behavior several times in my own xpage apps, and I've found that the problem happens only for partial page refreshes where the target refreshId is not large enough in scope to reload all of the data needed by the control. When I change the refreshId to the page's main div (or use full page refresh), then all works as expected.

I think that it's the call to location.reload in the client-side code which is actually fixing your issue. I'd be interested to learn if increasing the scope of refreshId also fixes the problem.