Oh, ok. I didn't know you could extend it and use a different one. Still, that means I have to explicitly put a VCL on each field, which is tedious. Better than doing it in code though. I think this will do unless you can think of a way to avoid having to add the VCL tag to every component.
Thanks Dan -----Original Message----- From: Andrew Robinson [mailto:[EMAIL PROTECTED] Sent: Friday, July 13, 2007 11:49 AM To: MyFaces Discussion Subject: Re: Detecting whether or not the user changed anything on a form You don't need a phase listener. You could use one bean if you want. Here is just one example that you could use to track changes: public class ChangeTrackingListener implements ValueChangeListener { private final static String CHANGED_KEY = "ChangeTrackingListener"; public void processValueChange(ValueChangeEvent event) { FacesContext fctx = FacesContext.getCurrentInstance(); fctx.getExternalContext().getRequestMap().put(CHANGED_KEY, Boolean.TRUE); } public static boolean hasChanges() { FacesContext fctx = FacesContext.getCurrentInstance(); Boolean value = (Boolean)fctx.getExternalContext() .getRequestMap().get(CHANGED_KEY); return (value != null && value.booleanValue()); } } <h:inputText id="..." value="#{...}> <f:valueChangeListener type="example.ChangeTrackingListener" /> </h:inputText> Now this is a VERY simple example. You could change it to determine what changed, instead of just if there just was a change, etc. -Andrew On 7/13/07, Hannum, Daniel <[EMAIL PROTECTED]> wrote: > Thanks. Pardon my inexperience as I think this through > > So I could write a phase listener that would check for queued > ValueChangeEvents during the validation phase and the listener would set some > flag on one backing bean. The flag would indicate "Did the last JSF form > submission that occurred contain any changes?" I also have to be careful of > the scoping of that bean since it's shared across all pages. I think session > would work. > > Does that design make sense? I'm new to PhaseListeners and the right way to > use them. > > Dan > > > -----Original Message----- > From: Andrew Robinson [mailto:[EMAIL PROTECTED] > Sent: Friday, July 13, 2007 10:52 AM > To: MyFaces Discussion > Subject: Re: Detecting whether or not the user changed anything on a form > > If at least one ValueChangeEvent is queued (by a UIInput component) > during the validation pahse, then something has changed. > > On 7/13/07, Hannum, Daniel <[EMAIL PROTECTED]> wrote: > > > > > > > > > > Hi, > > > > > > > > I have a form for editing a business entity. The form is prepopulated with > > the current values and the user can change everything and hit the submit > > button when their done. Fairly simple. What's tricky is that I'd like to > > only show a confirmation ("Changes saved") message if they actually changed > > something instead of just submitting the same values as before. > > > > > > > > The naïve way is to check each backing bean field against the field in the > > business entity, but that's unmaintainable when the object starts changing. > > Is there a framework-based way to detect this? I want to avoid having to > > enumerate every field when I check. I want to know that _at least one_ of > > the fields on the page has a submitted value different from the model value. > > (I think I got the terminology right) > > > > > > > > Maybe the answer lies in a phase listener that would somehow do that check, > > my experience with that is limited. Please let me know if this is possible > > or not. > > > > > > > > And I'm using MyFaces and Trinidad so hopefully it would only use mechanisms > > include in those projects. > > > > > > > > Thanks > > > > Dan > > > > > > ________________________________ > > > > > > > > > > ***Note:The information contained in this message may be privileged and > > confidential and protected from disclosure. If the reader of this message is > > not the intended recipient, or an employee or agent responsible for > > delivering this message to the intended recipient, you are hereby notified > > that any dissemination, distribution or copying of this communication is > > strictly prohibited. If you have received this communication in error, > > please notify the Sender immediately by replying to the message and deleting > > it from your computer. Thank you. Premier Inc. > > ----------------------------------------- > ***Note:The information contained in this message may be privileged > and confidential and protected from disclosure. If the reader of > this message is not the intended recipient, or an employee or agent > responsible for delivering this message to the intended recipient, > you are hereby notified that any dissemination, distribution or > copying of this communication is strictly prohibited. If you have > received this communication in error, please notify the Sender > immediately by replying to the message and deleting it from your > computer. Thank you. Premier Inc. >

