8 Replies Latest reply on Mar 30, 2010 9:34 AM by Nick Belaevski

    Get a error message with <rich:message  style="color:red" for="" id="" />

    Thang Phan Apprentice

      Hello everybody!

      I'm a student of a University of HCM city.

      I would to display a error message in JSF page!

      This error message is got in server!

      Thereinafter, there are two file :

       

      Student.java:

      public String addStudent() throws Exception {
              FacesContext facesContext = FacesContext.getCurrentInstance();
              if (StudentDB.checkUsername(username)) {
                  FacesMessage message = new FacesMessage(
                          "Please check your Username again!");
                  facesContext.addMessage("errUserName", message);
              } else {
                  Student st = new Student(username, password, email, age, phone,
                          "user");
                  boolean re = StudentDB.addStudent(st);
                  FacesMessage mes;
                  if (re)
                      mes = new FacesMessage("Add Student is successfull!");
                  else
                      mes = new FacesMessage("Add Student is not successfull!");

                  facesContext.addMessage("errUserName", mes);

              }
              return "addStudent";
          }

       

      index.jsp:

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:a4j="http://richfaces.org/a4j"
          xmlns:rich="http://richfaces.org/rich">

      <f:view>
              <h:form>

                     .....

                     <rich:message for="errUserName" style="color:red" />

                     ....

           </h:form>
          </f:view>
      </ui:composition>

       

       

      I would to display a error message in JSF page!

      Can you help me to discuss this problem?

      Thank you very much!

       

      ThangPhan!