-
1. Re: Seam-faces messages, and @PostConstruct
piklos Jun 8, 2011 7:57 AM (in response to piklos)It seems that i found something that could be a source of this behaviour.
namely if you have messages in your post construct method on a bean,
your<h:messages />
Must appear after (not before) your first appearence of your bean.
So if you got a bean with a post construct method like this one:
public @Model class HelloWorld { @PostConstruct public void initialize() { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("A Message.")); } }
And a page like this one:
<h:messages /> <span style="color: blue;">#{helloWorld.text}</span>
You messages will be empty.
But if you rearrange your page to look like this:
<span style="color: blue;">#{helloWorld.text}</span> <h:messages />
The messages will be displayed.
It looks to me as if facelets evaluate everything from top to bottom really eagerly.
That why the messages are empty in the first case.Please let someone correct me if i am wrong with this.
Thanks in advance.
PS. If i am not wrong, than maybe there should be a worn in the documentation about this feature??
-
2. Re: Seam-faces messages, and @PostConstruct
lightguard Jun 8, 2011 3:03 PM (in response to piklos)I'd be very interested to see what happen if you use an h:ouputText instead of the direct EL output. I bet it works the way you want it to.
-
3. Re: Seam-faces messages, and @PostConstruct
piklos Jun 9, 2011 3:02 AM (in response to piklos)Yep you are right,
with<h:outputText.../>
the position is not important.
Thank you.So can somebody give me a link with the explanation of differences between directly using EL and using it through a jsf component?
I mean,<h:outputText style="color: blue; .../>
gets rendered as
<span style="color: blue;">...</span>
(the same html that i put there by hand).
So just by looking at the ending html there is no difference at all. Yet one works and one doesn't.Should i because of this example conclude that whenever i have an option to choose between plane html with EL, and a jsf commponent that will end up the same, that i should always use jsf component??
Thanks in advance.
-
4. Re: Seam-faces messages, and @PostConstruct
lightguard Jun 9, 2011 3:27 AM (in response to piklos)Now you're getting into some of the intricacies of JSF and the JSF lifecycle. The problem you're experiencing is that the messages tag will already have it's content by the time you reach RENDER_RESPONSE (typically it's all figured out in INVOKE_APPLICATION, assuming you don't short circuit the lifecycle).
Your EL output is only being invoked in RENDER_RESPONSE because it's not associated with a JSF component, so the @PostConstruct happens too late to add any messages. The output that's created and sent to the buffer has to be done from top to bottom once the values are determined otherwise your resulting HTML would be messed up. You could verify this with a debugger and getting a handle on the FacesContext and seeing what phase you're in during the @PostConstruct method.
A good general rule: If you need something to affect the component tree or values in other components, you have to use a component so everything is done in the correct order. If it doesn't matter, then you're fine with the EL output.
-
5. Re: Seam-faces messages, and @PostConstruct
piklos Jun 9, 2011 4:10 AM (in response to piklos)Thanks a lot for a very good explanation.
I already messed with the debbuger during my session with this yesterday, and @PostConstruct was indeed called in render response phase.If this forum had a point system, i would have given you maximum points available :)
Thanks again.