You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by th...@webmd.net on 2002/03/11 01:20:39 UTC

Found Solution to setting server side parm in Javascript BUT....

After spending 2 hours trying to find a solution to this, I found one by
trial and error...
BUT THERE HAS GOT TO BE A BETTER WAY  :-)

Here's what I did but I can't believe it's "this" difficult to do...

Here's my checkfield property that needs to "force a form value to be
updated":

                         <html:select property="psdProductType" size="1"
                              onchange="setCurrProductType(this.value)">
                              <html:options collection="psbusinesstype"
property="value"
                                   labelProperty="label"/>
                         </html:select>

Here's the javascript function:

     function setCurrProductType(inProductType) {
          alert("Setting curr product type to: " + inProductType);
          window.location="SetProperty.jsp?enteredPt="+inProductType;
     }

----
and here's the SetProperty.jsp
-----------------------------
<%@ taglib uri="/struts-bean" prefix="bean" %>

<bean:define id="psInfo" name="psSession" type="express.EBPsSession" scope
="session" />
<bean:define id="psForm" name="psForm" type="express.psForm" scope
="session" />

<%
     //
     // If they changed the product type on the first page, set it
     // here in the form object...
     //
     String sCurrProductType=request.getParameter("enteredPt");
     psInfo.setCurrProductType(sCurrProductType);
     System.out.println("Current Product Type = " +
psInfo.getCurrProductType()
          + " current page = " + psInfo.getCurrpage());
     psForm.setPsdProductType(psInfo.getCurrProductType());
%>

<jsp:forward page="PsPage.jsp"/>
--------------------

So in essence, the "forward" tag simply causes control to come back to the
page I was on...   But in-between, I was able to set a form bean
property....    Again my problem is the form bean property is not updated
until you hit the submit button...   In this case, I don't want a submit to
occur when you change the contents of the dropdown.   Only the property for
that drop down should change...   After adding this, when I click to go to
the 4th tab, the action now sees the newly changed value....

It works BUT I have to believe there's a better way!!!    I open to any
suggestions...



                                                                                                        
                    theron.kousek                                                                       
                    @webmd.net           To:     Struts Users Mailing List                              
                                         <st...@jakarta.apache.org>                               
                    03/10/02             cc:                                                            
                    02:32 PM             Subject:     setting server side parm in Javascript?           
                    Please                                                                              
                    respond to                                                                          
                    Struts Users                                                                        
                    Mailing List                                                                        
                                                                                                        
                                                                                                        




Hi Folks:

I'm doing a mimic-JTabbedPane approach.   I have a screen with 5 tabs.    I
am using 1 form object and 5 action mappings...

On tab 4, I'd like to detect changes made to a field on tab 1.     I notice
I can change the field on tab 1 but tab 4 does not know about until the
form is submitted.    I can't submit the form...

I'd like to have a Javascript handler that implements the onchange() and
somehow sets a session attribute or some kind of trigger that tells tab 4
to "reload" itself when this field on tab 1 has changed.    I notice if I
change these values, the form object will not get the new values until you
hit submit.    Having the javascript function call submit is not an option
either...   Any ideas on how best to do this??

If I could access my form-bean directly within the Javascript method, that
would be an option to (as I could call the set method on the form object)
but I am not sure if the javascript can access the form object directly and
call a set method?

thanks,
Theron


--
To unsubscribe, e-mail:   <
mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <
mailto:struts-user-help@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Found Solution to setting server side parm in Javascript BUT....

Posted by Robert Nocera <rn...@neosllc.com>.
Theron,

There isn't an easier way because a FormBean is a server-side object.
You might think that your html page has access to it, but it's only
because of the sleight of hand involved in JSP programming.  Since a JSP
is actually a servlet, it is only sending HTML to a browser so your
browser knows nothing of these objects.

Robert Nocera
New England Open Solutions
www.neosllc.com
"You supply the vision, we'll do the rest."
 

-----Original Message-----
From: theron.kousek@webmd.net [mailto:theron.kousek@webmd.net] 
Sent: Sunday, March 10, 2002 7:21 PM
To: Struts Users Mailing List
Cc: struts-user@jakarta.apache.org; Kalven.Beaver@expressbill.com
Subject: Found Solution to setting server side parm in Javascript
BUT....


After spending 2 hours trying to find a solution to this, I found one by
trial and error...
BUT THERE HAS GOT TO BE A BETTER WAY  :-)

Here's what I did but I can't believe it's "this" difficult to do...

Here's my checkfield property that needs to "force a form value to be
updated":

                         <html:select property="psdProductType" size="1"
                              onchange="setCurrProductType(this.value)">
                              <html:options collection="psbusinesstype"
property="value"
                                   labelProperty="label"/>
                         </html:select>

Here's the javascript function:

     function setCurrProductType(inProductType) {
          alert("Setting curr product type to: " + inProductType);
          window.location="SetProperty.jsp?enteredPt="+inProductType;
     }

----
and here's the SetProperty.jsp
-----------------------------
<%@ taglib uri="/struts-bean" prefix="bean" %>

<bean:define id="psInfo" name="psSession" type="express.EBPsSession"
scope
="session" />
<bean:define id="psForm" name="psForm" type="express.psForm" scope
="session" />

<%
     //
     // If they changed the product type on the first page, set it
     // here in the form object...
     //
     String sCurrProductType=request.getParameter("enteredPt");
     psInfo.setCurrProductType(sCurrProductType);
     System.out.println("Current Product Type = " +
psInfo.getCurrProductType()
          + " current page = " + psInfo.getCurrpage());
     psForm.setPsdProductType(psInfo.getCurrProductType());
%>

<jsp:forward page="PsPage.jsp"/>
--------------------

So in essence, the "forward" tag simply causes control to come back to
the
page I was on...   But in-between, I was able to set a form bean
property....    Again my problem is the form bean property is not
updated
until you hit the submit button...   In this case, I don't want a submit
to
occur when you change the contents of the dropdown.   Only the property
for
that drop down should change...   After adding this, when I click to go
to
the 4th tab, the action now sees the newly changed value....

It works BUT I have to believe there's a better way!!!    I open to any
suggestions...



 

                    theron.kousek

                    @webmd.net           To:     Struts Users Mailing
List                              
 
<st...@jakarta.apache.org>                               
                    03/10/02             cc:

                    02:32 PM             Subject:     setting server
side parm in Javascript?           
                    Please

                    respond to

                    Struts Users

                    Mailing List

 

 





Hi Folks:

I'm doing a mimic-JTabbedPane approach.   I have a screen with 5 tabs.
I
am using 1 form object and 5 action mappings...

On tab 4, I'd like to detect changes made to a field on tab 1.     I
notice
I can change the field on tab 1 but tab 4 does not know about until the
form is submitted.    I can't submit the form...

I'd like to have a Javascript handler that implements the onchange() and
somehow sets a session attribute or some kind of trigger that tells tab
4
to "reload" itself when this field on tab 1 has changed.    I notice if
I
change these values, the form object will not get the new values until
you
hit submit.    Having the javascript function call submit is not an
option
either...   Any ideas on how best to do this??

If I could access my form-bean directly within the Javascript method,
that
would be an option to (as I could call the set method on the form
object)
but I am not sure if the javascript can access the form object directly
and
call a set method?

thanks,
Theron


--
To unsubscribe, e-mail:   <
mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <
mailto:struts-user-help@jakarta.apache.org>




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>