Hi
I did not get why u need to explicitely put the FormBean in the request
scope when it will be done by struts for you .
I mean if u specify something like this in the JSP file

<html:form action="/submitAction.do">

</html:form>

The form associated with the <action path="submitAction"> will be retrieved
from the request scopr to render  ur  JSP page . This will be done for you
in the Struts-framework Why u doing this on your own ??????????/

Also the iterate tag should be indexed iterate tag  as against the normal
iterate tag as u want to update the data modified by user .
Check the Dave Hey's iterate tag in http://www.husted.com/about/struts/

Suhas





----- Original Message -----
From: Torsten Terp <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 19, 2001 10:01 AM
Subject: Re: Long Story short


> Hi,
>
> Although i have followed the example below i still have the problem with
saving
> the indexed fields. It is driving me nuts so if anybody who have it
working would
> take the time to see if they can spot the error i will be very very
greatfull.
>
> The source below is with a vector instead of an array. What happens is
that when
> the action code is executed the vector in the form is empy although the
simple String
> element is saved alright!
>
> My form looks like this:
>
> public final class ParametersForm extends ActionForm
> {
>    // --------------------------------------------------- Instance
Variables
>
> private Vector parameterList = new Vector();
> private String tester;
>
>    // -----------------------------------------------------------
Properties
>
> public String getTester() { return tester; }
>
> public void setTester(String  v) { this.tester = v; }
>
> public Vector getParameterList() { return(this.parameterList); }
>
> public void setParameterList(Vector parameterList) { this.parameterList =
parameterList; }
>
> public Parameter getParameter(int index){ return
(Parameter)parameterList.elementAt(index); }
> }
>
> The Parameter class used for each row:
>
> public class Parameter {
>
> String key;
> String desc;
> String value;
>
> public String getKey() {return key;}
> public void setKey(String  v) {this.key = v;}
>
> public String getDesc() {return desc;}
> public void setDesc(String  v) {this.desc = v;}
>
> public String getValue() {return value;}
> public void setValue(String  v) {this.value = v;}
> }
>
> The action looks like this:
>
> public final class SaveParametersAction extends Action {
>
>     // --------------------------------------------------------- Public
Methods
>
>     public ActionForward perform(ActionMapping mapping,
>    ActionForm form,
>    HttpServletRequest request,
>    HttpServletResponse response)
>            throws IOException, ServletException {
>
> ParametersForm paramForm = (ParametersForm) form;
>
> // Get the simple tester
> String test = paramForm.getTester();
> System.out.println("paramForm tester was = '"+ test + "'");
>
> // Get the parameter list
> Vector paramList = paramForm.getParameterList();
> Parameter parm1 = new Parameter();
> parm1 = (Parameter)paramList.elementAt(0);
> System.out.println("parm1.getValue():"+parm1.getValue());
>
> // Forward control to the specified success URI
> return (mapping.findForward("success"));
> }
> }
>
> My JSP looks like this:
>
>
> <%
>    file://cheating to get the objects in the request...
>
>    ParametersForm parametersForm =  new ParametersForm();
>
>    Vector parametersList = new Vector();
>
>    Parameter parameter1 = new Parameter();
>    Parameter parameter2 = new Parameter();
>
>    parameter1.setKey("key0");
>    parameter1.setDesc("desc0");
>    parameter1.setValue("value0");
>    parameter2.setKey("key1");
>    parameter2.setDesc("desc1");
>    parameter2.setValue("value1");
>
>    parametersList.addElement(parameter1);
>    parametersList.addElement(parameter2);
>
>    parametersForm.setParameterList(parametersList);
>    parametersForm.setTester("Testing non-indexed");
>
>    pageContext.setAttribute("parametersForm", parametersForm,
PageContext.REQUEST_SCOPE);
> %>
>
> <html>
> <head>
> </head>
> <body>
> <html:form action="parameters">
> <table>
> <logic:iterate id="parameter" name="parametersForm"
property="parameterList">
> <tr>
> <td width="50%">
> <bean:write name="parameter" property="key"/>
> <bean:write name="parameter" property="desc"/>
> </td>
> <td width="50%">
> <html:text name="parameter" property="value" indexed="true"
onchange="validate(this)"/>
> </td>
> </tr>
> </logic:iterate>
> <tr>
> <td width="50%">
> tester:
> </td>
> <td width="50%">
> <html:text name="parametersForm" property="tester"
onchange="validate(this)"/>
> </td>
> </tr>
> </table>
> <html:submit property="submit">submit</html:submit>
> </html:form>
> </body>
> </html>
>
>
> And finally the struts-config.xml elements related to this:
>
> <struts-config>
>
>   <form-beans>
>     <!-- index test -->
>     <form-bean name="parametersForm"
>                type="full.classname.ParametersForm"/>
>   </form-beans>
>
>   <action-mappings>
>     <!-- index test -->
>     <action    path="/parameters"
>                type="full.classname.SaveParametersAction"
>                name="parametersForm"
>                scope="request"
>                input="/parameters.jsp">
>       <forward name="error"                path="/parameters.jsp"/>
>       <forward name="success"              path="/parametersSuccess.jsp"/>
>     </action>
>   </action-mappings>
>
> </struts-config>
>
> I apologize for the long post (i dosnt quite live up to the title anymore
:-)
>
> I can see from logging that when i press submit the setTester() method is
called,
> and the getParameter(int index) but not the setValue on the parameter,
isnt' that
> was is supposed to happen, i.e., getParameter(1).setValue("someValue")?
>
> Guys, im on my knees here, can anybody spot the error? If there is some
more info
> you need, just say so!
>
> Thanks _alot_ in advance...
>
> Regards,
> Torsten
>
>
> -----Oprindelig meddelelse-----
> Fra: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sendt: 12. juli 2001 20:00
> Til: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Emne: Re: Long Story short
>
> PLEASE IGNORE LAST POST!!!
>
> Sorry, guys - please ignore my ramblings in the last post.  Was a mistake
on my
> part converting everything to arrays.
>
> My iteration DOES work with arrays, as well as collections!  As follows:
>
> public final class ParametersForm extends ActionForm
> {
>    // --------------------------------------------------- Instance
Variables
>
>    /**
>     * The parameter list
>     */
>    private Parameter[] parameterList;
>    // -----------------------------------------------------------
Properties
>
>    /**
>     * Return the list of parameters
>     */
>    public Parameter[] getParameterList()
>    {
>       return(this.parameterList);
>    }
>
>    /**
>     * Set the list of parameters
>     *
>     * @param parameterList The new list
>     */
>    public void setParameterList(Parameter[] parameterList)
>    {
>       this.parameterList = parameterList;
>    }
>
>    /**
>     * Get a particular parameter from the parameterList, based on index
>     *
>     * @param   index The index of the parameter to retrieve
>     */
>    public Parameter getParameter(int index)
>    {
>       return parameterList[index];
>    }
> }
>
> In parameters.jsp:
>
>       ....
>       <logic:iterate id="parameter" name="ParametersForm"
> property="parameterList">
>       <TR>
>          <TD WIDTH="50%">
>             bean:write name="parameter" property="key"/>
>             <bean:write name="parameter" property="desc"/>
>          </TD>
>          <TD WIDTH="50%">
>                     <html:text name="parameter" property="value"
indexed="true"
> onchange="validate(this)"/>
>          </TD>
>       </TR>
>       </logic:iterate>
>      ....
>
> In my SaveParametersAction.java I simply get the paramList from the form
and
> process them...
>
>    public ActionForward perform(ActionMapping mapping,
>                                 ActionForm form,
>                                 HttpServletRequest request,
>                                 HttpServletResponse response)
>    throws IOException, ServletException
>    {
>       ...
>       ParametersForm paramForm = (ParametersForm) form;
>
>       // Get the parameter list
>       Parameter[] paramList = paramForm.getParameterList();
>
>      ...do stuff with paramList
>    }
>
> So, Frank, not sure what you're doing differently!  Maybe you can check
the code
>  above and see if you spot anything?
>
> Cheers, and sorry for the confusion - too little sleep, I think!
>
> Dave
>
>
>

Reply via email to