Announcement Announcement Module
Collapse
No announcement yet.
<form:form> tag not generating correct "action" attribute Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <form:form> tag not generating correct "action" attribute

    I just migrated the following code to the new "form" tag library in 2.0-m5 release:

    Old way:
    Code:
    <form method="post" action="<c:url value='/base64.htm' />">
    New way:
    Code:
    <form:form commandName="base64Form">
    However when the page renders I get the following incorrect value for the "action" attribute:

    Actual:
    Code:
    <form method="POST" action="/hcbo-sso-web/WEB-INF/jsp/base64.jsp">
    Expected:
    Code:
    <form method="post" action="/hcbo-sso-web/base64.htm">
    The action is pointing directly to a JSP is obviously incorrect, so I tried specifying the action attribute as "/base64.htm". That produced the following:
    Code:
    <form method="POST" action="/base64.htm">
    Notice that the context for the web-app is missing. What is the correct way to get the context generated? I am also using Tiles. Would that make a difference?

    Shannon Kendrick

  • #2
    Originally posted by mskendrick
    I just migrated the following code to the new "form" tag library in 2.0-m5 release:

    Old way:
    Code:
    <form method="post" action="<c:url value='/base64.htm' />">
    New way:
    Code:
    <form:form commandName="base64Form">
    Shannon, if I'm reading the 2.0 documentation (14.9.2 of [1], also separately [2]) correctly, the commandName attribute is just for the name of the form backing object (defaults to "command" if not used) -- so your output results with respect to the action attribute would not be a function of what you place in for commandName.

    Have you tried reinserting the action attribute within the 2.0 form:form tag? As far as I can tell from the documentation, the form:form has not offered any changes with respect to the action attribute, so whatever you did in 1.2.x should also hold in 2.0 here.

    (Another issue is I'm not sure you even need an "action" attribute. If I recall correctly that can be specified in your spring-servlet.xml file.)

    Glen

    [1] http://static.springframework.org/sp...taglib-formtag
    [2] http://www.jroller.com/page/habuma?e...ring_form_tags

    Comment


    • #3
      Originally posted by gmazza
      Shannon, if I'm reading the 2.0 documentation (14.9.2 of [1], also separately [2]) correctly, the commandName attribute is just for the name of the form backing object (defaults to "command" if not used) -- so your output results with respect to the action attribute would not be a function of what you place in for commandName.
      I understand that the commandName is not relevant. I'm only concerned with the value that is rendered in the "action" attribute of the form tag.

      Originally posted by gmazza
      Have you tried reinserting the action attribute within the 2.0 form:form tag? As far as I can tell from the documentation, the form:form has not offered any changes with respect to the action attribute, so whatever you did in 1.2.x should also hold in 2.0 here.
      I wasn't aware that the form tag was available in the 1.2.x series. I thought that the form tag library was new to 2.0. I did try the "action" attribute, but it rendered exactly what I enter without inserting the web application context.

      Comment


      • #4
        Also experiencing

        I'm also experiencing the same thing as Shannon. I believe it's a Tiles or Sptring 2.0 RC2 thing, as the action attribute in my case refers to the root tile.
        This code bit:
        <form:form commandName="commercial" name="commercialform">

        Results in this:
        <form id="commercialform" name="commercialform" method="post" action="/i04marketing/WEB-INF/jsp/tiles/root.jsp?commercialId=1">

        Unfortunately I haven't had the chance yet to test this in earlier versions of Spring. So what I'm wondering is that is this a Spring 2.0 problem? Should it be raised as a JIRA?

        Comment


        • #5
          here's what's causing this problem..

          I'm having difficulties with this as well.

          The problem is being caused by the introduction of the resolveAction() method as can be seen here - http://springframework.cvs.sourcefor...?r1=1.8&r2=1.9
          I'm afraid I can't get more time to dig into the Spring source, much as I would like to

          I've added a comment to the jira issue whose fix introduced this bug http://opensource.atlassian.com/proj...rowse/SPR-2015

          I don't know how to get an issue re-opened though.

          In the meantime if you want to get your form working either roll back to 2.0m4 or add an action attribute that points to your mapping for the form bean. In my case this is something like action="someAction.do"

          hth

          Comment

          Working...
          X