• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Backing Bean query

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a screen in which all values being dislayed are stored in java backing bean.
i have to code particular functionality under which whenever a person cliks OK button at end of screen a call needs to be made to server to compare current values on screen with stored value in backing beans. If values are different an alert is sent to user informing him that values have changed. If he opts yes then new values are retained and old values lost.
The new values will also be stored in same bean. Can any one using some sample code explain me how this can be done .....

In summary how can i use my form bean's same field to store different values on each form submission and also retain old values for comparision purpose....
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no silver bullet that I am aware of for doing this. You'll just need to store old values in session (most likely) and then compare the new values coming in off the request to the session values. Replacing values in both scopes when necessary.
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can write a custom validator that will read the new values off the request, and compare them against the values in the backing bean.

Remember, your new values will not overwrite the old values until after validation.

Something like this for a String value (if you are using non-String values you will need to convert your request value to the correct type:



Now you want to do a confirm and then proper submit, to do this you can set a backing bean boolean to true on the first submit and check for it in the validator - if they that value is true you know this is the second submit (the confirm) and you can ignore the validation.
 
zaxxon25
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
will using valuechangeListener work ....something like this ....

JSF
<h:inputText valueChangeListener="#{myBean.inputListener}" />



MyBean
public void inputListener(ValueChangeEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
// do your thing
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic