2 Replies Latest reply on Oct 31, 2009 4:56 PM by Petr Jung

    addToControlFromResourceBundle messages aren't <s:decorate>d when using generated demo

    Petr Jung Newbie
      Hi,
      I'm using Seam 2.2.0.GA as it was distributed on a JBoss AS 5.1.0.GA and have also problems with decorating invalid input fields.
      I have read a topic, with similar name. The result of this topic, if I understood correctly was add the message to the component and  return null.
      I have to say, I am using the seam generated application from database. I have just added to the DeviceHome extends EntityHome<Device> a unique key validation.

      like:

              /* (non-Javadoc)
               * @see org.jboss.seam.framework.EntityHome#persist()
               */
              @Override      
              public String persist() {
                      Query query = getEntityManager().createQuery("select device from Device device where device.device = #{device.device}");
                     
                      if (query.getResultList().size() > 0) {
                              if (facesMessages != null) {
                                      facesMessages.addToControlFromResourceBundle("device", Severity.ERROR, "device.device.exists");
                                      return null;
                              }
                              throw new AlreadyExistsException("device.device.exists");
                      }
                      return super.persist();
              }

              /* (non-Javadoc)
               * @see org.jboss.seam.framework.EntityHome#update()
               */
              @Override
              public String update() {
                      Query query = getEntityManager().createQuery("select device from Device device where device.device = #{device.device} and not (device.id = #{device.id})");
                     
                      if (query.getResultList().size() > 0) {
                              if (facesMessages != null) {
                                      facesMessages.addToControlFromResourceBundle("device", Severity.ERROR, "device.device.exists");
                                      return null;
                              }
                              throw new AlreadyExistsException("device.device.exists");
                      }
                      return super.update();
              }

      I do not see my "device.device.exists" message till I set up the <h:messages globalOnly="false".
      Message is present, but not correctly assigned to the control. Is it possible, there is another limitation, which is not taken in a account in your demo?

      my form begins with:

      <ui:define name="body">
          <h:form id="device" styleClass="edit">

              <rich:panel>
                  <f:facet name="header">#{deviceHome.managed ? 'Edit' : 'Add'} Device</f:facet>

                              <h:inputHidden id="id" value="#{device.id}" />

                  <s:decorate id="deviceField" for="device" template="layout/edit.xhtml" >
                      <ui:define name="label">Device</ui:define>
                      <h:inputText id="device" required="true" size="50" maxlength="50" value="#{device.device}" >
                           <a:support event="onblur" reRender="deviceField" bypassUpdates="true" ajaxSingle="true"  />                                 
                      </h:inputText>
                  </s:decorate>

      my edit.xml:

          <div class="prop">

              <s:label styleClass="name #{invalid?'errors':''}">
                  <ui:insert name="label"/>
                  <s:span styleClass="required" rendered="#{required}">*</s:span>
              </s:label>

              <span class="value #{invalid?'errors':''}">
                  <s:validateAll>
                      <ui:insert/>
                  </s:validateAll>
              </span>
              <span class="error">
                  <h:graphicImage value="/img/error.gif" rendered="#{invalid}" styleClass="errors"/>
                  <s:message styleClass="errors"/>
              </span>
          </div>


      Thanks for a help.
      Petr