-
1. Re: facesmessages in java code. Problem with the documentation
monkeyden Feb 2, 2011 12:05 PM (in response to aldian00)You're correct, the method should be returning some string, or null. Presumably, that return value is a string representing the JSF navigation rule, represented by
success
in the example below:<page view-id="/some/view-id.xhtml"> <navigation> <rule if-outcome="success"> <redirect view-id="/some/other/view-id.xhtml"/> </rule> </navigation> </page>
'Hello' in that case is a resource bundle key. All you need to do is add the message to your resource bundle, for example:
messages.hello=Hello
and have this in the code:
@Name("hello") @Stateless public class HelloBean implements Hello { @In FacesMessages facesMessages; //inject component public String sayIt() { facesMessages.addFromResourceBundle("messages.hello"); //add msg to component return "success"; //or null, to return to the same view id } }
then, in your view, you have an commandButton/link which has an action of
hello.sayIt
<h:commandButton id="sayItButton" value="Say It" action="#{hello.sayIt}" />
Once you have that working, explore the FacesMessages api for different ways to add the message, including Severity, message parameters, etc.
http://docs.jboss.com/seam/2.1.2/api/org/jboss/seam/faces/FacesMessages.html
Note that many FacesMessages methods have been deprecated in favor of StatusMessages, which are functionally similar.