Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Perserving form values on submit

 
Bill Zelan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to preserve input elements values after a submit? I looked at the tomahawk docs and it seems that t:subform can be used to preserve elements during a submit. The problem with this is that I have some plain html elements in my web application and placing a t:subform around these elements does not seem to preserve their values after a submit has occurred. Trinidad has a partialsubmit that may possibly work, and I will look into it.

During a submit I do not want to send everything on the page back to the server, instead I only want to send one subform to the server.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you possibly organize the components you want to submit into separate form tags?

Form data isn't usually too verbose, compared to all the other data sent across a network, especially things like images and video. What's the big issue with sending a few extra bytes of data over the network?

-Cameron McKenzie
 
Bill Zelan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not worried about the bandwidth. The user expects these elements to remain on the page with whatever style changes they have made.

I have tried using h:forms around the different components, but everything on the page is still getting submitted to the server. I am triggering this submit by using javascript to click a hidden submit button.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic JSF architecture should be doing that for you. If you create a JSF view with a form on it, submit the form, and don't navigate to some other view, the original page should be resdisplayed with the updated values (assuming your backing beans set/get methods are all correct).

If you have multiple forms on a page, this rule changes somewhat, since JSF is building on HTTP and HTTP only supports submitting one form per request. So only the submitted form will update. Any other forms on the page will lose their client-side changes and be refreshed from the server. The server literally never sees the client-side changes for the other forms.

Sometimes that's not a good idea. Fortunately, now we have AJAX solutions that support partial page updating. In Rich Faces, for example, you can designate each form as an AJAX form and instruct it to reRender itself but not any of the rest of the page (unless you want to).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic