views:

346

answers:

1

i am using strut-2.1.6

I have a view page wich contains the Primary key of the currently viewed record in a hidden field. If i post this page to Save the record and any validation gets faild. i come back on the same page it keeps all other values but lose the hidden field value. Now when try to save it i get null for the primary key value in request parameters.

any help on this will highly be oblighed.

+1  A: 

Do you have both a getter and a setter for this hidden value in your action that performs the validation?

If so, you should be able to set breakpoints in there and make sure the hidden value is both getting pushed into your action, and pulled back out.

Is there any chance this id in the action is getting destroyed either in the validation method, or prepare method if you're using Preparable?

Is the action that gets called to render this page initially the same one that is used for validation?

Brian Yarger
Yes, i have setter and getter for that field in Action Class. Actually i receive the hidden field value if there is no Validation Error. Only i lost it when Validation error occurs.No, i am not using Preparable. I dont know if Prepareable will work. Because the first time i am getting the Value in hidden field is through Request Parameter. i am not sure if i will be having access to Request object in prapare().
Muhammad Shahid
Does your getter get called after validation fails? If so, is the value still correct in your field?
Brian Yarger
No setter was not called after validation fails. Anyhow i have solved the problem, Just capture the value in prepare() method. thanks Brain.now i have another question :)i have a Date field createDate in my PasswordHistory Bean, and corresponding date component on my "search.jsp" this field is optional - no validation required . if i submit the form i am get the follwoing error on consoleognl.MethodFailedException: Method "setCreatedDate" failed for object com.security.data.PasswordHistory@d5b561 [java.lang.NoSuchMethodException: setCreatedDate([Ljava.lang.String;)]
Muhammad Shahid
it looks that it is trying to convert the empty string to date, when it fails it tryies to search the corresponding String argument method and if it converts the value to date successfully it calls the corresponding Date argument method
Muhammad Shahid