-
1. Re: display messages
danielc.roth Mar 26, 2008 3:29 PM (in response to lasansue.jeremy.girard.satives.fr)I would do:
<h:message for="name" styleClass="error" /> ... <h:message for="name2" styleClass="error" />
where name/name2 are id:s of some input field (inputText/commandButton etc)
and then catch the error and show it:try { em.persist(someThing); } catch(SomeException e) ( FacesMessages.instance().addToControl("name", "An error occured: #0", e.getMessage()) } catch(SomeOtherException e) ( FacesMessages.instance().addToControl("name", "An error that bla bla bla occured: #0", e.getMessage()) }
Hope this helps
-
2. Re: display messages
danielc.roth Mar 26, 2008 3:31 PM (in response to lasansue.jeremy.girard.satives.fr)The second addToControl should have been 'name2', but hopefully that was trivial to see :-)
Hence, depending on exception, diffrent h:messages are shown.
-
3. Re: display messages
lasansue.jeremy.girard.satives.fr Mar 26, 2008 3:42 PM (in response to lasansue.jeremy.girard.satives.fr)Thanks for this answer.
I want to use something like this but for successuful message generated by the home object
CommentHome extends extends AbstractHome<...> .... @Override public String getCreatedMessage() { return "Votre commentaire a été ajouté"; }
How can it specify to the h:message should display only messages from CommentHome ?
-
4. Re: display messages
lasansue.jeremy.girard.satives.fr Mar 27, 2008 8:15 AM (in response to lasansue.jeremy.girard.satives.fr)No idea ?
Is it impossible to filter the display of message from the home object ? -
5. Re: display messages
danielc.roth Mar 27, 2008 8:51 AM (in response to lasansue.jeremy.girard.satives.fr)Sorry, I haven't used home objects at all :/
If you just are trying to filter which messages to show, you could probably iterate over
List<FacesMessages> messages = FacesMessages.instance().getCurrentMessages()
and remove the ones you don't want to display.
-
6. Re: display messages
lasansue.jeremy.girard.satives.fr Mar 27, 2008 9:59 AM (in response to lasansue.jeremy.girard.satives.fr)In fact i do not want to filter message has you describe it.
I've got pages that made change on differents entities.I want my message to be displayed exactly were i want in the page.
Suppose i have two form in one page. Each form display a successfully created/updated message.
I want message from entity 1 to be displayed near the entity 1 form and message from the entity 2 to be displayed near the entity 1 form.
Now messages from both entity are displayed near all form. (in each h:messages in fact)
-
7. Re: display messages
lasansue.jeremy.girard.satives.fr Mar 27, 2008 5:12 PM (in response to lasansue.jeremy.girard.satives.fr)Is it possible to configure for each home object the target component for message display ?
-
8. Re: display messages
pmuir Mar 29, 2008 3:12 PM (in response to lasansue.jeremy.girard.satives.fr)Override createdMessage(), updatedMessage() and deletedMessage() and uses FacesMessages.instance(),addToControl() instead of adding to the global message pool.