Cannot find bean Customers in any scope
Tengo un optionsCollection en un formulario que me está dando el error mencionado (no encuentra el bean Customers). Soy nuevo en Struts y quisiera entender porque del error.
Ya probé configurando redirect="false" y "true" en struts-config.xml
El código que estoy trabajando es un ejemplo que saqué de la web:
=== JSP ===
<body>
<html:form action="/example">
<h4>Simple use of <html:optionsCollection> Tag</h4>
<html:select property="selectedItem">
<html:optionsCollection name="Customers" value="id" label="name"/>
</html:select>
<html:submit/>
</html:form>
=== ActionForm ===
package pruebas;
import org.apache.struts.action.*;
public class ExampleForm extends ActionForm {
private String selectedItem;
public String getSelectedItem() {
return selectedItem;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
}
}
=== Action ===
package pruebas;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.*;
public class ExampleAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form;
HttpServletRequest request,
HttpServletResponse response) {
Collection customers = new ArrayList();
cust.add(new Customers(1, "Marie"));
cust.add(new Customers(2, "Klaus"));
cust.add(new Customers(3, "Peter"));
request.setAttribute("customers", cust);
return mapping.findForward("success");
}
}
=== Customers ===
package pruebas;
public class Customers {
public class Customers() {}
public class Customers(int id, String name) {
this.id = id;
this.name = name;
}
... Sets y gets respectivos para id y name
}
Ya probé configurando redirect="false" y "true" en struts-config.xml
El código que estoy trabajando es un ejemplo que saqué de la web:
=== JSP ===
<body>
<html:form action="/example">
<h4>Simple use of <html:optionsCollection> Tag</h4>
<html:select property="selectedItem">
<html:optionsCollection name="Customers" value="id" label="name"/>
</html:select>
<html:submit/>
</html:form>
=== ActionForm ===
package pruebas;
import org.apache.struts.action.*;
public class ExampleForm extends ActionForm {
private String selectedItem;
public String getSelectedItem() {
return selectedItem;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
}
}
=== Action ===
package pruebas;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.*;
public class ExampleAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form;
HttpServletRequest request,
HttpServletResponse response) {
Collection customers = new ArrayList();
cust.add(new Customers(1, "Marie"));
cust.add(new Customers(2, "Klaus"));
cust.add(new Customers(3, "Peter"));
request.setAttribute("customers", cust);
return mapping.findForward("success");
}
}
=== Customers ===
package pruebas;
public class Customers {
public class Customers() {}
public class Customers(int id, String name) {
this.id = id;
this.name = name;
}
... Sets y gets respectivos para id y name
}
1 Respuesta
Respuesta de alejosoft
1