File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Retaining Old value in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Retaining Old value in JSF" Watch "Retaining Old value in JSF" New topic

Retaining Old value in JSF

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362

I have a input text and a command button. The input text has some validations and when the user enters/updates an invallid text and clicks the command button, the message should appear that the value is invalid and the the data should revert back to the original text which was in the text box. How can it be done in JSF?

Thanks in advance
Mallika gowd

Joined: Sep 28, 2009
Posts: 26
Hi Mary,

when user entered values are invalid, you can set it back to original value in your backing bean.

please post your code to understand better and others can suggest you a solution.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16897

Actually, this isn't really a good idea. It's confusing to display an error message for a value that no longer exists on-screen.

The simplest way to reset to the old value is to use the HTML reset function. You can place an actual "type=RESET" button on the form or invoke the javascript reset() function. However unless you take extra care, it will reset ALL values in the form, not just the one you didn't like.

I think that for a single field, there may be an "undo" javascript method, but I'd have to look it up to be sure.

Customer surveys are for companies who didn't pay proper attention to begin with.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
I agree that its confusing but that's the functionality the biz needs. On click of the button it should save the value if all the validations pass, but if the validations fail, the old value needs to be displayed on the screen
karan khosla

Joined: Apr 27, 2009
Posts: 25

Hi Mary,

What you wanted to achieve is quite possible and it won't take much time. either way you have already defined your validation logic. You have something called <h:messages> which will help you display the error. If you want to reset the value to the original one can be done via js or java. It's like have a <f:ajax> in you commandButton and update the inputbox and <h:messages>.

Hope! this helps.

Karan Check me out on
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Thanks for the response. Can you be more specific and provide a line or two of the code to achieve this?
I agree. Here's the link:
subject: Retaining Old value in JSF
It's not a secret anymore!