File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes issue with scope of a form bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "issue with scope of a form bean" Watch "issue with scope of a form bean" New topic

issue with scope of a form bean

Souvvik Basu
Ranch Hand

Joined: Apr 05, 2010
Posts: 96

I am creating an online exam application, and I am stuck with a validation issue.

I have a link on a jsp page adminHomePage.jspwhich calls an action that retrieves all Tests and all Users present in the database. The form bean being used is TestsNStudentsInfoForm. On success, the list of tests and students are being displayed on a new jsp testRegistration.jsp in drop-down fields. On this new jsp, I am using Struts validation framework to validate for empty fields. The testRegistration.jsp page uses its own form bean TestRegistrationForm to carry the workflow forward. However, the validation method is giving an error

When I convert the TestsNStudentsInfoForm bean from request to session scope, the error is rectified.

Now, my question is, why does the framework look at the bean whose use is already over, and which is not being used at all for the current workflow? Also, as long as the fields are not empty, and the code to add an ActionMessage to the ActionError object is not being executed, it is working fine. Looks like the framework is searching for the old bean before adding an action error, but not otherwise.

Here are my codes


On clicking the link Allow a Student for a Test the /retrieveTestsNStudents path is followed. the struts-config.jsp for this mapping is

The data is being pulled correctly and displayed correctly on testRegistration.jsp.

On clicking the submit button, the following mapping is invoked

The TestRegistrationForm bean is this

My apologies for the long post, but the issue seems to be tied to 2 actions, so I gave both the flows.

OCJP 6.0
I agree. Here's the link:
subject: issue with scope of a form bean
It's not a secret anymore!