aspose file tools*
The moose likes JSF and the fly likes Backing Bean query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Backing Bean query" Watch "Backing Bean query" New topic
Author

Backing Bean query

zaxxon25
Ranch Hand

Joined: Feb 26, 2005
Posts: 35
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....
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
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.


ph34r my 133t j4v4 h4><0r1ng sk177z
zaxxon25
Ranch Hand

Joined: Feb 26, 2005
Posts: 35
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
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Backing Bean query