[jboss-user] [JBoss Seam] - Re: @IfInvalid is out, so?

SmokingAPipe do-not-reply at jboss.com
Thu Dec 14 17:04:44 EST 2006


What's happening is that the action is being called even though the input is not valid.  My thought was that if the object is not valid, the page should re-display, without calling the action, right?

Here's some code:

In test.jsp:

            <h:form id="createTestBean">
  |                 <s:validateAll>
  |                     <h:panelGrid columns="3"  border="3" >
  |                         
  |                         <h:outputLabel for="foo">
  |                             <h:outputText value="Foo:"/>
  |                         </h:outputLabel>
  |                         <h:inputText id="foo" value="#{testBean.foo}"/>
  |                         <h:message for="foo"/>
  |                         
  |                         
  |                         <h:outputLabel for="bar">
  |                             <h:outputText value="Bar:"/>
  |                         </h:outputLabel>
  |                         <h:inputText id="bar" value="#{testBean.bar}"/>
  |                         <h:message for="bar"/>
  |                         
  |                     </h:panelGrid>
  | 
  |                     <h:messages globalOnly="false"/>
  |                     
  |                     <h:commandButton value="Create new test bean" action="#{testManager.persist}"/>
  |                     <h:commandButton value="Reset" type="reset"/>
  |                 </s:validateAll>
  |             </h:form>

And the action:

@Stateful
  | @Name("testManager")
  | public class TestManagerAction implements TestManager {
  |     private static final Logger logger = 
  |             Logger.getLogger("TESTMANAGER");
  |     
  |     
  |     /** Creates a new instance of TestAction */
  |     public TestManagerAction() {
  |     }
  |     
  |     /** This thing is just injected, not created! */
  |     @In(create=true) EntityManager smpc;
  |     
  |     /** This is one to persist */
  |     @In(create=true) @Out TestBean testBean;
  |     
  |     @DataModel
  |     List<TestBean> testBeans;
  |     
  |     @DataModelSelection
  |     TestBean selectedTestBean;
  |     
  |     @Factory("testBeans") 
  |     public void testBeansFactory() {
  |         if(smpc == null) {
  |             logger.severe("OH NO! there was no entity manager");
  |             return;
  |         }
  |         
  |         final Query query = smpc.createQuery("from TestBean t " +
  |                 "order by foo");
  |         testBeans = query.getResultList();
  |         
  |     }
  |     
  |     public String persist() {
  |         if(smpc == null) {
  |             logger.severe("OH NO! there was no entity manager");
  |             return null;
  |         }
  | 
  |         smpc.persist(testBean);
  |         testBean = new TestBean();
  |         
  |         return null;
  |     }
  | 
  |     @In(create=true)
  |     private transient FacesMessages facesMessages;
  |     
  |     @Remove @Destroy
  |     public void destroy() { }
  |     
  | }
  | 

and the bean itself, boilerplate removed:

@Entity 
  | @Name("testBean")
  | public class TestBean {
  |     
  |     private int id;
  |     @Id @GeneratedValue public int getId() { return id; }
  |     public void setId(int id) { this.id = id; }
  |         
  |     private String foo;
  |     private String bar;
  | 
  |     @Length(min=5,max=8,message="Length must be from 5 to 8 chars bozo")
  |     public String getFoo() {
  |         return foo;
  |     }
  | 
  |     public void setFoo(String foo) {
  |         this.foo = foo;
  |     }
  | 
  |     public String getBar() {
  |         return bar;
  |     }
  | 
  |     public void setBar(String bar) {
  |         this.bar = bar;
  |     }
  |     
  |     public String toString() {
  |         return "TestBean " + id + "; foo= " + foo + ", bar = " + bar;
  |     }
  |     
  | }
  | 

Whenever I use the form, if I enter an invalid field, it attempts to do the persist and then throws an exception.  What it should do is redisplay the page with the validation message, and not even attempt to persist it.  I don't get it.

This is all with Seam 1.1.0 GA and JBoss 4.0.5 GA.

Any ideas on this?  It must be something simple I'm missing.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3994046#3994046

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3994046



More information about the jboss-user mailing list