erik.c
erik.c

Reputation: 1362

Struts can't "refresh" value for a disabled field

I have a problem with Struts. The flow is like this:

Any idea how should this be solved? I'm using Struts 1.

Upvotes: 2

Views: 911

Answers (1)

Bogdan
Bogdan

Reputation: 24590

You probably have a session scoped form bean that retains the values between requests. When you submit new data, the form bean gets it's values updated from the fields inside the request (a data bind with the request parameters).

But there is a problem with disabled fields and checkboxes. Disabled fields, just like unchecked checkboxes, are not sent on the request when you submit the form. When the request arrives the field is not present in the request (because it's disabled) and Struts doesn't do a bind on it so it retains whatever value it previously had.

There are two ways to fix this:

  • use a request scoped form bean. This is not persisted between requests but is recreated fresh on each submit. Might not be possible if you have a wizard kind of flow and you do need to keep data in session in between requests.
  • use the ActionForm.reset() method to reset the value of your disabled field to null. If it's not present on the request when you submit it remains null, if it's present it's then updated when Struts does the data bind.

Upvotes: 3

Related Questions