Drop List error
The drop list is supposed to be populated by a form before the user enters the jsp page. The error is - "Failed to obtain specified collection". I think it is a servlet call or the logic of javascript and JSP whichever either process first. I'm trying to do the droplist, then I'll be doing the chain droplist by subcategories via ajax call. Any other strategies might be nice. I added the<body onload="retrieveCategories();"> to call the function in the js -
var req;
function retrieveCategories(){
var url ="/CategoriesAction/categories;"
if (window.XMLHttpRequest){
req =new XMLHttpRequest();
}
elseif (window.ActiveXObject){
req =new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("Get", url,true);
req.send();
}
struts-config.xml - the js should get this info and call CategoriesAction.
<action input="/addsheet.jsp" name="refsheetsForm" path="/categories" scope="request" type="com.refsheets.struts.CategoriesAction" validate="false"/>
This code summons the struts Action - CategoriesAction. It gets the list of categories from database and setAttribute in the form. I'm not sure if it's right -request.setAttribute(categories, list); I basically set the first parameter to the form - Collection categories, and supply the list(data) to be set in.
publicclass CategoriesActionextends Action{
/* forward name="success" path="" */
privatefinalstatic String SUCCESS ="success";
Collection list =new ArrayList();
String categories ="categories";
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception{
DAOFactory TomcatFactory =
DAOFactory.getDAOFactory(DAOFactory.TOMCAT);
ClientDAO clientdao = TomcatFactory.getClientDAO();
list = clientdao.getCategories();
request.setAttribute(categories, list);
return mapping.findForward(SUCCESS);
}
}
the form - as you can see the setCategories(Collection categories) it should be set up before the droplist requests this collection.
public Collection getCategories(){
return categories;
}
publicvoid setCategories(Collection categories){
this.categories = categories;
}
The jsp page - placed the keys to get the form data. I couldn't figure out why it is still returning an error.
<html:select property="category" value="Select Categories">
<html:optionsCollection property="categories"/>
</html:select>

