aspose file tools*
The moose likes Struts and the fly likes How to update the object property on the server side by updating value in javascript before submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to update the object property on the server side by updating value in javascript before submit" Watch "How to update the object property on the server side by updating value in javascript before submit" New topic
Author

How to update the object property on the server side by updating value in javascript before submit

jack fe
Greenhorn

Joined: Nov 10, 2009
Posts: 16
Guys:
I have a question. When the form submitted, the value of 'clientPageNumber' of 'pageInfo' of 'form' is still 0 instead of 5
during processing the action class on the server side.
How can I update the value of that?

Thanks.
The source is in the following:
jsp
<bean:define id="formPageInfo" name="TestForm" property="pageInfo"/>
<!-- pageInfo is a property object of form -->
<input type="hidden" id="tablePageNumber" name="tablePageNumber" value="<bean:write name="formPageInfo" property="clientPageNumber"/>"/>
<!-- clientPageNumber is a int property of pageInfo object -->

javascript
function submitFormFunction(){
document.getElementById("tablePageNumber").value= 5 + '';
document.myform.action = "/<%=StartupConstants.APPLICATION_WAR_VALUE%>/TestUpdateFormAction.do";
document.myform.submit();
}
Travis Hein
Ranch Hand

Joined: Jun 06, 2006
Posts: 161
Here the the pageInfo bean is defined as a session (or request?) attribute, where the HTML form is submitting a tablePageNumber property, which will become a request parameter.

I'm not sure of any way using the javascript form submit thing there to automatically have the value loaded into the session object form bean. - this is what those struts taglibs do for us under the hood, but here we aren't using them.

What you can try to do in your action handler, is try to stuff the request paramter we are getting into the tablePageNumber property of the bean.



Error: Keyboard not attached. Press F1 to continue.
a kishore
Ranch Hand

Joined: Sep 16, 2009
Posts: 82
Hi jack fe


document.getElementById("tablePageNumber").value= 5 + '';



What you are trying to do with '5+', are you setting a value with increment ?


regards,
kishore
jack fe
Greenhorn

Joined: Nov 10, 2009
Posts: 16
The name of the input field is going to need to match the name of the property in your form. So the name of the input field should be pageInfo.clientPageNumber.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to update the object property on the server side by updating value in javascript before submit