This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Cannot find bean in any scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Cannot find bean in any scope" Watch "Cannot find bean in any scope" New topic
Author

Cannot find bean in any scope

Kalith Aazad
Greenhorn

Joined: Jun 27, 2010
Posts: 24
I have been trying to debug this application for 2 days now..
I am unable to understand what is wrong wth the code..
Please someone help me out...

I keep on getting this message as the Error 500 and I dont understand what it means while


this is the web.xml file--


Now the welcome.jsp is shown as this file --


The struts-config.xml has the action-mapping. Please consider the action-mapping for the enterDetails since the previous action mapping works fine.
The form-bean UserDetailsForm is also included later in this section


The code for the form-bean is as follows-


The countryData is another set of class which is as follows-


The action-class is as shown--






Kalith Aazad
Greenhorn

Joined: Jun 27, 2010
Posts: 24
What I fail to understand here is that what should the optionsCollection property have?
the name?
the property that points to the list?
the name that points to the CountryData ??
I am really confused when it comes to this..
Please help me out..Thanks..
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you accessing welcome.jsp directly (younare using it as a welcome file) or through the action?
Kalith Aazad
Greenhorn

Joined: Jun 27, 2010
Posts: 24
Dear David,
I am calling the welcome.jsp file using the welcome-file-list..I am not directly calling it. When I run the application , it directs the control to welcome.jsp.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Okay. So, the action isn't being run, right?
Kalith Aazad
Greenhorn

Joined: Jun 27, 2010
Posts: 24
I guess the formbean is not being populated.
What i see is..
first on loading web.xml -> struts-config.xml -> welcome.jsp -> It is stuck..
If that is resolved, then the action will be loaded right and the bean be populated right???
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're calling the JSP directly--Struts isn't involved at all.
Kalith Aazad
Greenhorn

Joined: Jun 27, 2010
Posts: 24
So how do I go about calling the action?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You either configure the container to allow the use of an action as a welcome file (I don't remember how), or meta refresh to the action from a welcome page.
Kalith Aazad
Greenhorn

Joined: Jun 27, 2010
Posts: 24
Dear David,
Thank you . Will let you know if it worked .
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No problem!
Kalith Aazad
Greenhorn

Joined: Jun 27, 2010
Posts: 24
so the course of action would be to call a test.jsp page from welcome-file list which redirects to the Action mapping.
The action class then calls the populate method and populates the formbean
which then after wards delegates the control to the welcome.jsp which displays the select options tag?
would that work?
Kalith Aazad
Greenhorn

Joined: Jun 27, 2010
Posts: 24
I finally resolved it--

Here is the solution--
The struts-config.xml file--


The Action-form was created using SelectedItem as one more property for using it in the jsp file.
The Collections element was induced in the request object as CountryList.

The Action-Form



The Action - Class



The show-Details.jsp file--


What I observed was this--
For this to work in the form-bean if you have a country-list
countryList.add(new CountryData("1", "USA"));
countryList.add(new CountryData("2", "Canada"));
countryList.add(new CountryData("3", "Mexico"));
request.setAttribute("countryListAttribute",countryList);
Now, since the attribute in the request is set to countryListAttribute,
At the JSP side, for the html:select code,
<html:form action="/login">
<html:select name="UserDetailsForm" property="selectedItem">
<!-- property refers to the name of the request parameter in the form -->
<htmlptionsCollection name="countryListAttribute" />
<!-- label="countryName" value="countryId" -->
</html:select>
<html:submit/>
</html:form>
Here , the action pertains to any action that will get executed once the submit is clicked.
The property=”selectedItem refers to a string property in the form “UserDetailsForm ” which has been mapped in the struts-config.xml as a form-bean mapping.The name of the form-bean is “UserDetailsForm”. Now, with the name=”countryListAttribute” , it is taken from the request scope. The request scope is present in the action mapping as described as under.
Thus an important part to be noted is that in html:select , the property=”selectedItem” should be a string in the form-bean.
If you do not have getlabel() and getValue() to the associated form-bean then, by default, if you do not put label=”countryName” and value=”countryID” , it searches for the implementation of the getLabel() and getValue() inside the form-bean.




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot find bean in any scope
 
Similar Threads
Struts 2 checkboxlist error - list key could not be resolved
JspException: Failed to obtain specified collection for Struts:optionscollection
Dependent drop down boxes with javascript?
Displaying Database values on jsp page in struts 1.3
Submitting hidden values on the form with onSelect option