Problem when the struts validator rejects user input

I have a JSP page that needs to have a few objects set in the request scope in order to render properly. For example my action class loads user's information from database and an object with user info is put in the request (as an attribute). The JSP then uses that object to display user info on parts of the screen.

That JSP happens to have a struts form as well. The problem is if user entered bad input, struts validator rejects the input and then tries to re-render the JSP. But this time my action class is not called before rendering the JSP. So the objects needed to render the JSP do not exist and JSP fails to display properly.

I have a JSP page that needs to have a few objects set in the request scope in order to render properly. For example my action class loads user's information from database and an object with user info is put in the request (as an attribute). The JSP then uses that object to display user info on parts of the screen.

That JSP happens to have a struts form as well. The problem is if user entered bad input, struts validator rejects the input and then tries to re-render the JSP. But this time my action class is not called before rendering the JSP. So the objects needed to render the JSP do not exist and JSP fails to display properly.

You can specify the code for getting user info from database in separate bean class( say in its constructor) and initialise all user info with diff. varaibles in Bean class. Then you can specify this Bean in your jsp page with request scope (for e.g. <jsp:useBean id="DBean" scope="request" class="???" /> ) so that whenever jsp page is displayed you will get this user info detail in Bean object and not require to get it from action class.

You can set the input attribute of your ActionMapping to be another Action, rather than a JSP. Whatever Action is called to properly render the JSP, use that as the input of the next Action so that when the validator picks up an error, it immediately re-calls the first Action to put all the necessary data in the request, and properly display the JSP with the error message.