Announcement Announcement Module
Collapse
No announcement yet.
Binding error message? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding error message?

    How would I show (within jsp page) the exception or message of a form post that fails to bind to a command object?

    Is there a standard request varname for the request?

    Is there a way to identify which params failed?

    Is there a way to get a general message for binding failure, say a simple binding message determined by the command object type?

    Also, why does the spring:bind tag need to throw an exception when it doesn't find the @path? That seems kind of silly, shouldn't it just passively result to an empty string or a null so we don't always have to check that it exists before rendering the tag?

    Saves lines, saves time, saves the wrist.

    Thanks
    -joe

  • #2
    Inspect command fields for binding failure

    Say that I did use the generic "command" name for the command, how would I determine which field of the command object failed?

    Code:
    			<spring&#58;hasBindErrors name="command">
    	  		<div>
    			    <spring&#58;bind path="command">
    			      <br/>errorMessage&#58; <c&#58;out value="$&#123;status.errorMessage&#125;"/>
    			      <br/>value&#58; <c&#58;out value="$&#123;status.value&#125;"/>
    			      <br/>expression&#58; <c&#58;out value="$&#123;status.expression&#125;"/>
    			    </spring&#58;bind>
        		</div>
    			</spring&#58;hasBindErrors>
    The above shows notta. It does roll into hasBindErrors, but how do you capture what the binding exception was without knowing the field before?

    Code:
    errorMessage&#58;
    value&#58;
    expression&#58;

    Comment


    • #3
      BindErrorsTag

      This tag is not included in the spring (1.1) TLD...

      Comment


      • #4
        solved...

        Ok here is what I settled with ... this seems to get most of my requirements.

        Code:
        <%@ page language="java"%>
        <%@ taglib prefix="c" uri="http&#58;//java.sun.com/jsp/jstl/core" %>
        <%@ taglib prefix="spring" uri="http&#58;//www.springframework.org/tags" %>
        <%@ page contentType="text/xml;charset=ISO-8859-1" %>
        <response>
        	<c&#58;choose>
        		<c&#58;when test="$&#123;!&#40;empty result&#41;&#125;">
        			<c&#58;out value="$&#123;result&#125;"/>
        		</c&#58;when>
        		<c&#58;when test="$&#123;!&#40;empty exception&#41;&#125;">
        			<exception id="exception">
        				<spring&#58;message code="$&#123;exception.message&#125;" var="message">
        					<c&#58;out value="$&#123;message&#125;"  default="N/A" />
        				</spring&#58;message>
        			</exception>
        		</c&#58;when>
        		<c&#58;otherwise>
        			<spring&#58;hasBindErrors name="command">
        				<exception id="bindingErrors">
        					<c&#58;forEach var="error" items="$&#123;errors.allErrors&#125;">
        						<div><c&#58;out value="$&#123;error&#125;"/></div>
        					</c&#58;forEach>
        					<c&#58;if test="$&#123;errors.globalErrorCount&#125; != 0">
        						<div><c&#58;out value="$&#123;errors.globalError&#125;"/></div>
        					</c&#58;if>
        				</exception>
        			</spring&#58;hasBindErrors>
        		</c&#58;otherwise>
        	</c&#58;choose>
        </response>

        Comment

        Working...
        X