You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Madhav Bhargava <Ma...@infosys.com> on 2009/03/05 12:12:33 UTC

Check if anything has been changed on the form

Hi All,

We are trying to fine tune the DAO layer where we are using Hibernate as our ORM. Since we have too many detached objects, every time we go and save which is quite often (because of implicit save) too many queries get fired and the application responds slowly. This happens even if nothing is changed by the user on the UI.

I was hoping to find a dirty flag setter in JSF where it can be checked first and only if the form has been changed will the call to other layers is made.

There are a couple of options that we considered:


1.       Using JS we iterate all the elements on the page and check if something has changed. However the JS gives an error if there are just too many elements on the page. Most of our pages are long and complex - don't ask me why - just a client requirement :(

2.       Attach value change listeners for every component that can be modified. What if nothing gets changed and therefore no ValueChangeEvent is queued. How will this be checked?

3.       Hack model update phase and try and set a dirty flag if anything is updated during that phase. Do not know how to do that either?

The solution needs to be light on performance. Any pointer would be really appreciated.


Thanks & Regards,
Madhav

**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are not 
to copy, disclose, or distribute this e-mail or its contents to any other person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has taken 
every reasonable precaution to minimize this risk, but is not liable for any damage 
you may sustain as a result of any virus in this e-mail. You should carry out your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***

Re: Check if anything has been changed on the form

Posted by Simon Kitching <sk...@apache.org>.
Madhav Bhargava schrieb:
> Hi All,
> 
>  
> 
> We are trying to fine tune the DAO layer where we are using Hibernate as
> our ORM. Since we have too many detached objects, every time we go and
> save which is quite often (because of implicit save) too many queries
> get fired and the application responds slowly. This happens even if
> nothing is changed by the user on the UI.
> 
>  
> 
> I was hoping to find a dirty flag setter in JSF where it can be checked
> first and only if the form has been changed will the call to other
> layers is made.
> 
>  
> 
> There are a couple of options that we considered:
> 
>  
> 
> 1.       Using JS we iterate all the elements on the page and check if
> something has changed. However the JS gives an error if there are just
> too many elements on the page. Most of our pages are long and complex –
> don’t ask me why – just a client requirement L
> 
> 2.       Attach value change listeners for every component that can be
> modified. What if nothing gets changed and therefore no ValueChangeEvent
> is queued. How will this be checked?
> 
> 3.       Hack model update phase and try and set a dirty flag if
> anything is updated during that phase. Do not know how to do that either?
> 
>  
> 
> The solution needs to be light on performance. Any pointer would be
> really appreciated.

So what you really need is to know whether a ValueChangeEvent has been
queued for any component, right?

One way to do that would be to use a custom ViewHandler in order to
return a custom UIViewRoot object that "wraps" the real one. Then you
could override the UIViewRoot.queueEvent method, and check in there
whether the event being queued is a ValueChangeEvent. If at the start of
the update-model phase, one or more ValueChangeEvents has been queued
during the request then you have a real change to the model. You could
store this flag as a request-scope property or similar.

Note that each input component is responsible for detecting that the
model property it is bound to has a different value, and queueing a
ValueChangeEvent on itself. But queuing an event on itself just causes
the call to bubble up the component tree until it reaches the
UIViewRoot, where the event is stuck on a global queue. So
UIViewRoot.queueEvent is eventually called for all events. Possibly the
original queued event gets "wrapped" on the way up (eg tables create a
wrapper so they can restore the correct row when the event is executed),
but I would expect that any wrapper for a ValueChangeEvent would also be
a subclass of ValueChangeEvent.

This seems generally useful; maybe such a patch would even be accepted
into the MyFaces UIViewRoot impl (though of course if you want your app
to run on Mojarra too then you'd need a separate implementation anyway).

I don't quite understand your point (2) above : if nothing gets changed,
and no ValueChangeEvent is triggered, isn't that ok? In this case your
model isn't changed and that is what you wanted to know.

By the way, I believe that JSF2.0 will state that during the
update-model phase, setters are only called on model properties where
the property value *has* changed, ie where a ValueChangeEvent has been
queued for that component because calling the property getter returned a
different value than the component contains internally. However the
JSF1.1 spec didn't say this, and both Sun and MyFaces currently call
property setters for all input components, regardless of whether the
value has changed or not.

Regards,
Simon
-- 
-- Emails in "mixed" posting style will be ignored
-- (http://en.wikipedia.org/wiki/Posting_style)