3 Replies Latest reply on Jan 1, 2008 12:58 PM by yilmaz_

    s:validateAll not working here

    inscanc

      i think i am doing something wrong because my s:validateAll seem not working

      this is my code

      addGadget.xhtml
      --------------------------
      <!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:richfaces="http://richfaces.ajax4jsf.org/rich"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:s="http://jboss.com/products/seam/taglib">


      <f:view>
      New Gadget
      <h:form>
      <s:validateAll>
      <h:panelGrid columns="2">
      Description: <h:inputText value="#{gadget.description}" />
      Type: <h:inputText value="#{gadget.type}" />
      </h:panelGrid>
      </s:validateAll>
      <h:commandButton action="#{gadgetManager.addGadget}" value="Add"
      type="submit" />
      </h:form>
      <h:messages globalOnly="false" />
      </f:view>




      Gadget.java
      -------------------------
      package org.domain.gadgetcatalog.entity;

      import java.io.Serializable;

      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;

      import org.hibernate.validator.NotNull;
      import org.jboss.seam.annotations.Name;

      @Entity
      @Name("gadget")
      public class Gadget implements Serializable{
      private Long id;
      private String description;
      private String type;

      public Gadget() {
      // TODO Auto-generated constructor stub
      }

      @Id @GeneratedValue
      public Long getId() {
      return id;
      }

      public void setId(Long id) {
      this.id = id;
      }

      @NotNull
      public String getDescription() {
      return description;
      }

      public void setDescription(String description) {
      this.description = description;
      }

      @NotNull
      public String getType() {
      return type;
      }

      public void setType(String type) {
      this.type = type;
      }

      }




      GadgetManager.java
      --------------------------
      package org.domain.gadgetcatalog.session;

      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.Iterator;
      import java.util.List;

      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;

      import org.domain.gadgetcatalog.entity.Gadget;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.faces.FacesMessages;

      @Stateless
      @Name("gadgetManager")
      public class GadgetManager implements IGadgetManager, Serializable {
      @PersistenceContext
      private EntityManager em;

      @In(required=false)
      private Gadget gadget;

      public String addGadget() {
      try {
      em.persist(gadget);
      } catch (Exception e) {
      FacesMessages.instance().add("Error adding the new gadget");
      }
      return "listGadgets";
      }

      public List getAllGadgets() {
      List gadgets = new ArrayList();
      try {
      Iterator it = em.createQuery("select g from Gadget as g order by g.id").getResultList().iterator();
      while (it.hasNext()) {
      gadgets.add((Gadget) it.next());
      }
      } catch (Exception e) {
      e.printStackTrace();
      }
      return gadgets;
      }

      public Gadget getGadget() {
      return gadget;
      }

      public void setGadget(Gadget gadget) {
      this.gadget = gadget;
      }

      }