Announcement Announcement Module
Collapse
No announcement yet.
${status.errorMessage} not displayed Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ${status.errorMessage} not displayed

    Hello,

    I am using the Spring Validator, but I have a hard time showing the ${status.errorMessage}, which remains empty for "stServerVo.address" although
    spring:hasBindErrors for "stServerVo" is true. Am I missing something?
    Thanks in advance for your help.


    ------------------- JSP
    <spring:bind path="stServerVo.address">
    <td>address:</td>
    <td>
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
    </td>
    <td>

    <!-- NOT DISPLAYED -->
    <font color="red"><c:out value="${status.errorMessage}"/></font>

    <!-- DISPLAYED -->
    <spring:hasBindErrors name="stServerVo">
    <div class="error">Please provide valid search criteria!</div>
    </spring:hasBindErrors>
    </td>

    ------------------- VALIDATOR
    public class LoginValidator implements Validator {

    public boolean supports(Class clazz) {
    return StServerVo.class.equals(clazz);
    }

    public void validate(Object obj, Errors errors) {
    StServerVo stServerVo = (StServerVo)obj;
    if (stServerVo.getAddress() == null || stServerVo.getAddress().length() == 0){
    errors.reject("address", null,"Please provide an address.");
    }
    if (stServerVo.getUserName() == null || stServerVo.getUserName().length() == 0){
    errors.reject("userName", null,"Please provide a user name.");
    }

    }
    }

    ------------------- FLOW

    <view-state id="displayLogin" view="loginView">
    <transition on="login" to="bindAndValidateLogin">
    </transition>
    </view-state>

    <action-state id="bindAndValidateLogin">
    <action bean="formAction" method="bindAndValidate"/>
    <transition on="success" to="loginAction"/>
    <transition on="error" to="displayLogin"/>
    </action-state>

    ------------------- BEANS
    <bean name="formAction" class="org.springframework.webflow.action.FormActi on">
    <property name="formObjectName"><value>stServerVo</value></property>
    <property name="formObjectClass"><value>web.StServerVo</value></property>
    <property name="validator">
    <bean class="web.flow.LoginValidator"/>
    </property>
    </bean>
    Last edited by jcantonio; Jan 31st, 2006, 05:26 AM. Reason: erratum

  • #2
    This works

    This snipped usually works for me!
    Code:
    <c:if test="${status.error}">
    		<tr><td></td><td><div class="error"><c:out value="${status.errorMessage}" /></div></td></tr>
    	</c:if>
    Hope it helps

    Comment


    • #3
      Thanks for your reply.
      I actually tried this before without success.
      Cheers

      Comment


      • #4
        Greetings!

        try the following:

        Code:
        <spring:bind path="stServerVo.*">
        <c:forEach var="error" items="${status.errorMessages}">
        <font color=red><c:out value="${error}"/></font>
        </c:forEach>
        </spring:bind>
        See the difference? 'status.errorMessages' has to be contained within the <spring:bind></spring:bind> tags.

        Hope this helps,

        Curtney

        Comment


        • #5
          Thanks for your help Curtney.

          With this I get all messages.
          Is there a way to only get validation messages related to "stServerVo.address"?
          Cheers,

          Comment


          • #6
            try the following code:

            Code:
            <spring:bind path="stServerVo.address">
            
            <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>" />
            <c:if test="${status.error}">
            <div style="color: red">
            <c:out value="${status.errorMessage}"/>
            </div>
            </c:if>
            </spring:bind>
            In your previous post, you did not have the ending '</spring:bind>', I don't know if you forgot to copy it into your post or did not have it to begin with.
            Anyway, the above should do the trick.

            Hope this helps,

            Curtney

            Comment


            • #7
              Yes I did forget to paste the end tag in my post.
              And when I use that code (or the one you just posted) I do not get any error message.

              Comment


              • #8
                Then it must be something else that is wrong. The code I posted previously should work.

                Is your form backing object in the proper scope (Flow, Request)? I don't see where you are specifying this in your mapping. Do you have it set in your FormAction class?

                If not, specify it like so in your mapping, assuming flow scope:

                <property name="formObjectScope" value="FLOW"/>
                Also, check your validate method.

                _Curtney

                Comment


                • #9
                  Hello

                  I tried with the flow scope without success (see below).
                  I believe the messages are in the right scope since the code you first sent returned messages. Somehow messages are shown with stServerVo.* but not with stServerVo.address.

                  Code:
                  <spring:bind path="stServerVo.*">
                      <c:forEach var="error" items="${status.errorMessages}">
                          <font color=red><c:out value="${error}"/></font>
                      </c:forEach>
                  </spring:bind>



                  Code:
                  	<bean name="formAction" class="org.springframework.webflow.action.FormAction">
                  		<property name="formObjectScope" value="FLOW"/>
                  		<property name="formObjectName"><value>stServerVo</value></property>
                  		<property name="formObjectClass"><value>web.StServerVo</value></property>
                  		<property name="validator">
                  			<bean class="web.flow.LoginValidator"/>
                  		</property>
                  	</bean>

                  Comment


                  • #10
                    Hello,

                    I sould have read the JavaDoc.

                    errors.rejectValue()
                    Reject the given field of the current object, using the given error description.

                    while errors.reject()
                    Reject the current object, using the given error description.

                    So by changing to rejectValue() it works.....

                    Comment


                    • #11
                      Your welcome

                      _Curtney

                      Comment


                      • #12
                        Thanks Curtney!

                        Comment

                        Working...
                        X