• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Cannot find bean: "EMPLOYEELIST" in any scope

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's look more closely at this:

In the <html:optionsCollection> 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:
<html:optionsCollection 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 <html:optionsCollection> 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.
 
Steve Huang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 once met a man from Nantucket. He had a tiny ad
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic