hi pple
am a struts-beginner and i need help on passing an Arraylist frm Action to JSP.
-- users access ContactPage.jsp
-- present text boxes and a combo box with values loaded from DB
-- SetUpMessageAction is called when ContactPage.jsp is called and i load an arraylist here
-- next, i need send the arraylist to ContactPage.jsp
i cud use Session or request.setAttribute ( ) to get this done. but i am sure there is a 'struts-way' of doing this.
in the execute ( ) of SetUpMessageAction, i have:
i have a CategoryBean with int id, String description. in service.getCategories ( ), i do
repeatedly to populate the Arraylist. This is supposed to make a 'select' from the DB. For now, i populate it manually.
from Action, request is fwd-ed to ContactPage.jsp, where I need to get the 'categories' collection to populate my combo box.
this is how i try to populate the combo box:
in my struts-config.xml, this is wht i have:
the exception i get is:
what does that mean? am i not setting 'categories' explicitly in Action? what am i missing here?
thanks a ton.
-- $uDhA
am a struts-beginner and i need help on passing an Arraylist frm Action to JSP.
-- users access ContactPage.jsp
-- present text boxes and a combo box with values loaded from DB
-- SetUpMessageAction is called when ContactPage.jsp is called and i load an arraylist here
-- next, i need send the arraylist to ContactPage.jsp
i cud use Session or request.setAttribute ( ) to get this done. but i am sure there is a 'struts-way' of doing this.
in the execute ( ) of SetUpMessageAction, i have:
Code:
MessageService service = new MessageService ( ) ;
DynaActionForm messageForm = ( DynaActionForm ) form ;
Collection categories = service.getCategories ( ) ;
request.setAttribute ( mapping.getAttribute ( ), messageForm ) ;
return ( mapping.findForward ( "continue" ) ) ;
i have a CategoryBean with int id, String description. in service.getCategories ( ), i do
Code:
list.add ( new CategoryBean ( 1, "Accounting" ) ) ;
from Action, request is fwd-ed to ContactPage.jsp, where I need to get the 'categories' collection to populate my combo box.
this is how i try to populate the combo box:
Code:
<html:select name="messageForm" property="category_id"> <html ptions collection="categories" property="id" labelProperty="description"/></html:select>
in my struts-config.xml, this is wht i have:
Code:
<form-beans>
<form-bean name="messageForm"
dynamic="true"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="name" type="java.lang.String"/>
<form-property name="email" type="java.lang.String"/>
<form-property name="category_id" type="java.lang.String"/>
<form-property name="message" type="java.lang.String"/>
</form-bean>
</form-beans>
the exception i get is:
Code:
exception javax.servlet.ServletException: Cannot find bean under name categories org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:673) org.apache.jsp.ContactForm_jsp._jspService(ContactForm_jsp.java:227) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248) javax.servlet.http.HttpServlet.service(HttpServlet.java:856)root cause javax.servlet.jsp.JspException: Cannot find bean under name categories org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:407) org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:232) org.apache.jsp.ContactForm_jsp._jspx_meth_html_options_0(ContactForm_jsp.java:460) org.apache.jsp.ContactForm_jsp._jspx_meth_html_select_0(ContactForm_jsp.java:433) org.apache.jsp.ContactForm_jsp._jspx_meth_html_form_0(ContactForm_jsp.java:358) org.apache.jsp.ContactForm_jsp._jspService(ContactForm_jsp.java:217) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248) javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
what does that mean? am i not setting 'categories' explicitly in Action? what am i missing here?
thanks a ton.
-- $uDhA