Hi Brian,

I didn�t really get everything what u wrote. (It�s a problem of my bad
english, I guess). But I made myself some thoughts about what u worte about
"id".
And finally I got my error why I only could read from my formbean but not
submit any changes in the bean. The error was the "id" (I guess).
OK I try to explain (correct me if I�m wrong).


I have a formbean which looks like this:

public class TimeProofFormBean extends ActionForm {


    public Vector getTimeProofList() {
        return this.timeProofList;
    }

    public void setTimeProofList( Vector v ) {
        this.timeProofList = v;
    }

   <snip>

    private Vector timeProofList = new Vector();

}

******************************************************
In my set and get TimeProofList-Vector I save following bean:

public class TimeProofTableBean implements Serializable {
public TimeProofTableBean(){}

public String getFromHour(){
        return FromHour;
    }

public void setFromHour(String FromHour){
        this.FromHour = FromHour;
    }

<snip>

private String FromHour;

<snip>
}

**************************************************************************+
In my jsp I had following iterate Tag:

<logic:iterate id="element" indexId="listIdx" name="timeProofForm"
property="timeProofList">
<tr>
  <td> <bean:write name="element" property="date" /> </td>
  <td> <html:text name="element" property="fromHour" size="2" maxlength="2"
indexed="true"/></td>
 </tr>
</logic:iterate>

So, I declare an "element" which comes from my timeProofForm with the method
getTimeProofList. (This returnes a vector of TimeProofTableBeans)
So in the html:text struts goes to element.getfromHour and gets the value of
this fromHour Property in the TimeProofTableBean.

But I never could press submit to get the changes fromHour�s

Now I tried to give id the name of the get/set method of timeProofForm. And
now I could read my data back! It�s working. Here�s my change:


<logic:iterate id="timeProofList" indexId="listIdx" name="timeProofForm"
property="timeProofList">
<tr>
  <td> <bean:write name="timeProofList" property="date" /> </td>
  <td> <html:text name="timeProofList" property="fromHour" size="2"
maxlength="2" indexed="true"/> </td>
 </tr>
</logic:iterate>

Somehow I didn�t understand really why it�s not working with any name on id
(because this bean scope is only valid in the actual jsp pagem isn�t it?)

But if u take a look on the generated html input

<input type="text" name="timeProofList[0].fromHour" maxlength="2" size="2"
value="11">

It�s somehow logic, that it must work like this. Because the timeProofList
is the name of the get/set Method of the Formbean. So I want to have the
element [0] ind this returned vedtor array. And from the element 0 I want to
get/set the fromHour property.


I hope this also helps somebody.

Take care Michael



--
Fehlerfreie Software wirkt weniger komplex und diskreditiert damit den
Entwickler!
----- Original Message -----
From: "Brian DeLuca" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, December 12, 2002 11:53 PM
Subject: RE: Struggling with indexed/repeating input fields


