Form does not validate on submit, but does on blur
timony Mar 31, 2008 2:29 PMHi,
when I go through the form by tab key (triggering the onblur), the validations work fine (e.g. for the required fields, or regex and the correct message is displayd next the input field, but when I submit the form, the validations are not employed
Curious is, that for some jpdl pageflows, the validations work fine
Does anyone know what is wrong?
Thanks
JPDL definition
<?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>
Home object (Seam framework)
package cz.timony.portfolioManager.session.portfolio; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Begin; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.security.Restrict; import org.jboss.seam.annotations.web.RequestParameter; import org.jboss.seam.framework.EntityHome; import cz.timony.portfolioManager.CCConstants; import cz.timony.portfolioManager.ejb.portfolio.Company; import cz.timony.portfolioManager.ejb.portfolio.Product; import cz.timony.portfolioManager.ejb.user.User; @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; } public List<Product> getProducts() { return getInstance() == null ? null : new ArrayList<Product>( getInstance().getProducts()); } public BigDecimal getSumActualStates(Company company) { BigDecimal sum = new BigDecimal(0); for (Product p : company.getProducts()) { BigDecimal latest = productHome.getLatestState(p.getId()) .getValue(); sum = sum.add(latest); } return sum; } public BigDecimal getSumActualStates() { return getSumActualStates(getInstance()); } }
EJB model class
package cz.timony.portfolioManager.ejb.portfolio; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import org.hibernate.validator.NotNull; import cz.timony.portfolioManager.ejb.Idable; import cz.timony.portfolioManager.ejb.user.User; import cz.timony.portfolioManager.validation.Required; @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 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; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Collection<Product> getProducts() { return products; } public void setProducts(Collection<Product> products) { this.products = products; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } }
JSF page for edit/insert company
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:a="https://ajax4jsf.dev.java.net/ajax" template="../layout/template.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> </ui:composition>
JSF fragment which starts the JPDL edit flow
<s:button action="#{companyHome.start}" value="#{messages.label_add}" id="newCompany" />