Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: ${status.errorMessage} not displayed

  1. #1
    Join Date
    Jan 2006
    Posts
    13

    Default ${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 at 04:26 AM. Reason: erratum

  2. #2
    Join Date
    Oct 2005
    Location
    Amsterdam
    Posts
    81

    Default 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

  3. #3
    Join Date
    Jan 2006
    Posts
    13

    Default

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

  4. #4
    Join Date
    Dec 2004
    Location
    CA
    Posts
    208

    Default

    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
    Curtney Jacobs

  5. #5
    Join Date
    Jan 2006
    Posts
    13

    Default

    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,

  6. #6
    Join Date
    Dec 2004
    Location
    CA
    Posts
    208

    Default

    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
    Curtney Jacobs

  7. #7
    Join Date
    Jan 2006
    Posts
    13

    Default

    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.

  8. #8
    Join Date
    Dec 2004
    Location
    CA
    Posts
    208

    Default

    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
    Curtney Jacobs

  9. #9
    Join Date
    Jan 2006
    Posts
    13

    Default

    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>

  10. #10
    Join Date
    Jan 2006
    Posts
    13

    Default

    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.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •