XPage: Why can't I reset a sessionScope variable?

I’d like a Panel to display when my sessionscope variable is set to Y, and then disappear when the variable is set to “”. Simple thing. But, I can’t get it to work. My “open” button will set the variable to Y (I have a label to show me the current value) and a partial refresh will indeed cause the Panel to display. However, when I click a “cancel” button to clear the sessionscope variable and partial refresh, nothing happens. The variable is not reset and the Panel stays visible.

While playing around with it, I changed my cancel button to set the variable to N. When I open my xpage, I can indeed click the cancel button first and see that the variable changes to N. Then, I click the open button, and it changes to Y and the Panel displays (correctly). Click the cancel button again - nothing.

Here’s my code for the open and cancel buttons:

sessionScope.put(“NewIssue”,“Y”)

and

sessionScope.put(“NewIssue”,“N”)

The buttons are positioned side by side in the same context.

What am I missing here? Why will the sessionscope variable change easily to Y, but not to N or blank or whatever once it is Y?

Signed,

Confused (again)

Subject: try…

<xp:panel id="panel2Refresh">

	<xp:button value="Show and Hide" id="button2">

		<xp:eventHandler event="onclick" submit="true"

			refreshMode="partial" refreshId="panel2Refresh">

			<xp:this.action>

				<xp:setValue binding="#{sessionScope.v01}">

					<xp:this.value><![CDATA[#{javascript:var sh = sessionScope.v01;

if (sh ==“SHOW”){“HIDE”

}

else{“SHOW”

}}]]></xp:this.value>

				</xp:setValue>

			</xp:this.action>

		</xp:eventHandler>

	</xp:button>

	<xp:panel

		style="width:443.0px;height:186.0px;text-align:center;border-color:rgb(0,128,255);border-style:solid;border-width:thin">

		<xp:this.rendered><![CDATA[#{javascript:sessionScope.v01 == "SHOW"}]]></xp:this.rendered>

		<xp:label value="PANEL" id="label1"

			style="margin-top:30px;color:rgb(0,128,192);font-weight:bold;font-size:14pt"></xp:label>

	</xp:panel>

</xp:panel>

http://www.bleedyellow.com/blogs/XPagesStuff/entry/a_show_and_hide_example_using_sessionscope?lang=en

Subject: Nope, didn’t work…

I copied in your code and saw how it worked just as you said. I then used your approach for my “open” and “close” buttons, but still get the same result. Here’s what I have:

<xp:panel id=“NewIssue”>

<xp:button value="close issue" id="button2" style="margin-left:10px">

<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="NewIssue">

	<xp:this.action>

		<xp:actionGroup>

			<xp:setValue binding="#{sessionScope.NewIssue}">

				<xp:this.value><![CDATA[#{javascript:"N"}]]></xp:this.value>

			</xp:setValue>

		</xp:actionGroup>

	</xp:this.action>

</xp:eventHandler>

</xp:button>



<xp:button value="New Issue" id="button1" style="margin-left:10px">

<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="NewIssue">

	<xp:this.action>

		<xp:actionGroup>

			<xp:setValue binding="#{sessionScope.NewIssue}">

				<xp:this.value><![CDATA[#{javascript:var tmp = sessionScope.NewIssue;

				if (tmp=="Y"){"";

				}		

				else {"Y";

				}}]]></xp:this.value>

			</xp:setValue>

		</xp:actionGroup>

	</xp:this.action>

</xp:eventHandler>

</xp:button>



<xp:label value="#{javascript:sessionScope.NewIssue}" id="label51" style="color:rgb(255,0,0)"></xp:label>

<xp:br></xp:br>



<xp:panel

	style="background-color:rgb(255,255,204);padding-left:10px;padding-right:10px;padding-top:10px;padding-bottom:10px">

	<xp:this.rendered><![CDATA[#{javascript:sessionScope.get("NewIssue")=="Y"}]]></xp:this.rendered>

	...

	...

When I click the close button, the label displays the variable as N, correctly. When I then click the open button, the variable changes to Y and my Panel displays (hooray) However, if I then click the close button again, nothing happens. Also, the open button - which is supposed to toggle the variable - does nothing. So, once the variable is Y, it won’t change.

Can you see what I’m missing?

Thanks for your time.

  • More info - I changed the close button to toggle the variable from blank to N. This works just as expected. Each time I click it,it toggles from blank to N or N to blank. But, the open button will not work that way. It will toggle from blank to Y, but once it’s Y, it won’t toggle back. And, the close button does nothing either. It must have something to do with the fields in the Panel. The fields are bound to a different data source than the rest of the control because the user is creating a new document.

Subject: Make sure that the panel you’re refreshing contains the panels you need refreshed…

<?xml version="1.0" encoding="UTF-8"?>

<xp:view xmlns:xp=“http://www.ibm.com/xsp/core”>

<xp:panel id="NewIssue">

	<xp:button value="close issue" id="button2" style="margin-left:10px">

		<xp:eventHandler event="onclick" submit="true"

			refreshMode="partial" refreshId="NewIssue">

			<xp:this.action>

				<xp:actionGroup>

					<xp:setValue binding="#{sessionScope.NewIssue}">

						<xp:this.value><![CDATA[#{javascript:"N"}]]></xp:this.value>

					</xp:setValue>

				</xp:actionGroup>

			</xp:this.action>

		</xp:eventHandler>

	</xp:button>



	<xp:button value="New Issue" id="button1" style="margin-left:10px">

		<xp:eventHandler event="onclick" submit="true"

			refreshMode="partial" refreshId="NewIssue">

			<xp:this.action>

				<xp:actionGroup>

					<xp:setValue binding="#{sessionScope.NewIssue}">

						<xp:this.value><![CDATA[#{javascript:var tmp = sessionScope.NewIssue;

				if (tmp=="Y"){"";

				}		

				else {"Y";

				}}]]></xp:this.value>

					</xp:setValue>

				</xp:actionGroup>

			</xp:this.action>

		</xp:eventHandler>

	</xp:button>



	<xp:label value="#{javascript:sessionScope.NewIssue}" id="label51"

		style="color:rgb(255,0,0)"></xp:label>

	<xp:br></xp:br>



	<xp:panel style="background-color:rgb(255,128,128);text-align:center">

		<xp:this.rendered><![CDATA[#{javascript:sessionScope.NewIssue == "N"}]]></xp:this.rendered>

		<xp:label value="NO" id="label2"

			style="color:rgb(255,255,0);font-size:26pt;font-weight:bold">

		</xp:label>

	</xp:panel>

	<xp:panel style="background-color:rgb(0,255,0);text-align:center">

		<xp:this.rendered><![CDATA[#{javascript:sessionScope.NewIssue == "Y"}]]></xp:this.rendered>

		<xp:label value="YES" id="label1"

			style="font-weight:bold;font-size:26pt;color:rgb(0,128,64)"></xp:label>

	</xp:panel>





</xp:panel>

</xp:view>

Subject: My display panel is within my refresh panel…

But, I think the problem may be with my context. My xpage (Task document) contains a tabbed table and the second tab contains a view element showing related Issues. When the user clicks that tab, I want them to have the option to create a new Issue without leaving the page. The NewIssue panel (which contains the panel with the fields) is in a custom control, which is bound to a different datasource with a default action = “create document”. (to create a new Issue doc)

I’m actually having 2 problems that I thought were unrelated, but now think they may be related. The fields that I have bound to my new datasource won’t show in the browser when the panel is displayed. The browser doesn’t give me an error, but I suspect maybe that’s why the panel display toggle doesn’t work the way it should. (?)

Your sample code is excellent, so there must be something going on with this custom control trying to create a new Issue document. I’m missing something, but I don’t know what.

Oh, and one more thing that could be the cause… while working with the elements in Designer, I’ll periodically get an error that states “an error has occurred. see the error log for more details: java.lang.illegalargumentexception” with details that read, “argument not valid.” I have no idea what this means or where to go to resolve it. There’s nothing in my notes log, and I changed my Perspective to Plug-in Development to see that log and there’s nothing there either. So, maybe this is where my problem is… ?

Your help is much appreciated!

Subject: Thanks, Paul, I’ll give it a try…

Wonder why my code wouldn’t work using the ‘execute script’ option?..

Thank you!