Results 1 to 6 of 6

Thread: Using Spring 2.0 form tag in a JSP 2.0 tag file

  1. #1
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

    Default Using Spring 2.0 form tag in a JSP 2.0 tag file

    Hello,

    The new Spring 2.0 MVC <form> tag has been working fine for me, but I'm having difficulty trying to get this tag to work properly within a JSP 2.0 tag file.

    Directly within a JSP page, the following code snippet works fine:

    Code:
    <tr>
        <td colspan=2 class="validationError"><form:errors path="paidDateFrom"/></td>
    </tr>
    <tr>
       <td><fmt:message key="paidDateFrom.label"/></td>
       <td><form:input path="paidDateFrom" size="10"/></td>
    </tr>
    Since this code is repeated in many input fields in many JSP files, I wanted to factor this into a JSP 2.0 tag file, similar to the process described on pages 185-190 of Seth Ladd's Expert Spring MVC Book by APress.

    Here is my JSP 2.0 tag file that replaces the above in my JSP file:
    Code:
    <tag:formField path="paidDateFrom" label="paidDateFrom.label" size="10"/>
    I know the tag file call above works because if my formField.tag tag file just outputs ${path}, ${label}, and ${size}, I get the three field values I gave above.

    But with my actual tag file code below, it is failing on the form:errors and form:input tags. Something seems wrong with the scoping, form:errors and form:input appear to no longer be able to identify the parent command bean when I place them in a tag file:

    Code:
    <%@ tag body-content="scriptless" %>
    <%@ attribute name="path" required="true" %>
    <%@ attribute name="label" required="true" %>
    <%@ attribute name="size" required="true" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    
    <tr>
        <td colspan=2 class="validationError"><form:errors path="${path}"/></td>
    </tr>
    <tr>
        <td><fmt:message key="${label}"/></td>
        <td><form:input path="${path}" size="${size}"/></td>
    </tr>
    Here's the error code I'm getting back from Tomcat 5.5 on this:

    Code:
    java.lang.IllegalStateException: Neither Errors instance nor plain target object for bean name 'null' available as request attribute
    	org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:134)
    	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:150)
    	org.springframework.web.servlet.tags.form.ErrorsTag.shouldRender(ErrorsTag.java:42)
    	org.springframework.web.servlet.tags.form.ErrorsTag.writeTagContent(ErrorsTag.java:50)
    	org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:82)
    	org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:68)
    	org.apache.jsp.tag.web.formField_tag._jspx_meth_form_errors_0(org.apache.jsp.tag.web.formField_tag:141)
    	org.apache.jsp.tag.web.formField_tag.doTag(org.apache.jsp.tag.web.formField_tag:101)
    ...
    Can anyone see what I'm doing wrong here?

    Thanks,
    Glen

  2. #2
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

    Default

    OK, I think I see the problem: JSP 2.0 Tag files are compiled independently of the parent JSP page, and have no knowledge of the parent. So within the tag file, form:input and form:errors, for example, will still need to be encased by a form:form object (even though one already exists in the calling JSP page) whose "commandName" property identifies the name of the command bean. This is why I'm currently getting the "null" comman bean error message.

    However, encasing my tag file code above with a parent form:form tag, while fixing this problem, introduces another: form:form automatically generates a html form element in the output, so if I call my tag file for three data elements I end up getting an additional three HTML forms in the output--which ends up messing up both the validation and request parameter collection, etc. The code ceases to function properly.

    (Another minor issue is that I will need to create another parameter in my Tag file, to store the name of the commandBean that the form:form uses. No big deal, just stating as an FYI.)

    I'll enter this as a JIRA enhancement request--to update the Spring 2.0 docs[1] to give a simple example of how one can place Spring 2.0 form tag elements like form:input into JSP 2.0 tag files. And, also, of course, if such functionality is not already present to begin with, to add that capability to the form tags.

    Glen

    [1] http://static.springframework.org/sp...mvc-formtaglib

  3. #3
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

    Default

    I added this issue to an already existing JIRA report:
    http://opensource.atlassian.com/proj...rowse/SPR-2235

    Glen

  4. #4
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

  5. #5

    Default help form:error tag

    Hi

    i got problem with form error tag

    if anyone knows given example and show me in jsp and validator class how to use the tag

    regards
    karthikeyan

  6. #6
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

Posting Permissions

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