List Info

Thread: TagHandlers, Compiletime/Rendertime and State of ValueExpressions




TagHandlers, Compiletime/Rendertime and State of ValueExpressions
user name
2007-10-11 02:29:43
Hi,

i've come to an issue which can be shortened to the example
below:

1)
A Taghandler which does nothing more than setting a variable
"myVar"
with a random value:
public void apply(FaceletContext faceletcontext, UIComponent
uicomponent)
			throws IOException, FacesException, FaceletException,
ELException {

	faceletcontext.setAttribute("myVar",
String.valueOf(Math.random()));
}

2)
A xhtml which displays this Variable.
<h:form>
<xy:myTag />	
<h:outputText value="#"/>	
<h:commandLink value="post"/>
<h:form>

What happens is that with every post the outputtext
component displays  
always
the same value (the firstly created random)

My first thought: the reason is that a TagHandler only is
valid during  
tree creation.
Doing a post to the same view requests the previously
created tree which  
means the
TagHandler won't be called again.
But something is wrong with my understanding of compiletime
and rendertime  
because the
TagHandler gets called everytime regardless of a post to the
same view or  
requesting a new view.

Having a closer look at the sources i can summarize this to
the following:
"#" is a com.sun.el.ValueExpressionImpl
which holds the  
ValueExpresion "myVar".
Additionally a VariableMapper is set which maps as
key<->value the  
myVar<->theRandomValue.
The VariableMapper is only used when pushing a Variable into
the context  
via faceletcontext.setAttribute(...)
I've found no other cases when the VariableMapper was set.

And now: ValueExpressionImpl externalizes the
VariableMapper.

This means the component which holds the valueexpression
"#" always  
associates this binding
with the first resolved value and never resolves that
ValueBinding again.


Is this a desired behaviour?
The problem simply is that my TagHandler prepares a value
which changes  
dynamically.
But my components never work with other values than the
initial one  
although the TagHandler
pushes the right value with every request into the context.

Does anybody have had the same problem and knows a
workaround?
(Or: is it really neccessary that the VariableMapper must be
externalized?)

thanks
Denny

------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribefacelets.dev.java.net
For additional commands, e-mail: users-helpfacelets.dev.java.net


Re: TagHandlers, Compiletime/Rendertime and State of ValueExpressions
user name
2007-10-11 10:22:31
I can't help you with your issue (I don't believe it would
be a
MyFaces problem, however), but to clear up your
understanding:

> My first thought: the reason is that a TagHandler only
is valid during
> tree creation.
> Doing a post to the same view requests the previously
created tree which
> means the
> TagHandler won't be called again.
> But something is wrong with my understanding of
compiletime and rendertime
> because the
> TagHandler gets called everytime regardless of a post
to the same view or
> requesting a new view.
>

TagHandlers will also be called on the postback (much like
JSP-Tags,
they will also be executed on the postback as well).
TagHandlers won't
be executed for every row of a dataTable or a
<ui:repeat/>, however -
so you can't use tree-build-time functionality (like
tag-handlers,
e.g. c:if) in such iterating components, if you want them to
be
evaluated for every row anew.

regards,

Martin

------------------------------------------------------------
---------
To unsubscribe, e-mail: users-unsubscribefacelets.dev.java.net
For additional commands, e-mail: users-helpfacelets.dev.java.net


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )