This discussion is archived
14 Replies Latest reply: May 31, 2012 5:25 AM by gimbal2 RSS

global messages and inilne messages both are being displayed

934728 Newbie
Currently Being Moderated
Hi,

I have a page index.xhtml in which i am including another page header.xhtml like this

<ui:insert name="header">
               <ui:include src="header.xhtml" />
          </ui:insert>
my header.xhtml is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
     xmlns:h="http://java.sun.com/jsf/html">
     
<body>
     <div id="header-container">
          <div id="header">

               <div class="left_logo">
                    <h:graphicImage library="images" name="trainings.jpg" width="339"
                         height="120" />
               </div>
               <div id="navigation">
                    <ul>
                         <li id="home-nav">JSF Training</li>
                         <li id="about-nav">About</li>
                    </ul>
               </div>
               <div class="clear"></div>

          </div>
     </div>
</body>
</html>

and index.xhtml is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:lang="en">
<body>
<f:view xmlns:c="http://java.sun.com/jstl/core"
     xmlns:s="http://www.springframework.org/tags"
     xmlns:form="http://www.springframework.org/tags/form">
     <h:head>

          <h:outputStylesheet library="css" name="style.css" target="head" />
          <meta http-equiv="content-type" content="text/html; charset=utf-8" />
          <title>#{msgs.welcome}</title>
          <link rel="shortcut icon" href="../resources/images/favicon.ico" />
          <link rel="stylesheet" href="../resources/css/style.css"
               type="text/css" media="all" />
     </h:head>
     <h:body class="home blog">
     
          <!-- <ui:composition template="baseTemplate.xhtml">
               <ui:define name="content"> -->
          <ui:insert name="header">
               <ui:include src="header.xhtml" />
          </ui:insert>
          <div id="home-training-container">
                         <h:form>
                              <table align="center">
                                   <tr>
                                        <td colspan="2" align="center"><font size="4"><b><h:outputLabel
                                                            value="#{msgs.welcomeTitle}" /></b></font></td>
                                   </tr>
                                   <tr>
                                        <td colspan="2"><font size="4"><b><h:outputLabel
                                                            value="#{msgs.homepageTitle}"></h:outputLabel></b></font></td>
                                   </tr>
                                   <tr>
                                        <td><h:outputLabel value="#{msgs.nameLabel}" /></td>
                                        <td><h:inputText binding="#{loginName}"
                                                  value="#{user.loginName}" id="loginName" label="Name"
                                                  required="true" requiredMessage="#{msgs.nameRequired}">
                                                  <f:validateLength minimum="5" maximum="20" />
                                                  <f:validateRegex pattern="#{msgs.regexPattern}"></f:validateRegex>
                                                  
                                             </h:inputText>
<h:message showSummary="true" showDetail="false"
                                                  for="loginName" errorClass="errors" globalOnly="true"></h:message>
                                        </td>
                                   </tr>
                                   <tr>
                                        <td><h:outputLabel value="#{msgs.passwordLabel}" /></td>
                                        <td><h:inputSecret binding="#{password}"
                                                  value="#{user.password}" id="password" required="true"
                                                  requiredMessage="#{msgs.passwordRequired}">
                                                  <f:validateLength minimum="3" maximum="20" />
                                             </h:inputSecret>
<h:message showSummary="true" showDetail="false"
                                                  for="password" errorClass="errors"></h:message>
                                             <!-- <h:message for="loginValid" errorClass="errors" globalOnly="true"></h:message> -->
                                        </td>
                                   </tr>
                                   <tr>
                                        <td><h:outputLabel value="#{msgs.roleLabel}" /></td>
                                        <td><h:selectOneMenu value="#{user.role}">
                                                  <f:selectItem itemValue="#{msgs.admin}"
                                                       itemLabel="#{msgs.admin}" />
                                                  <f:selectItem itemValue="#{msgs.guest}"
                                                       itemLabel="#{msgs.guest}" />
                                             </h:selectOneMenu></td>
                                   </tr>
                                   <tr>
                                        <td colspan="2" align="left"><h:commandButton
                                                  value="#{msgs.login}" action="#{user.login}"></h:commandButton>
                                        </td>
                                   </tr>
                                   <tr>
                                        <td colspan="2" align="right"><h:commandButton
                                                  value="#{msgs.registerNewUser}" action="#{user.addNewUser}"
                                                  immediate="true">
                                             </h:commandButton></td>
                                   </tr>
                              </table>
                         </h:form>
                    </div>
                    <ui:insert name="footer">
          <ui:include src="footer.xhtml"/>
     </ui:insert>          
     </h:body>
</f:view>
</body>
</html>

if an error occur then currently it is displaying below the text box and also at the top which should not happen. I want to show messages only below the corresponding text boxes.
how can i do it?

if i remove namespace declaration in header.xhtml like this
<div id="header-container">
          <div id="header">

               <div class="left_logo">
                    <h:graphicImage library="images" name="trainings.jpg" width="339"
                         height="120" />
                         <h:messages rendered="false" globalOnly="true" layout="table"/>
               </div>
               <div id="navigation">
                    <ul>
                         <li id="home-nav">JSF Training</li>
                         <li id="about-nav">About</li>
                    </ul>
               </div>
               <div class="clear"></div>
          </div>
     </div>

then top messages are not displayed but a warning message displayed
"Warning: This page calls for XML namespace declared with prefix div but no taglibrary exists for that namespace"

Please help me...

Edited by: 931725 on May 31, 2012 1:46 AM
  • 1. Re: global messages and inilne messages both are being displayed
    gimbal2 Guru
    Currently Being Moderated
    Don't remove the namespace declaration, remove the h:messages element. Makes sense doesn't it? You don't want to display the messages at the top, so remove the element that displays messages at the top.

    And the next time post code between \
     tags to actually make it readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  • 2. Re: global messages and inilne messages both are being displayed
    934728 Newbie
    Currently Being Moderated
    actually after removing the namespace declaration the actual code is
    <div id="header-container">
              <div id="header">
    
                   <div class="left_logo">
                        <h:graphicImage library="images" name="trainings.jpg" width="339"
                             height="120" />                         
                   </div>
    
                   <div id="navigation">
                        <ul>
                             <li id="home-nav"><a href="#">JSF Training</a></li>
                             <li id="about-nav"><a href="#">About</a></li>
                        </ul>
                   </div>
                   <div class="clear"></div>
    
              </div>
         </div>
    by mistake i put that h:messages code there. Even if i remove that h:messages tag then also messages are being displayed at the top..:(

    Edited by: 931725 on May 31, 2012 1:59 AM
  • 3. Re: global messages and inilne messages both are being displayed
    gimbal2 Guru
    Currently Being Moderated
    So is it perhaps in that template that you have?

    Its not appearing as if by magic, its not weird, its not unexplainable. Find the reason, but you have to want to look first before you are going to find it. It might require you to do some reading on the different elements used.
  • 4. Re: global messages and inilne messages both are being displayed
    934728 Newbie
    Currently Being Moderated
    i am not using that template. That is commented. I tried using template but same issue is coming.
    I amjust including a header.xhtml and when i declare a namespace and put the code under <body> code then global message starts displaying at top.
  • 5. Re: global messages and inilne messages both are being displayed
    gimbal2 Guru
    Currently Being Moderated
    If you don't want to make effort yourself to figure it out, then at least repost the code with code tags.
  • 6. Re: global messages and inilne messages both are being displayed
    934728 Newbie
    Currently Being Moderated
    i have made lot effort over this, but could not find the solution.. :|
    index.html is
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:lang="en">
    <body>
    <f:view xmlns:c="http://java.sun.com/jstl/core"
         xmlns:s="http://www.springframework.org/tags"
         xmlns:form="http://www.springframework.org/tags/form">     
         <h:head>
    
              <h:outputStylesheet library="css" name="style.css" target="head" />
              <meta http-equiv="content-type" content="text/html; charset=utf-8" />
              <title>#{msgs.welcome}</title>
              <link rel="shortcut icon" href="../resources/images/favicon.ico" />
              <link rel="stylesheet" href="../resources/css/style.css"
                   type="text/css" media="all" />
         </h:head>
         <h:body class="home blog">
                 <ui:insert name="header">
                   <ui:include src="header.xhtml" />
              </ui:insert>
              <div id="home-training-container">
                             <h:form>
                                  <table align="center">
                                       <tr>
                                            <td colspan="2" align="center"><font size="4"><b><h:outputLabel
                                                                value="#{msgs.welcomeTitle}" /></b></font></td>
                                       </tr>
                                       <tr>
                                            <td colspan="2"><font size="4"><b><h:outputLabel
                                                                value="#{msgs.homepageTitle}"></h:outputLabel></b></font></td>
                                       </tr>
                                       <tr>
                                            <td><h:outputLabel value="#{msgs.nameLabel}" /></td>
                                            <td><h:inputText binding="#{loginName}"
                                                      value="#{user.loginName}" id="loginName" label="Name"
                                                      required="true" requiredMessage="#{msgs.nameRequired}">
                                                      <f:validateLength minimum="5" maximum="20" />
                                                      <f:validateRegex pattern="#{msgs.regexPattern}"></f:validateRegex>
                                                      <br />
                                                 </h:inputText><br /> <h:message showSummary="true" showDetail="false"
                                                      for="loginName" errorClass="errors" globalOnly="true"></h:message>
                                            </td>
                                       </tr>
                                       <tr>
                                            <td><h:outputLabel value="#{msgs.passwordLabel}" /></td>
                                            <td><h:inputSecret binding="#{password}"
                                                      value="#{user.password}" id="password" required="true"
                                                      requiredMessage="#{msgs.passwordRequired}">
                                                      <f:validateLength minimum="3" maximum="20" />
                                                 </h:inputSecret><br /><h:message showSummary="true" showDetail="false"
                                                      for="password" errorClass="errors"></h:message>
                                                 <!-- <h:message for="loginValid" errorClass="errors" globalOnly="true"></h:message> -->
                                            </td>
                                       </tr>
                                       <tr>
                                            <td><h:outputLabel value="#{msgs.roleLabel}" /></td>
                                            <td><h:selectOneMenu value="#{user.role}">
                                                      <f:selectItem itemValue="#{msgs.admin}"
                                                           itemLabel="#{msgs.admin}" />
                                                      <f:selectItem itemValue="#{msgs.guest}"
                                                           itemLabel="#{msgs.guest}" />
                                                 </h:selectOneMenu></td>
                                       </tr>
                                       <tr>
                                            <td colspan="2" align="left"><h:commandButton
                                                      value="#{msgs.login}" action="#{user.login}"></h:commandButton>
                                            </td>
                                       </tr>
                                       <tr>
                                            <td colspan="2" align="right"><h:commandButton
                                                      value="#{msgs.registerNewUser}" action="#{user.addNewUser}"
                                                      immediate="true">
                                                 </h:commandButton></td>
                                       </tr>
    
    
                                  </table>
    
                             </h:form>
                        </div>
                         <ui:insert name="footer">
                                    <ui:include src="footer.xhtml"/> 
                                 </ui:insert>          
         </h:body>
    </f:view>
    </body>
    </html>
    header.xhtml is
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:h="http://java.sun.com/jsf/html">
         
    <body>
         <div id="header-container">
              <div id="header">
    
                   <div class="left_logo">
                        <h:graphicImage library="images" name="trainings.jpg" width="339"
                             height="120" />
                   </div>
    
                   <div id="navigation">
                        <ul>
                             <li id="home-nav"><a href="#">JSF Training</a></li>
                             <li id="about-nav"><a href="#">About</a></li>
                        </ul>
                   </div>
                   <div class="clear"></div>
    
              </div>
         </div>
    </body>
    </html>
  • 7. Re: global messages and inilne messages both are being displayed
    r035198x Pro
    Currently Being Moderated
    931725 wrote:
    i am not using that template. That is commented. I tried using template but same issue is coming.
    Also try removing the code completely instead of commenting out and be sure to tell your browser to reload the page rather than serve it from some cache.
  • 8. Re: global messages and inilne messages both are being displayed
    934728 Newbie
    Currently Being Moderated
    Also tried after removing the commented code and clearing the cache of browser but still facing same issue...
  • 9. Re: global messages and inilne messages both are being displayed
    934728 Newbie
    Currently Being Moderated
    SOLVED...


    Change the PROJECT_STAGE value in web.xml to Production from Development
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
      </context-param>
  • 10. Re: global messages and inilne messages both are being displayed
    gimbal2 Guru
    Currently Being Moderated
    931725 wrote:
    SOLVED...


    Change the PROJECT_STAGE value in web.xml to Production from Development
    <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
    </context-param>
    ??? That's weird, I have it set to development myself and I don't experience this issue. What version of JSF 2 are you using exactly? If it is an older one I would try upgrading to the latest release, you might be running into a bug that has already been fixed.

    Oops I have to eat my earlier words; it IS weird :)
  • 11. Re: global messages and inilne messages both are being displayed
    r035198x Pro
    Currently Being Moderated
    931725 wrote:
    SOLVED...


    Change the PROJECT_STAGE value in web.xml to Production from Development
    <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
    </context-param>
    If PROJECT_STAGE is set to Development then the cache duration is ignored so there is a better chance of getting the updated page but Development mode also results in more error feedback being rendered :http://weblogs.java.net/blog/driscoll/archive/2009/09/28/jsf-20-reminder-project-stage
    Would be awesome if there is a page describing the property more fully/formally
  • 12. Re: global messages and inilne messages both are being displayed
    gimbal2 Guru
    Currently Being Moderated
    r035198x wrote:
    931725 wrote:
    SOLVED...


    Change the PROJECT_STAGE value in web.xml to Production from Development
    <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
    </context-param>
    If PROJECT_STAGE is set to Development then the cache duration is ignored so there is a better chance of getting the updated page but Development mode also results in more error feedback being rendered :http://weblogs.java.net/blog/driscoll/archive/2009/09/28/jsf-20-reminder-project-stage
    Would be awesome if there is a page describing the property more fully/formally
    the main thing that happens is that JSF starts to moan that components are not in a form and such.

    Speaking of which, I noticed that a regular <body> tag is being used in header.xhtml in stead of <h:body>. Perhaps that is exactly a source of development specific messages. Also, style.css is linked twice in the index.xhtml; once through a JSF resource and once "hardcoded" the HTML way.
  • 13. Re: global messages and inilne messages both are being displayed
    934728 Newbie
    Currently Being Moderated
    I am using this artifact in maven
    <dependency>
         <groupId>com.sun.faces</groupId>
         <artifactId>jsf-api</artifactId>
         <version>2.1.0-b03</version>
    </dependency>
  • 14. Re: global messages and inilne messages both are being displayed
    gimbal2 Guru
    Currently Being Moderated
    That would be a very old version. Its not provided, so it is deployed in your war file?

    Try with this artifact in stead to force the latest version:
    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.faces</artifactId>
      <version>2.1.8</version>
    </dependency>
    (information taken from the JSF download page: http://javaserverfaces.java.net/download.html)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points