You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Bill Schneider <bs...@vecna.com> on 2006/04/02 06:30:45 UTC

h:inputHidden vs t:saveState explained

Hello,

I just learned there's a subtle but important difference between 
<h:inputHidden value="#{bean.foo}"/> and <t:saveState 
value="#{bean.foo}"/>, assuming bean.foo is a String property. 
inputHidden and saveState look very similar and they have the same end 
result of setting bean.foo, but they get applied at different phases of 
the JSF lifecycle.  <t:saveState> is during Restore View phase, 
<h:inputHidden> is during Apply Request Values.

This is an important distinction if you have something like 
<h:commandLink rendered="#{bean.foo}">--I was very confused when my 
commandLink action wasn't executed, yet the link was still displayed.

the other lesson learned is that the 'rendered' attribute is actually 
evaluated twice, once in Restore View to decide whether the 
commandLink/Button you clicked on should actually run the action; and a 
separate time during Render Response to decide whether to show the link 
again.

Hope that sharing this spares others the confusion I had trying to get 
my code to work.

-- Bill

Re: h:inputHidden vs t:saveState explained

Posted by Martin Marinschek <ma...@gmail.com>.
Hi Bill,

the rendered attribute is actually checked for more often - at the
beginning of every lifecycle phase. It's very dangerous to make it an
expensive operation - as well as letting it change it s value out of
an action method.

regards,

Martin

On 4/2/06, Bill Schneider <bs...@vecna.com> wrote:
> Hello,
>
> I just learned there's a subtle but important difference between
> <h:inputHidden value="#{bean.foo}"/> and <t:saveState
> value="#{bean.foo}"/>, assuming bean.foo is a String property.
> inputHidden and saveState look very similar and they have the same end
> result of setting bean.foo, but they get applied at different phases of
> the JSF lifecycle.  <t:saveState> is during Restore View phase,
> <h:inputHidden> is during Apply Request Values.
>
> This is an important distinction if you have something like
> <h:commandLink rendered="#{bean.foo}">--I was very confused when my
> commandLink action wasn't executed, yet the link was still displayed.
>
> the other lesson learned is that the 'rendered' attribute is actually
> evaluated twice, once in Restore View to decide whether the
> commandLink/Button you clicked on should actually run the action; and a
> separate time during Render Response to decide whether to show the link
> again.
>
> Hope that sharing this spares others the confusion I had trying to get
> my code to work.
>
> -- Bill
>


--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces