users@glassfish.java.net

Re: JSF's requiredMessage attribute and JSF EL

From: <glassfish_at_javadesktop.org>
Date: Mon, 16 Jul 2007 11:28:01 PDT

Thanks, rlubke.

faces-config.xml:
&lt;faces-config&gt;
    &lt;managed-bean&gt;
        &lt;managed-bean-name&gt;entrance&lt;/managed-bean-name&gt;
        &lt;managed-bean-class&gt;
            example.Entrance
        &lt;/managed-bean-class&gt;
        &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt;
    &lt;/managed-bean&gt;
    &lt;navigation-rule&gt;
        &lt;from-view-id&gt;/entrance.jsp&lt;/from-view-id&gt;
        &lt;navigation-case&gt;
            &lt;from-outcome&gt;success&lt;/from-outcome&gt;
            &lt;to-view-id&gt;/ok.jsp&lt;/to-view-id&gt;
            &lt;redirect/&gt;
        &lt;/navigation-case&gt;
    &lt;/navigation-rule&gt;
&lt;/faces-config&gt;


entrance.jsp:
&lt;%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%&gt;
&lt;%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%&gt;
&lt;html&gt;
&lt;body&gt;
&lt;f:view&gt;
    &lt;f:loadBundle basename="msg" var="msg" /&gt;
    &lt;h1&gt;TEST&lt;/h1&gt;
    &lt;h:form&gt;
        &lt;h:outputText value="#{msg.keyword_required}" /&gt;
        &lt;h:inputText id="keyword" value="#{entrance.keyword}" required="true"
            requiredMessage="#{msg.keyword_required}" /&gt;
        &lt;h:commandButton id="submit" action="#{entrance.search}"
            value="#{msg.search}" /&gt;
        &lt;h:message for="keyword" /&gt;
    &lt;/h:form&gt;
&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;

web.xml:
&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:j2ee="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
&lt;/web-app&gt;

You can see "KEYWORD REQUIRED" at h:outputText but cannot see at h:message. Moreover, you can see "FOO" at h:message.
[Message sent by forum member 'nakamurakenichi' (nakamurakenichi)]

http://forums.java.net/jive/thread.jspa?messageID=226807