You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Susan Bradeen <Su...@softlanding.com> on 2002/08/23 22:11:14 UTC
Form bean is null
Hello,
I have been through numerous excellent examples in this mailing list,
and still just can't seem to get this right. At this point I am just
trying to
display a list of items on a jsp with checkboxes next to them. I am always
getting
"Cannot retrieve definition for form bean null". Can someone please point out
the proper way to access the form bean?
Action form:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
AddCatalogItemsForm itemForm = (AddCatalogItemsForm)form;
ProductFactory pfactory = new ProductFactory();
ProductBO[] products = pfactory.getProducts();
String[] choices = new String[products.length];
for (int i = 0; i < choices.length; i++) {
choices[i] = products[i].getDescription();
}
itemForm.setChoices(choices);
request.setAttribute("addCatalogItemsForm", itemForm);
// have also tried request.setAttribute(mapping.getAttribute(),
itemForm);
return mapping.findForward("success");
Form bean:
public class AddCatalogItemsForm extends ActionForm {
private String[] productsChosen;
private String[] choices;
public AddCatalogItemsForm() {super();}
public String[] getChoices() {return choices;}
public void setChoices(String[] choices) {this.choices = choices;}
public String[] getProductsChosen() {return productsChosen;}
public void setProductsChosen(String[] productsChosen) {
this.productsChosen = productsChosen; }
public void reset (ActionMapping mapping, HttpServletRequest request) {
productsChosen = new String [0]; }
}
Struts-Config:
<form-bean
name="addCatalogItemsForm"
type="com.softlanding.storefront.actionformbeans.AddCatalogItemsForm"/>
<!-- Product List to choose from -->
<action
path="/addcatalogitems"
type="com.softlanding.storefront.actions.AddCatalogItemsAction"
name="addCatalogItemsForm"
scope="request"
validate="false">
<forward name="success"
path="/maintain/addCatalogItems.jsp"/>
</action>
JSP file:
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html locale="true">
<head>
<title><bean:message key="chooseproducts.title" /></title>
</head>
<body>
<html:form action="/savecatalogitems.do">
<logic:iterate id="product" property="choices">
<html:multibox property="productsChosen">
<bean:write name="product"/>
</html:multibox>
</logic:iterate>
</html:form>
</body>
</html:html>
Sorry for the length of this message.
Thanks,
Susan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>