This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Aug 7, 2012, 10:00 PM
19 Posts
topic has been resolvedResolved

Scope Variable Troubles

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.3
  • Role:
  • Tags: xPages,SSJS,ScopeVariables
  • Replies: 3
I am trying to force users filling out a form to review a pdf document.  I tried this by putting a link on the form to view the pdf.   When they click the link, I set a scope variable so I know they read the pdf.  Later in my submit button I check the value of the scope variable and submit the document if they read the pdf or let them know they have to review it before submitting the form.
 
I try to achieve this by the following:
 
I have a field on the form that is tied to a sessionScope variable.  When the link is clicked the sessionScope var is updated with the value "Yes"

In my submit button, I check the sessionScope variable for the value of Yes. The value is never Yes.  I have tried accessing the scope variable directly instead of the field value as well as several ways of getting the field value but I can not get the value of Yes .  Can anyone see what I am doing wrong here?

The link that sets the value of the scope variable which is linked to the field below. . .
<xp:link escape="true"
    text="Required: Click to Review Certificate of Insurance Requirements"
    id="link1"
    value="http://info.lmsnet.com/lms/assets/vendortracking/coirequirements.pdf"
    target="_blank" style="background-color:rgb(255,128,128)">
    <xp:eventHandler event="onclick"
        submit="true" refreshMode="partial" refreshId="btnSubmit"
        id="eventHandler1">
            <xp:this.action><![CDATA[#{javascript:sessionScope.put( "vendorAppReadCOI", "Yes" );}]]></xp:this.action>
    </xp:eventHandler>
</xp:link>

<xp:inputHidden id="vendorAppReadCOI1" value="#{sessionScope.vendorAppReadCOI}"></xp:inputHidden>

Button Code:
<xp:button value="Finish" id="btnSubmit">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="complete">
        <xp:this.action><![CDATA[#{javascript:

//if( sessionScope.vendorAppReadCOI == "Yes" )
//if( getComponent( "vendorAppReadCOI1" ).value == "Yes" )
//if( getComponent( "vendorAppReadCOI1" ).getValue() == "Yes" )
if( getComponent( "vendorAppReadCOI1" ).getSubmittedValue() == "Yes" )
{
    vendorApplication.save();
   
    viewScope.dialogFinishTitle = "Application Complete!";
    viewScope.dialogFinishMessage = "Thank you very much for submitting your application!\nAn e-mail will be sent shortly confirming we received your application.\nShould you need to make changes to the application or send Insurance Certificates etc.  you can email them to vp@lmsnet.com!";
    var dialogFinish = getComponent( "dialogFinish" );
    dialogFinish.show();
}
else
{
    viewScope.dialogOopsTitle = "Validation Error!";
    viewScope.dialogOopsMessage = "Required: Click the red link above to review our Certificate of Insurance requirements before saving your application!";
    var dialogOops = getComponent( "dialogOops" );
    dialogOops.show();
}
    }]]></xp:this.action>
    </xp:eventHandler></xp:button>
Aug 8, 2012, 4:51 AM
366 Posts
Re: Scope Variable Troubles
Can't really find anything wrong with the logic, but you might need to dial back your scope variable to be a view scope. 
 
I basically copied your code and took out the save logic.  I clicked the button and the session scope variable was null.  clicked the pdf link and then clicked the button and the session scope variable was Yes.
 
Remember that once a session scope variable is set, even if they load another page that uses that same variable the value remains until the browser is closed or the session times out. 

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

<xp:view

xmlns:xp="http://www.ibm.com/xsp/core">


<xp:link

escape="true"

text="Required: Click to Review Certificate of Insurance Requirements"

id="link1"

value="http://info.lmsnet.com/lms/assets/vendortracking/coirequirements.pdf"

target="_blank"

style="background-color:rgb(255,128,128)">

<xp:eventHandler

event="onclick"

submit="true"

refreshMode="partial"

refreshId="btnSubmit"

id="eventHandler1">

<xp:this.action><![CDATA[#{javascript:sessionScope.put( "vendorAppReadCOI", "Yes" );}]]></xp:this.action>

</xp:eventHandler>

</xp:link>




<xp:button

value="Finish"

id="btnSubmit">

<xp:eventHandler

event="onclick"

submit="true"

refreshMode="complete">

<xp:this.action><![CDATA[#{javascript:if(sessionScope.vendorAppReadCOI=="Yes"){

println(sessionScope.vendorAppReadCOI+" should be yes")

} else {

println(sessionScope.vendorAppReadCOI+" should be null")

}

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

</xp:eventHandler>

</xp:button>

</xp:view> 
 
 
This is the output in the log file from the above code. 
 
[0D54:0009-0C38] 08/08/2012 12:53:01 AM  HTTP JVM: null should be null
[0D54:0009-0C38] 08/08/2012 12:53:49 AM  HTTP JVM: Yes should be yes 
Aug 13, 2012, 6:30 PM
7 Posts
Re: Scope Variable Troubles
I'm not that familiar with xp:inputHidden, but I'm wondering if the link's partial refresh target is part of the problem. You're refreshing only the button, and the button code references the xp:inputHidden, which doesn't get refreshed. I created a simplified control to test:
 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:link escape="true"
        text="Required: Click to Review Certificate of Insurance Requirements"
        id="link1" target="_blank"
        style="background-color:rgb(255,128,128)">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="partial" id="something"
            refreshId="panel1">
            <xp:this.action><![CDATA[#{javascript:sessionScope.put( "vendorAppReadCOI", "Yes" );
print("sessionScope.vendorAppReadCOI: "+sessionScope.vendorAppReadCOI);
print("vendorAppReadCOI1: "+getComponent( "vendorAppReadCOI1" ).getSubmittedValue())}]]></xp:this.action>
        </xp:eventHandler>
    </xp:link>

<xp:inputHidden id="vendorAppReadCOI1" value="#{sessionScope.vendorAppReadCOI}">
    <xp:eventHandler event="onClientLoad" submit="true"
        refreshMode="partial" refreshId="panel1">
    </xp:eventHandler>
</xp:inputHidden>

<xp:panel id="panel1">
    <xp:text escape="true" id="computedField1">
        <xp:this.value><![CDATA[#{javascript:"sessionScope.vendorAppReadCOI: "+sessionScope.vendorAppReadCOI}]]></xp:this.value>
    </xp:text>
    <xp:br></xp:br>
    <xp:text escape="true" id="computedField2">
        <xp:this.value><![CDATA[#{javascript:"vendorAppReadCOI1: "+getComponent( "vendorAppReadCOI1" ).getSubmittedValue()}]]></xp:this.value>
    </xp:text>
</xp:panel>
</xp:view>
 
(The XPage that hosts this control has a beforePageLoad event to set the sessionScope variable to "No', so I can see whether something happens when the link is clicked.)
 
When I click the link, I can see the sessionScope variable getting set to "Yes", but the xp:inputHidden remains null. The server console output shows the same thing.
 
Aug 19, 2012, 10:57 PM
19 Posts
Re: Scope Variable Troubles
Sometime you gotta love IBM Support.  They found the issue:
 once I checked the Do no Validate or Update Data, it worked just like it should have.  Go IBM.  I have had great success with their support over the years.  Kudos to them.
 


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal