0 Replies Latest reply on May 6, 2008 4:02 PM by timony

    jPDL +  validation

    timony

      Hi,
      I am using the jPDL for defining the work flow and also validate the fields in the form using the ajax rerender feature. If I enter invalid data to the field (e.g. leave the form empty for required fiedl) and leave the input, the validation work fine, the message is displayed that I left the field empty (what indicates that the validation is set-up properly).
      But when I send the data to the server by the nodes defined in jPDL, the data are sent allthrough some required fields are emtpy (or e.g. wrong number format is provided).
      I dont want to validate explicitly by using expression in the jPDL, if there is powerful validation framework built in Seam...




      Does anyone know where the problem is? Maybe I missed something really important on inserting the data by using jPDL.


      Here is the code:


      Starting the pageflow:



      <s:button action="#{companyHome.start}" value="#{messages.label_edit}" id="editCompany">
       <f:param name="companyId" value="#{companyHome.instance.id}" />
      </s:button>




      pageflow edit company:





      <?xml version="1.0"?>
      
      <pageflow-definition xmlns="http://jboss.com/products/seam/pageflow"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://jboss.com/products/seam/pageflow http://jboss.com/products/seam/pageflow-1.2.xsd"
           name="editCompany">
      
           <start-state name="start">
                <transition name="edit" to="edit" />
                <transition name="remove" to="confirmRemove" />
           </start-state>
           
           <page name="edit" view-id="/portfolio/companyEdit.xhtml">
                <redirect />
                <transition name="save" to="saveCompany" />
                <transition name="cancel" to="complete" />
           </page>
      
           <page name="confirmRemove" view-id="/confirm.xhtml">
                <redirect/>
                <transition name="yes" to="completeDelete" >
                     <action expression="#{companyHome.remove}" />
                </transition>
                <transition name="no" to="complete" />
           </page>
           
           <decision name="saveCompany"
                expression="#{companyHome.managed}">
                <transition name="true" to="complete">
                     <action expression="#{companyHome.update}" />
                </transition>
                <transition name="false" to="complete">
                     <action expression="#{companyHome.persist}" />
                </transition>
           </decision>
           
           <page name="complete" view-id="/portfolio/portfolio.xhtml"
                no-conversation-view-id="/portfolio/portfolio.xhtml">
                <redirect />
                <end-conversation />
           </page>
           
           <page name="completeDelete" view-id="/portfolio/portfolio.xhtml"
                no-conversation-view-id="/portfolio/portfolio.xhtml">
                <redirect />
                <end-conversation />
           </page>
      
      </pageflow-definition>




      CompanyHome (Seam framework)




      @Name("companyHome")
      @Restrict("#{identity.loggedIn}")
      @Scope(ScopeType.CONVERSATION)
      public class CompanyHome extends EntityHome<Company>
      {
      
          private static final long serialVersionUID = 9057915693870914547L;
      
          @RequestParameter
          Integer companyId;
      
          @RequestParameter
          String action;
      
          @In(value = "currentUser")
          User currentUser;
      
          @In(create = true)
          ProductHome productHome;
      
          @Begin(join = true, pageflow = "editCompany")
          public String start()
          {
              setCompanyId(companyId);
      
              if (action == null || "".equals(action))
              {
                  return CCConstants.OUTCOME_EDIT;
              }
              return action;
          }
      
          public void setCompanyId(Integer companyId)
          {
              if (companyId != null)
              {
                  setId(companyId);
              }
          }
      
          public Integer getCompanyId()
          {
              return (Integer) getId();
          }
      
          @Override
          protected Company createInstance()
          {
              Company company = new Company();
              company.setUser(currentUser);
              return company;
          }
      
      
      }




      The edit company xhtml:




           <ui:define name="body">
      
                <h:form id="companyEditForm">
      
                     <s:decorate template="../layout/editBox.xhtml" id="editBox">
      
                          <ui:define name="header">
                               <h:outputText value="#{companyHome.managed ? 'messages.label_company_edit': 'messages.label_company_create'}" />
                          </ui:define>
      
                          <ui:define name="buttons">
                               <s:button id="saveCompany" value="#{companyHome.managed ? messages.label_edit : messages.label_create}" action="save" disabled="#{companyBean.validationFailed}" />
                               <s:button id="cancelCompany" value="#{messages.label_cancel}"
                                    action="cancel" />
                          </ui:define>
      
                          <s:decorate id="nameDecoration"
                               template="../layout/edit.xhtml">
                               <ui:define name="label">#{messages.label_name}</ui:define>
                               <h:inputText required="true"
                                    value="#{companyHome.instance.name}">
                                    <a:support event="onblur" reRender="nameDecoration" />
                               </h:inputText>
                          </s:decorate>
                          
                     </s:decorate>
      
                </h:form>
      
           </ui:define>




      and the Entity bean Company:




      @Entity
      @Table(name = "company")
      public class Company implements Serializable, Idable<Integer>
      {
      
          private static final long serialVersionUID = 8106268264760054294L;
      
          @Id
          @GeneratedValue
          @Column(name = "id", unique = true, nullable = false)
          private Integer id;
      
          @NotNull
          @Required
          @Capitalized
          private String name;
      
          @OneToMany(mappedBy = "company", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
          private Collection<Product> products = new ArrayList<Product>(0);
      
          @ManyToOne
          @NotNull
          private User user;
      
          //getters and setters...