Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retaining Old value in JSF

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Mallikarjun
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,
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
Greenhorn
Posts: 25
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Regards,
Karan

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karan,
Thanks for the response. Can you be more specific and provide a line or two of the code to achieve this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic