Re: DynaForm Beans and Indexed Text fields.
Mark, Thank you very much for the hints. Everything works now. I appreciate your time very much. Joel. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaForm Beans and Indexed Text fields.
it should work with just.. theForm.set("pmiRanges", (ArrayList) currentRates.getPmiRanges()); You dont need session.setAttribute.. and this can lead to you thinking that's life's great when its not.. and then ... ArrayList rateList = (ArrayList) theForm.get("pmiRanges"); rates.setPmiRanges((List) rateList); I've been doing this okay using ArrayList so you could try that.I guess the class cast exception make have been thrown when you tried seting pmiRanges with an Object rather than list its stored as an object like with so many things in java. Cheers Mark On Monday, August 25, 2003, at 03:26 PM, Joel Wickard wrote: Mark Lowe wrote: That's more like it. Are all you fields of type string? Can I see the before and after actions? You sure can. The fields inside the PMIRateDTO ( the object that makes up each element of the List ) are all of type String. Here is the before action: /* * PreloadRateEditor.java */ package com.dbo.struts.actions; import java.text.NumberFormat; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.dbo.bd.RateStoreBD; import com.dbo.dto.RateDTO; import com.dbo.struts.forms.RateEditorForm; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; /** * Struts Action to Load current rates from xml, then preload a Struts Form Bean before sending request * to RateEditor.jsp to be displayed. * * === XDoclet Configuration Tags === * * @struts.action * name="persistRateInfo" * path="/preloadRateEditor" * scope="session" * input="RateEditor.jsp" * validate="false" * parameter="" * * @struts.action-forward * name="failure" * path="/main.jsp" * * @struts.action-forward * name="success" * path="/RateEditor.jsp" * * */ public class PreloadRateEditorAction extends Action { // Obtain log instance for logging. private Log log = LogFactory.getLog( this.getClass( ) ); /* Our implementation of Action.execute(); */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug( "PreloadRateEditorAction.execute() called." ); /* Grab an instance of RateStoreBD() to retrieve the current rates */ RateStoreBD store = new RateStoreBD(); /* Load the rates from storage */ RateDTO currentRates = store.loadRates(); // debug info log.debug( "RateDTO retrieved from storage: " + currentRates ); /* Here we cast the form we were passed into an instance of DynaActionForm, for easier * manipulation. */ DynaActionForm loadForm = (DynaActionForm) form; /* Obtain instance of Locale for use in NumberFormat. Used to format our doubles to strings */ Locale loc = Locale.US; NumberFormat fmt = NumberFormat.getInstance(loc); //get information from rates DTO and populate the form bean with them. loadForm.set( "hazardInsRate", fmt.format( currentRates.getHazardInsRate() ) ); loadForm.set( "dealOneIR", fmt.format( currentRates.getDealOneIR( ) ) ); loadForm.set( "dealOneTerm", Integer.toString( currentRates.getDealOneTerm( ) ) ); loadForm.set( "dealOnePercentageDown", fmt.format( currentRates.getDealOnePercentageDown() ) ); loadForm.set( "dealTwoIR", fmt.format( currentRates.getDealTwoIR( ) ) ); loadForm.set( "dealTwoTerm", Integer.toString(currentRates.getDealTwoTerm( ) ) ); loadForm.set( "dealTwoPercentageDown", fmt.format( currentRates.getDealTwoPercentageDown() ) ); loadForm.set( "dealThreeIR", fmt.format( currentRates.getDealThreeIR( ) ) ); loadForm.set("dealThreeTerm", Integer.toString(currentRates.getDealThreeTerm( ) ) ); loadForm.set( "dealThreePercentageDown", fmt.format( currentRates.getDealThreePercentageDown() ) ); loadForm.set( "pmiRanges", currentRates.getPmiRanges() ); /* Store the form bean in request scope so that the custom taglib can access it */ //request.setAttribute( "persistRateInfo", currentRates ); request.getSession().setAttribute( "persistRateInfo", currentRates ); /* set the forward to be successful */ String myForward = "success"; /* return forward */ return mapping.findForward( myForward ); } } Here is the action that the form is posted to: /* * PersistRateInfo.java */ package com.dbo.struts.actions; import javax.servlet.http.HttpServletRequest; im
Re: DynaForm Beans and Indexed Text fields.
Mark Lowe wrote: That's more like it. Are all you fields of type string? Can I see the before and after actions? You sure can. The fields inside the PMIRateDTO ( the object that makes up each element of the List ) are all of type String. Here is the before action: /* * PreloadRateEditor.java */ package com.dbo.struts.actions; import java.text.NumberFormat; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.dbo.bd.RateStoreBD; import com.dbo.dto.RateDTO; import com.dbo.struts.forms.RateEditorForm; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; /** * Struts Action to Load current rates from xml, then preload a Struts Form Bean before sending request * to RateEditor.jsp to be displayed. * * === XDoclet Configuration Tags === * * @struts.action * name="persistRateInfo" * path="/preloadRateEditor" * scope="session" * input="RateEditor.jsp" * validate="false" * parameter="" * * @struts.action-forward * name="failure" * path="/main.jsp" * * @struts.action-forward * name="success" * path="/RateEditor.jsp" * * */ public class PreloadRateEditorAction extends Action { // Obtain log instance for logging. private Log log = LogFactory.getLog( this.getClass( ) ); /* Our implementation of Action.execute(); */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug( "PreloadRateEditorAction.execute() called." ); /* Grab an instance of RateStoreBD() to retrieve the current rates */ RateStoreBD store = new RateStoreBD(); /* Load the rates from storage */ RateDTO currentRates = store.loadRates(); // debug info log.debug( "RateDTO retrieved from storage: " + currentRates ); /* Here we cast the form we were passed into an instance of DynaActionForm, for easier * manipulation. */ DynaActionForm loadForm = (DynaActionForm) form; /* Obtain instance of Locale for use in NumberFormat. Used to format our doubles to strings */ Locale loc = Locale.US; NumberFormat fmt = NumberFormat.getInstance(loc); //get information from rates DTO and populate the form bean with them. loadForm.set( "hazardInsRate", fmt.format( currentRates.getHazardInsRate() ) ); loadForm.set( "dealOneIR", fmt.format( currentRates.getDealOneIR( ) ) ); loadForm.set( "dealOneTerm", Integer.toString( currentRates.getDealOneTerm( ) ) ); loadForm.set( "dealOnePercentageDown", fmt.format( currentRates.getDealOnePercentageDown() ) ); loadForm.set( "dealTwoIR", fmt.format( currentRates.getDealTwoIR( ) ) ); loadForm.set( "dealTwoTerm", Integer.toString(currentRates.getDealTwoTerm( ) ) ); loadForm.set( "dealTwoPercentageDown", fmt.format( currentRates.getDealTwoPercentageDown() ) ); loadForm.set( "dealThreeIR", fmt.format( currentRates.getDealThreeIR( ) ) ); loadForm.set("dealThreeTerm", Integer.toString(currentRates.getDealThreeTerm( ) ) ); loadForm.set( "dealThreePercentageDown", fmt.format( currentRates.getDealThreePercentageDown() ) ); loadForm.set( "pmiRanges", currentRates.getPmiRanges() ); /* Store the form bean in request scope so that the custom taglib can access it */ //request.setAttribute( "persistRateInfo", currentRates ); request.getSession().setAttribute( "persistRateInfo", currentRates ); /* set the forward to be successful */ String myForward = "success"; /* return forward */ return mapping.findForward( myForward ); } } Here is the action that the form is posted to: /* * PersistRateInfo.java */ package com.dbo.struts.actions; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.dbo.bd.RateStoreBD; import com.dbo.dto.RateDTO; import com.dbo.struts.forms.RateEditorForm; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; /** * Action which obtains an instance of RateStoreBD() and saves an instance of the current mortgage rates * for use in the application. * * === XDoclet Struts Action Co
Re: DynaForm Beans and Indexed Text fields.
That's more like it. Are all you fields of type string? Can I see the before and after actions? Cheers MArk On Monday, August 25, 2003, at 02:04 AM, Joel wrote: Okay, so I set the scope of both the preload action, and the action servlet that my form is bieng posted to, to "session". I also put the bean in session scope instead of request scope when I preload the DynaForm with values before passing it to the jsp. So The jsp still loads and reders the indexed text fields just fine.. but now I get this exception when I submit the form: java.lang.ClassCastException at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java: 688) at org.apache.struts.action.RequestProcessor.processActionForm(RequestProc essor.java:359) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java :253) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1420) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:520) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknow n Source) at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source) at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContext.invoke(Unknown Source) at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invokeNext(Unknown Source) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invokeNext(Unknown Source) at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext. invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:5 94) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process Connection(Http11Protocol.java:392) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:5 65) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPoo l.java:619) at java.lang.Thread.run(Thread.java:534) --- - Apache Tomcat/4.1 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaForm Beans and Indexed Text fields.
Okay, so I set the scope of both the preload action, and the action servlet that my form is bieng posted to, to "session". I also put the bean in session scope instead of request scope when I preload the DynaForm with values before passing it to the jsp. So The jsp still loads and reders the indexed text fields just fine.. but now I get this exception when I submit the form: java.lang.ClassCastException at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:688) at org.apache.struts.action.RequestProcessor.processActionForm(RequestProcessor.java:359) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:253) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1420) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:520) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at javax.servlet.http.HttpServlet.service(HttpServlet.java) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source) at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContext.invoke(Unknown Source) at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619) at java.lang.Thread.run(Thread.java:534) Apache Tomcat/4.1 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaForm Beans and Indexed Text fields.
In the action tag is the form scoped to session? Cheers Mark On Sunday, August 24, 2003, at 04:59 PM, Joel wrote: I'm having a problem using Indexed text fields with DynaActionForms. I can make a jsp display my indexed text fields just fine using the and custom tags. The problem is when I submit the form, there is a problem populating the DynaActionForm with my indexed text values. I'm wondering if the problem is the fact that the collection used is a java.util.List populated with by own custom beans, each bean containing three String fields with their own getters/setters. I'm wondering if I can use DynaActionForms in this instance. Below is a copy of my DynaActionForms Config, the jsp code that utilizes the form and the error message I get when the form is submitted. Any input would be of great help. Thanks, Joel. Here's my DynaActionForm Bean declaration in struts-config.xml: Here's the loop I use in the jsp that needs to display the values of pmiRanges. of the form bean: Low: High: Rate: Now I use a Struts Action to preload this form bean with values from a database. It does this fine. When the jsp is called for the first time, it utilizes the form bean, and the List perfectly and displays the indexed text fields just like I want it to. here is an example row of rendered text fields: Low: High: Rate: The problem comes in when I try to submit the form to save the form values. It doesn't seem that the form bean can be populated with the indexed values. I get the follwoing Exception: ? java.lang.NullPointerException: No indexed value for 'pmiRanges[0]' at org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:293) at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyU tils.java:474) at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyU tils.java:428) at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUt ils.java:770) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.ja va:801) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: DynaForm Beans and Indexed Text fields.
> In the StrutsAction I use to preload the form? yep If you specify name attribute for your action mapping struts will create form bean upon request to your action. So whatever action causes your bean to be instantiated would need scope attribute to be set to session. Alex. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaForm Beans and Indexed Text fields.
Alex Shneyderman wrote: You should set scope of the bean as session. When, in the jsp page? In the StrutsAction I use to preload the form? An example would be great - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: DynaForm Beans and Indexed Text fields.
You should set scope of the bean as session. > -Original Message- > From: Joel [mailto:[EMAIL PROTECTED] > Sent: Sunday, August 24, 2003 11:59 AM > To: [EMAIL PROTECTED] > Subject: DynaForm Beans and Indexed Text fields. > > > I'm having a problem using Indexed text fields with DynaActionForms. I > can make a jsp display my indexed text fields just fine using the > and custom tags. The problem is when I > submit the form, there is a problem populating the DynaActionForm with > my indexed text values. I'm wondering if the problem is the fact that > the collection used is a java.util.List populated with by own custom > beans, each bean containing three String fields with their own > getters/setters. I'm wondering if I can use DynaActionForms in this > instance. Below is a copy of my DynaActionForms Config, the jsp code > that utilizes the form and the error message I get when the form is > submitted. Any input would be of great help. > > Thanks, > > Joel. > > > Here's my DynaActionForm Bean declaration in struts-config.xml: > > name="persistRateInfo" > type="org.apache.struts.action.DynaActionForm"> > > > > > > > > > > > > > > > > Here's the loop I use in the jsp that needs to display the values of > pmiRanges. of the form bean: > > > > Low: > > > > > High: > > > > > Rate: > > > > > > > Now I use a Struts Action to preload this form bean with values from a > database. It does this fine. When the jsp is called for the first time, > it utilizes the form bean, and the List perfectly and displays the > indexed text fields just like I want it to. here is an example row of > rendered text fields: > > > Low: > > > > > > High: > > > > > Rate: > > > > > > > The problem comes in when I try to submit the form to save the form > values. It doesn't seem that the form bean can be populated with > the indexed values. I get the follwoing Exception: > > ? > > java.lang.NullPointerException: No indexed value for 'pmiRanges[0]' > at > org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:293) > at > org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt il > s.java:474) > at > org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt il > s.java:428) > at > org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUti ls > .java:770) > at > org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.jav a: > 801) > at > org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881) > at > org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808) > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
DynaForm Beans and Indexed Text fields.
I'm having a problem using Indexed text fields with DynaActionForms. I can make a jsp display my indexed text fields just fine using the and custom tags. The problem is when I submit the form, there is a problem populating the DynaActionForm with my indexed text values. I'm wondering if the problem is the fact that the collection used is a java.util.List populated with by own custom beans, each bean containing three String fields with their own getters/setters. I'm wondering if I can use DynaActionForms in this instance. Below is a copy of my DynaActionForms Config, the jsp code that utilizes the form and the error message I get when the form is submitted. Any input would be of great help. Thanks, Joel. Here's my DynaActionForm Bean declaration in struts-config.xml: Here's the loop I use in the jsp that needs to display the values of pmiRanges. of the form bean: Low: High: Rate: Now I use a Struts Action to preload this form bean with values from a database. It does this fine. When the jsp is called for the first time, it utilizes the form bean, and the List perfectly and displays the indexed text fields just like I want it to. here is an example row of rendered text fields: Low: High: Rate: The problem comes in when I try to submit the form to save the form values. It doesn't seem that the form bean can be populated with the indexed values. I get the follwoing Exception: ? java.lang.NullPointerException: No indexed value for 'pmiRanges[0]' at org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:293) at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:474) at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428) at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]