jQuery in Action, 3rd edition
The moose likes JSF and the fly likes Perserving form values on submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Perserving form values on submit" Watch "Perserving form values on submit" New topic

Perserving form values on submit

Bill Zelan
Ranch Hand

Joined: Jan 09, 2009
Posts: 46
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

Joined: Aug 26, 2006
Posts: 4968

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

Joined: Jan 09, 2009
Posts: 46
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

Joined: Jun 25, 2001
Posts: 17417

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).

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link: http://aspose.com/file-tools
subject: Perserving form values on submit
It's not a secret anymore!