htobon
htobon

Reputation: 153

Clearing parameters after validation in Struts 2

I have a

URL="deliverable.do?id=123"

After clicking the submit button, it goes to the validate() method and find some missing field.

Then, when it goes back showing the problem (which is what I expect), the new URL is being displayed without the parameters

URL="deliverable.do"

BTW, I cannot make a redirect, because if I do it, I will lose the previous information entered in the form.

<action name="deliverable" class="DeliverableAction">
  <result name="input">/WEB-INF/deliverable.ftl</result>
  <result name="success" type="redirectAction">
    <param name="actionName">deliverable</param>
    <param name="id">${deliverable.id}</param>
  </result>     
</action>

I understand that the validation() method will return INPUT result if some problem occurs, however, is there a way to keep the parameters in the URL?

Upvotes: 1

Views: 511

Answers (1)

Roman C
Roman C

Reputation: 1

My guess is that your form action attribute doesn't have parameters in the URL and the method is post. When you submitted a form you didn't specify any parameters in the URL. In most cases when you doing post request you don't want to use parameters in the URL, so you can use hidden field with the name of the parameter. After the form is submitted you can get the parameter in the same way as any other request parameters. This parameter won't be passed with the URL but in the body of the request, so request methods to retrieve parameters work, and struts can populate this parameter to the action bean if it has a public setter.

<s:form action="deliverable" method="post">
  <s:hidden name="id" value="123"/>
  ...
</s:form> 

Upvotes: 1

Related Questions