aspose file tools*
The moose likes Struts and the fly likes Cannot find bean: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Cannot find bean: "EMPLOYEELIST" in any scope" Watch "Cannot find bean: "EMPLOYEELIST" in any scope" New topic
Author

Cannot find bean: "EMPLOYEELIST" in any scope

Steve Huang
Greenhorn

Joined: Aug 02, 2006
Posts: 2
Hi everyone,

This is my first post. Any help on this is much appreciated. I've been reading in Struts Forum about the proper usage of <html:select>, <html ptions>, <html ptionsCollection>, etc, honestly I am still confused. I am getting "cannot find bean: EMPLOYEELIST in any scope" error message. Can any of your struts experts tell me what I am doing wrong? Here is my code:


JSP:
<html:form action="/search">
<table>
<tr>
<td align="right"><bean:message key="label.search.name"/>:</td>
<td>
<html:select property="employee">
<html ptionsCollection name="EMPLOYEELIST" value="ssNum" label="name"/>
</html:select>

</td>


Struts-config.xml
<form-beans>
<form-bean name="searchForm"
type="com.jamesholmes.minihr.SearchForm">
</form-bean>
</form-beans>

<!-- Global Forwards Configuration -->
<global-forwards>
<forward name="search" path="/search.jsp"/>
</global-forwards>

<!-- Action Mappings Configuration -->
<action-mappings>
<action path="/search"
type="com.jamesholmes.minihr.SearchAction"
name="searchForm"
scope="request"
validate="true"
input="/search.jsp">
</action>
</action-mappings>


Action:
public final class SearchAction extends Action
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
EmployeeSearchService service = new EmployeeSearchService();
ArrayList results;
ArrayList empList;

SearchForm searchForm = (SearchForm) form;
empList = service.getEmployeeList();

searchForm.setEmployees(empList);

request.getSession().setAttribute("EMPLOYEELIST",searchForm);

// Forward control to this Action's input page.
return mapping.getInputForward();
}
}

Form:
public class SearchForm extends ActionForm
{
private ArrayList employees = new ArrayList();
private String employee;

public String getEmployee() {
return employee;
}

public void setEmployee(String employee) {
this.employee = employee;
}

public ArrayList getEmployees() {
return employees;
}

public void setEmployees(ArrayList employees) {
this.employees = employees;
}


Bean:
public class Employee
{
private String name;
private String ssNum;

public Employee(String name, String ssNum) {
this.name = name;
this.ssNum = ssNum;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setSsNum(String ssNum) {
this.ssNum = ssNum;
}

public String getSsNum() {
return ssNum;
}
}


Please help, thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Let's look more closely at this:

In the <htmlptionsCollection> tag, the name and (optionally) property attribute should refer to a collection of beans you want to iterate over to create the list of options.

You've provided name="EMPLOYEELIST", but the object in the session under the name "EMPLOYEELIST is an object of type SearchForm, not a collection, so that isn't going to work. What you're after is the employees property of SearchForm because that contains the actual list of employees you want to iterate over.

Stop reading and try fixing it yourself first. Then scroll down if you need to see the answer.










Answer:
<htmlptionsCollection name="EMPLOYEELIST" property="employees" value="ssNum" label="name"/>

Just so you know: Struts has already put your SearchForm in the session for you. You could therefore eliminate the line:

request.getSession().setAttribute("EMPLOYEELIST",searchForm);

and then change the name attribute of your <htmlptionsCollection> tag to "searchForm".

P.S. to get rid of those annoying smiley-faces, click the "Disable smilies in this post" box at the bottom of the Post A Reply page.


Merrill
Consultant, Sima Solutions
Steve Huang
Greenhorn

Joined: Aug 02, 2006
Posts: 2
Merrill, you're right! It was the problem setting incorrect object into the actionForm. I also deleted the line setting a collection object to the current session; that worked too. Anyway, your PROMPT response is much much appreciated.

By the way, I couldn't resist to scroll down and see your answers before trying it out myself. I was, say the least, a bit frustrated from trying for a long time before posting for help. Anyway, thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot find bean: "EMPLOYEELIST" in any scope