> Michael,
>
> Please Let me know if something doesn't make sense. I have included my
notes in a text file in case the formatting gets nasty.
>
> Enjoy
> b-
>
> I too have been struggling with the same type of scenario.  I have
> figured out a solution and reasoned the problem so here goes. Please bear
with me. I hope others will benefit or invalidate my solution.
>
> Setting up a logic iterate tag for this requires attributes
> 1 name --> In our case the name of the form
> 2 property --> the item that is an ArrayList, [], or map etc...
> 3 id --> This is going to be the key for the item that is set in a
>          request attribute.
>
> Recommend using type attribute as well.
>
> Our html input tag lets say in this a text tag requires
> name --> the bean whose member we want to populate
> property --> the member to store the data.
> indexed --> Set to TRUE since we are iterating.  This value is going
>            to be the index value of the converted MAP, ArrayList Etc.
>
> Now lets create an example
>
> Item is a class that only contains a string with appropriate get/set
> String item;
>
> FooBean has a member
> Item [] fooBar;
>
> Our form FooForm has a member of type FooBean.
> FooBean myInputRange;
>
> When one wants to create a JSP that uses FooForm and we need to ask
> the users for values for myInputRange.  To make it work will look like
> this in the JSP.
>
>
> /* This seems ok right?  Why do we need Class Item ? Why not a straight
String [] you ask.  Good question it is answered in how you need to set up
the subsequent Html:text tag */
>
> Text tag:
> " />
>
> This seems to be extreme.  I agree but it works.  Let's go through why all
this madness.
>
> Most doc says that while iterating make name=(Iterate id).  That is fine
in bean write but not here.  Html:text and other use BaseTagField which will
start writing you
> Well that is just not good in the request process the method populatebean
has no concept of anItem, It is not defined in the form so it won't populate
it, in fact you will never know it is not a hard error, the processor just
keeps going and forgets it.
>
> The next interesting piece here is the fact that you need some wrapper
class for String []. Why?  Simple when you hear it, There is *NO*
getter/Setter for a String.  Make Sense?  And you need the property
attribute in HTML:TEXT tag (TLD Rule -- REQUIRED) I tried
> tricking it by using property="" That doesn't help. because the resulting
html will look like this.
>
> NOTICE:  the "." after the index -- Throws off the populate bean process
also with no hard errors.
>
> Finally Why do we have to use scriptlet for the value?
> This is a pain in the butt, but here goes.
> The HTML:Text tag will figure out what the value is if it is not present,
but in our case it doesn't work.  Since our name"fooBean.fooBar" is not in
the PageContext and if value is null it makes a call to
RequestUtils.lookup( param's ) which ultimately makes a call to
findAttribute(name) which returns null and throws a JSP exception.  However
if you use the id from the logic:iterate it will find the context and work,
but alas it will not populate your form.  So to work around this we add a
value attribute.  This prevents the lookup unfortnately we cannot see what
the true value is
> without using scriplet   Why do we have yo use sciptlet -- Beacause the
tag will not try an evaluate the value of the value tag so it must be done
before hand with scriptlet.
>
> Please let me know if there is some flaw in my process because I don't
like the solution seems messy since I have to create wrapper classes of all
String items that I normally would put in an array.
>
>
> regards
> Brian DeLuca
> [EMAIL PROTECTED]
>
>
>
>
>
>  --- On Thu 12/12, Michael Olszynski  wrote:From: Michael Olszynski
[mailto: [EMAIL PROTECTED]]To: [EMAIL PROTECTED]: Thu,
12 Dec 2002 17:57:42 +0100Subject: Struggling with indexed/repeating input
fieldsI saw a post in the thread
http://www.mail-archive.com/[email protected]/msg49234.htmlI
have the same problem and I can�t get it working. Perhaps someone can help
me? It�d be very nice.I have the problems that the data in my formbean isn�t
updated. I mean, I get the data form my formbean in the jsp page. But when I
edit it and press submit, it is not updated. I get the same data as I got
before.Do you see perhaps an error? (I reviewed it now 7 hours with the
sample source attached in the upper thread, and I can�t find any error.
Thank you)It�s kind of urgent, because my thesis should be finished at the
end of december. Thanks!!!!Take care
Michael*********************************************************************
*****************************************This is my projekterfassung.jsp:
:        :
****************************************************************************
**********************************My struts-config.xml:          "-//Apache
Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd";>
name="timeProofForm"   type="de.proway.zerf.web.bean.TimeProofFormBean"/>
type="de.proway.zerf.web.controller.ShowTimeProofAction"
name="timeProofForm"                     scope="request"
input="/projekterfassung.jsp">
type="de.proway.zerf.web.controller.SaveTimeProofAction"
name="timeProofForm"                     scope="request"
input="/projekterfassung.jsp">
type="org.apache.struts.actions.AddFormBeanAction"/>
type="org.apache.struts.actions.AddForwardAction"/>
type="org.apache.struts.actions.AddMappingAction"/>
type="org.apache.struts.actions.ReloadAction"/>
type="org.apache.struts.actions.RemoveFormBeanAction"/>
type="org.apache.struts.actions.RemoveForwardAction"/>
type="org.apache.struts.actions.RemoveMappingAction"/>
****************************************************************************
**********************************SaveTimeProofAction.javapackage
de.proway.zerf.web.controller;import javax.servlet.http.*;import
org.apache.struts.action.*;import de.proway.zerf.web.bean.*;import
de.proway.zerf.app.controller.*;import de.proway.zerf.web.util.*;import
de.proway.zerf.app.bean.*;import java.util.*;import java.text.*;public final
class SaveTimeProofAction extends LoginCheckAction {    public ActionForward
perform( ActionMapping mapping,    ActionForm form, HttpServletRequest
request,    HttpServletResponse res ) {        TimeProofFormBean tpf =
(TimeProofFormBean) form;        System.out.println(tpf.toString());
System.out.println(tpf.getVector().toString());        for( int i=0; i
System.out.println( ((TimeProofTableBean)
pf.getVector().get(i)).getDate()  );          System.out.println(
((TimeProofTableBean) tpf.getVector().get(i)).getFromHour()  );
System.out.println( ((TimeProofTableBean)
tpf.getVector().get(i)).getFromMinute()  );        }        return
mapping.findForward(
ne" );    }}****************************************************************
**********************************************Show
TimeProofAction.javapackage de.proway.zerf.web.controller;import
javax.servlet.http.*;import org.apache.struts.action.*;import
de.proway.zerf.web.bean.*;import de.proway.zerf.app.controller.*;import
de.proway.zerf.web.util.*;import de.proway.zerf.app.bean.*;import
java.util.*;import java.text.*;public final class ShowTimeProofAction
extends LoginCheckAction {     public ActionForward perform( ActionMapping
mapping,    ActionForm form, HttpServletRequest request,
HttpServletResponse res ) {        Vector newCollection = new Vector();
TimeProofFormBean tpfb = ( TimeProofFormBean )form;
TimeProofTableBean tptb1 = new TimeProofTableBean();
TimeProofTableBean tptb2 = new TimeProofTableBean();
tptb1.setFromMinute(3);        tptb2.setFromMinute(4);
newCollection.add(tptb1);        newCollection.add(tptb2);
tpfb.setVector(newCollection);        return mapping.findForward(
ne" );    }}****************************************************************
**********************************************TimeProofFormBean.javapackage
de.proway.zerf.web.bean;import java.util.*;import
org.apache.struts.action.*;public class TimeProofFormBean extends ActionForm
{    public TimeProofFormBean() {    }    public Vector getVector()
{        return this.vector;    }    public void setVector( Vector v )
{        this.vector = v;    }    public int getEmployeeID() { return
employeeID; }    public void setEmployeeID( int employeeID ) {
this.employeeID = employeeID; }    public int getProjectID() { return
projectID; }    public void setProjectID( int projectID ) { this.projectID =
projectID; }    private int employeeID;    private int projectID;    private
Vector vector = new
Vector();}******************************************************************
********************************************TimeProofTableBean.javapackage
de.proway.zerf.web.bean;import java.util.*;import
java.io.Serializable;public class TimeProofTableBean implements Serializable
{public TimeProofTableBean(){}public String getFromHour(){        return
FromHour;    }public void setFromHour(String FromHour){        this.FromHour
= FromHour;    }public String getToHour(){        return ToHour;    }public
void setToHour(String ToHour){        this.ToHour = ToHour;    }public
String getFromMinute(){        return FromMinute;    }public void
setFromMinute(String FromMinute){        this.FromMinute =
mMinute;    }public String getToMinute(){        return ToMinute;    }public
void setToMinute(String ToMinute){        this.ToMinute =
inute;    }public String getDate(){        return Date;    }public void
setDate(String Date){        this.Date = Date;    }private String
FromHour;private String ToHour;private String FromMinute;private String
ToMinute;private String Date;}--Fehlerfreie Software wirkt weniger komplex
und diskreditiert damit den Entwickler!
>
> _______________________________________________
> Can a Web portal forever change your life?
> Win up to $25 Million on iWon - click here!
>


----------------------------------------------------------------------------
----


> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to