aspose file tools*
The moose likes JSF and the fly likes ValueChangeEvent fires for every datatable changed value, cannot reset. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "ValueChangeEvent fires for every datatable changed value, cannot reset." Watch "ValueChangeEvent fires for every datatable changed value, cannot reset." New topic
Author

ValueChangeEvent fires for every datatable changed value, cannot reset.

David Norris
Greenhorn

Joined: May 04, 2009
Posts: 3
I have index.jsp which has a Trinidad table.
Several columns will have a valueChangeListener bound to a backing bean method.
In the valueChangeListener method I print event getNewValue.

Problem: The method gets called (the event fires) for every changed input in every row every time any valueChange event fires.

I have found no way to reset or otherwise stop this behaviour.

The goal is to fire one value change event when an input is changed and update something with the new value.
Then the "newness" of the firing value should become old. The triggering input should not fire another event unless I change it again because it has been dealt with already.


Given: eclipse 3.4.2
JSF 1.2
Trinidad jsf components

My index.jsp partial code to show what I mean:


index backing bean partial code to show what I mean:
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

I don't know if I understood that, but you really shouldn't update the backing bean from the ValueChangeListener. It's intended to signal that a value has changed, but the actual value update is done by a later JSF lifecycle event.


Customer surveys are for companies who didn't pay proper attention to begin with.
David Norris
Greenhorn

Joined: May 04, 2009
Posts: 3
Thanks for the reply. I'm sure it's obvious I'm new to JSF.
To clearify, I want to detect a value change in a <tr:inputText which is inside a <tr:column which is inside a <tr:table. When a value change is detected I want to write the new value to a database. Then I need the changed value to know it is no longer new and not trigger another change event unless I change it again.

Example: I change text in a cell on row 1. The ValueChangeEvent fires.
Then I change a cell in row 2. The ValueChangeEvent fires two times. It has now fired 3 times total.

Problem: The ValueChangeEvent fires for every value that changed since the page was loaded.
If I have a 2 column by 2 row table and change all 4 inputs it will fire the event a total of 10 times.
Every time any value change is fired all of them fire where a value was changed.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

Definitely don't update the database in the ValueChangeListener.

Probably the best solution is to keep a list of the changed rows, which you update in the valuechangeListener. Then attach a "submit" commandButton to the page. In the submit action processor, write out the changed rows and clear the changed-row list. The Setter methods for the cell items will have updated your datamodel before the action processor gets invoked.

Another approach if you want something more immediate would be to make the inputText boxes have the "submit" function attached to them using JavaScript (or an AJAX-enabled tag like RichFaces). It would basically be the same thing, but you wouldn't have an explicit submit button on the page. This is usually more trouble than it's worth, though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ValueChangeEvent fires for every datatable changed value, cannot reset.