shin
shin

Reputation: 1681

Display validation messages in struts 2

I have a form in my application in which I want to validate the user inputs. It has a combo box which is populated from db table. So I have to go to the action class first to populate it(for eg: populateFormAction). Then it will go to form.jsp page.

But the problem is at the time of validation. I have set populateFormAction as input result as follows

<result name="input" type="redirect">/populateFormAction</result>

But when it returned to form.jsp, it doesn't show the validation errors. I think it is because of the use of populateFormAction in between Action handler and form.jsp.

Upvotes: 0

Views: 803

Answers (2)

pramod
pramod

Reputation: 11

you can use "MessageStoreInterceptor“ to preserve the messages.

Upvotes: 1

Anupam
Anupam

Reputation: 8016

There are two solutions to your problem

  1. Call the method which is populating the combo, efore returning INPUT (if there is any validation error). And then dont use type redirect, instead directly move to your form.jsp. Of course, this would be possible if you have the populate combo and validate methods in the same action class.

  2. Pass your action errors as parameters to the populateFormAction as follows.Take a look here

I m not sure whether there will be 's' after actionError or not, so try both

Upvotes: 2

Related Questions