Ciao!Sarà abbastanza chiaro che sono un 'autodidatta. Ho un problema con la mia applicazione che deve ciclare gli elementi di una form tramite l'utilizzo delle multibox. Da quanto ho capito, gli elementi selezionati vengono poggiati in un arrayList il cui nome corrisponde alla property definita nella jsp. Vi posto il codice:
ActionFormcodice:<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>HomePage</title> </head> <body> <h1>Prego selezionare un libro</h1> <html:form action="/seleziona" method="post"> <table> <tr> <td> Asimov: <html:multibox property="libro" name="multiboxForm" value="asimov"></html:multibox> </td> </tr> <tr> <td> Ritratto di Dorin Gray: <html:multibox property="libro" name="multiboxForm" value="ritratto di dorian gray"></html:multibox> </td> </tr> <tr> <td> Il maestro e Margherita: <html:multibox property="libro" name="multiboxForm" value="il maestro e margherita"></html:multibox> </td> </tr> <tr> <td> <html:submit>Invia</html:submit> </td> </tr> <tr> <td> <html:reset></html:reset> </td> </tr> </table> </html:form> </body> </html>
Actioncodice:public class multiboxForm extends ActionForm{ private ArrayList libro=new ArrayList(); public ArrayList getLibro() { return libro; } public void setLibro(ArrayList libro) { this.libro = libro; }
Struts-configcodice:public class multiboxAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest req, HttpServletResponse res)throws Exception{ multiboxForm listForm=(multiboxForm) form; ArrayList listAction=new ArrayList(); listAction=listForm.getLibro(); for(int i=0;i<listAction.size();i++){ if(listAction.get(i).equals("asimov")){ listAction.add(i, "asimov");} if(listAction.get(i).equals("ritratto di dorian gray")){ listAction.add(i, "ritratto di dorian gray");} if(listAction.get(i).equals("il maestro e margherita")){ listAction.add(i, "il maestro e margherita");} } return mapping.findForward("success"); } }
Quando la runno, mi dà l'errore:codice:<struts-config> <form-beans> <form-bean name="multiboxForm" type="org.multibox.multiboxForm"> <form-property name="libro" type="java.util.ArrayList"/> </form-bean> </form-beans> <action-mappings> <action path="/seleziona" type="org.multibox.multiboxAction" name="multiboxForm" scope="request" validate="false" input="/pages/Input.jsp"> <forward name="success" path="/welcome.jsp"/> <forward name="failed" path="/noElements.jsp"/> </action> </action-mappings>
Da cosa dipende?grazie!codice:exception javax.servlet.ServletException: javax.servlet.ServletException: BeanUtils.populate org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) root cause javax.servlet.ServletException: BeanUtils.populate org.apache.struts.util.RequestUtils.populate(RequestUtils.java:475) org.apache.struts.chain.commands.servlet.PopulateActionForm.populate(PopulateActionForm.java:50) org.apache.struts.chain.commands.AbstractPopulateActionForm.execute(AbstractPopulateActionForm.java:60) org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) root cause java.lang.IllegalArgumentException: Cannot invoke org.multibox.multiboxForm.setLibro on bean class 'class org.multibox.multiboxForm' - argument type mismatch - had objects of type "java.lang.String" but expected signature "java.util.ArrayList" org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2181) org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2141) org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1948) org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2054) org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1015) org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:830) org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:433) org.apache.struts.util.RequestUtils.populate(RequestUtils.java:473) org.apache.struts.chain.commands.servlet.PopulateActionForm.populate(PopulateActionForm.java:50) org.apache.struts.chain.commands.AbstractPopulateActionForm.execute(AbstractPopulateActionForm.java:60) org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) root cause java.lang.IllegalArgumentException: argument type mismatch sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2155) org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2141) org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1948) org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2054) org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1015) org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:830) org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:433) org.apache.struts.util.RequestUtils.populate(RequestUtils.java:473) org.apache.struts.chain.commands.servlet.PopulateActionForm.populate(PopulateActionForm.java:50) org.apache.struts.chain.commands.AbstractPopulateActionForm.execute(AbstractPopulateActionForm.java:60) org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305) org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191) org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

. Ho un problema con la mia applicazione che deve ciclare gli elementi di una form tramite l'utilizzo delle multibox. Da quanto ho capito, gli elementi selezionati vengono poggiati in un arrayList il cui nome corrisponde alla property definita nella jsp. Vi posto il codice:
Rispondi quotando