3 Replies Latest reply on Sep 19, 2007 9:11 AM by davidclf

    model validation failed

    davidclf

      I try to migrate Dan Allen's <<Seamless JSF>> example to seam 2.0,
      the program startups success,but when I edit the course and click save button,the page return "model validation failed" message!
      follows is error page:

      "Course Name
      Type Public Private Semi-Private Resort Military
      Website
      Phone
      Country model validation failed:/courseEditor.jspx @70,116 value="#{course.address.country}": Target Unreachable, 'address' returned null on 'com.ibm.dw.open18.Course'
      State model validation failed:/courseEditor.jspx @78,86 value="#{course.address.state}": Target Unreachable, 'address' returned null on 'com.ibm.dw.open18.Course'
      County model validation failed:/courseEditor.jspx @88,114 value="#{course.address.county}": Target Unreachable, 'address' returned null on 'com.ibm.dw.open18.Course'
      City model validation failed:/courseEditor.jspx @96,110 value="#{course.address.city}": Target Unreachable, 'address' returned null on 'com.ibm.dw.open18.Course'
      ZIP Code model validation failed:/courseEditor.jspx @104,122 value="#{course.address.postalCode}": Target Unreachable, 'address' returned null on 'com.ibm.dw.open18.Course''
      

      my web.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
       version="2.4">
      
       <display-name>Open 18 (Phase 1)</display-name>
       <description>JBoss Seam Sample Application</description>
      
       <context-param>
       <description>
       Comma separated list of URIs that serve as spring configuration files
       </description>
       <param-name>contextConfigLocation</param-name>
       <param-value>
       /WEB-INF/spring-beans.xml
       </param-value>
       </context-param>
      
       <filter>
       <filter-name>Seam Redirect Filter</filter-name>
       <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
       </filter>
      
       <filter-mapping>
       <filter-name>Seam Redirect Filter</filter-name>
       <url-pattern>*.action</url-pattern>
       </filter-mapping>
      
       <listener>
       <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
       </listener>
      
       <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>
      
       <listener>
       <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
       </listener>
      
       <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>client</param-value>
       </context-param>
      
       <context-param>
       <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
       <param-value>.jspx</param-value>
       </context-param>
      
       <servlet>
       <servlet-name>Faces Servlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
       </servlet>
      
       <servlet-mapping>
       <servlet-name>Faces Servlet</servlet-name>
       <url-pattern>*.action</url-pattern>
       </servlet-mapping>
      
       <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
       </welcome-file-list>
      
      </web-app>
      


      my componets.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:persistence="http://jboss.com/products/seam/persistence"
       xmlns:transaction="http://jboss.com/products/seam/transaction"
       xmlns:spring="http://jboss.com/products/seam/spring"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd
       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
      
       <!-- NOTE: this file can be used to provide IoC injection of spring-defined beans, instead of using the @In annotation -->
      
       <!-- enable the /debug.action page -->
       <core:init debug="true" />
      
       <!--
       <core:pages no-conversation-view-id="/main.jspx" />
       -->
      
       <core:manager conversation-timeout="60000"
       concurrent-request-timeout="500"
       conversation-id-parameter="cid" />
      
      
       <!--
       <core:ejb installed="false" />
       <core:microcontainer installed="false" />
       -->
      
       <!--<persistence:hibernate-session-factory name=""/>-->
      
       <persistence:managed-hibernate-session name="courseDatabase"
       session-factory="#{sessionFactory}"
       auto-create="true"/>
      
       <transaction:hibernate-transaction session="#{courseDatabase}"/>
      
       <!-- Enabling the debug property will generate an AJAX console (but you could just use FireBug) -->
       <component name="org.jboss.seam.remoting.remotingConfig">
       <property name="debug">false</property>
       </component>
      
      </components>
      

      my faces-config.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE faces-config
      PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
       "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
      <faces-config>
      
       <application>
       <view-handler>
       com.sun.facelets.FaceletViewHandler
       </view-handler>
       <variable-resolver>
       org.springframework.web.jsf.DelegatingVariableResolver
       </variable-resolver>
       <locale-config>
       <default-locale>en_US</default-locale>
       </locale-config>
       <message-bundle>MessageBundle</message-bundle>
       </application>
      
      </faces-config>
      


      the courseEditor.jspx:
      <?xml version="1.0" encoding="UTF-8"?>
      <jsp:root xmlns="http://www.w3.org/1999/xhtml"
       xmlns:jsp="http://java.sun.com/JSP/Page"
       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:s="http://jboss.com/products/seam/taglib"
       xmlns:c="http://java.sun.com/jstl/core" version="2.0">
       <ui:composition template="/templates/master.jspx">
       <ui:define name="title">
       <h:outputText value="#{course.id gt 0 ? 'Edit' : 'Create'} Course" />
       </ui:define>
       <ui:define name="body">
       <h:form id="course">
       <s:validateAll>
       <f:facet name="aroundInvalidField">
       <s:span styleClass="invalid"/>
       </f:facet>
       <f:facet name="afterInvalidField">
       <s:span styleClass="message">#{spacer}<s:message showDetail="true" showSummary="false" /></s:span>
       </f:facet>
       <table class="detail">
       <colgroup>
       <col width="20%" />
       <col width="80%" />
       </colgroup>
       <tr>
       <th><h:outputLabel for="name" value="Course Name" /></th>
       <td>
       <s:decorate>
       <h:inputText id="name" value="#{course.name}" size="40" styleClass="text"/>
       </s:decorate>
       </td>
       </tr>
       <tr>
       <th><h:outputLabel for="type" value="Type" /></th>
       <td>
       <s:decorate>
       <h:selectOneMenu id="type" value="#{course.type}">
       <s:convertEnum />
       <s:enumItem enumValue="PUBLIC" label="Public" />
       <s:enumItem enumValue="PRIVATE" label="Private" />
       <s:enumItem enumValue="SEMI_PRIVATE" label="Semi-Private" />
       <s:enumItem enumValue="RESORT" label="Resort" />
       <s:enumItem enumValue="MILITARY" label="Military" />
       </h:selectOneMenu>
       </s:decorate>
       </td>
       </tr>
       <tr>
       <th><h:outputLabel for="uri" value="Website" /></th>
       <td>
       <s:decorate>
       <h:inputText id="uri" value="#{course.uri}" size="40" styleClass="text" />
       </s:decorate>
       </td>
       </tr>
       <tr>
       <th><h:outputLabel for="phone" value="Phone" /></th>
       <td>
       <s:decorate>
       <h:inputText id="phone" value="#{course.phoneNumber}" size="10" styleClass="text" />
       </s:decorate>
       </td>
       </tr>
       <tr>
       <th><h:outputLabel for="country" value="Country" /></th>
       <td>
       <s:decorate>
       <h:inputText id="country" value="#{course.address.country}" required="true" size="40" styleClass="text" />
       </s:decorate>
       </td>
       </tr>
       <tr>
       <th><h:outputLabel for="state" value="State" /></th>
       <td>
       <s:decorate>
       <h:selectOneMenu id="state" value="#{course.address.state}" required="true">
       <s:selectItems var="state" value="#{states}" label="#{state}" noSelectionLabel="" />
       </h:selectOneMenu>
       </s:decorate>
       </td>
       </tr>
       <tr>
       <th><h:outputLabel for="county" value="County" /></th>
       <td>
       <s:decorate>
       <h:inputText id="county" required="true" value="#{course.address.county}" size="40" styleClass="text" />
       </s:decorate>
       </td>
       </tr>
       <tr>
       <th><h:outputLabel for="city" value="City" /></th>
       <td>
       <s:decorate>
       <h:inputText id="city" required="true" value="#{course.address.city}" size="40" styleClass="text" />
       </s:decorate>
       </td>
       </tr>
       <tr>
       <th><h:outputLabel for="postalCode" value="ZIP Code" /></th>
       <td>
       <s:decorate>
       <h:inputText id="postalCode" required="true" value="#{course.address.postalCode}" size="40" styleClass="text" />
       </s:decorate>
       </td>
       </tr>
       <tr>
       <th><h:outputLabel for="description" value="Description" /></th>
       <td>
       <s:decorate>
       <h:inputTextarea id="description" value="#{course.description}" cols="38" rows="4"/>
       </s:decorate>
       </td>
       </tr>
       </table>
      </s:validateAll>
      <p class="commands">
       <h:commandButton id="save" action="#{courseAction.saveCourse}" value="Save" styleClass="button" />
       #{spacer}
       <s:button id="cancel" action="#{courseAction.clearSelection}" value="Cancel" styleClass="button" />
      </p>
       </h:form>
       </ui:define>
      </ui:composition>
      </jsp:root>
      


      Any idea to solve it ? Is it a bug ?
      Many thanks in advance!


        • 1. Re: model validation failed
          dan.j.allen

          I wouldn't jump to it being a bug just yet. Most likely there is a restriction in the Hibernate validator that perhaps wasn't being applied before. I will try to take a look at it, but I am pretty jammed for time right now.

          However, what I can promise is that I am going to see if IBM will let me attach a Seam 2.0 version of the examples for the articles. That way you can be sure it will work ;) Don't expect anything in the next week though...I have a major deadline for Seam in Action that I am racing to meet.

          • 2. Re: model validation failed
            davidclf

            thank your reply.
            I traced the Seam 2.0 source and myfaces 1.2 source.And I Found that problem caused by myface 1.2 bug.
            In PropertyResolverToELResolver.java:
            private T invoke(ELContext context, Object base, Object property, ResolverInvoker invoker)
            myfaces set context.setPropertyResolved(true);
            but In PropertyResolverToELResolver.java:
            public Object getValue(ELContext context, Object base, Object property)
            myfaces return null, that cause the model validation failed

            • 3. Re: model validation failed
              davidclf

              the bug has been reported at myfaces MYFACES-1670,
              https://issues.apache.org/jira/browse/MYFACES-1670
              is fixed in myfaces 1.2.1.
              so I downloaded myfaces 1.2.1 snapshot and replaced myfaces 1.2.0 with it,I found everything is ok.