开发者

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 u开发者_如何转开发se of populateFormAction in between Action handler and form.jsp.


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


you can use "MessageStoreInterceptor“ to preserve the messages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