3 Replies Latest reply on Aug 25, 2008 1:35 PM by sambolino.sambolino.gmail.com

    how to target s:message

    sambolino.sambolino.gmail.com

      greetings!


      i'm developing an app which uses facelets templates in a similar fashion like in seam examples.


      this is edit.xhtml



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



      and this is my point of interest


      <s:decorate id="d1" template="layout/edit.xhtml">
           <ui:define name="label">
           ...
           <ui:define/>
           <h:outputFormat id="o1" ... />
      </s:decorate>



      now, when user hits submit first i want to check the validity of some data and throw a message if something is wrong. so let's say the submit button calls for a method:



      public String validateAndSave() {
           if(somethingIsWrong) {
                FacesContext context = FacesContext.getCurrentInstance();
                FacesMessage message = new FacesMessage("i won't let you do this");
                context.addMessage("frmMain:d1:o1", message);
                return null;
           }
           else
           //do the job
           }



      this won't work. now my question is: how do i target s:message? also, one detail from edit.xhtml: what is #{invalid}? it only looks like a seam component, but there's no way to access it from the beans. how can i manually turn it on?


      thanks a lot, veljko