struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian DeLuca" <>
Subject Re: Struggling with indexed/repeating input fields
Date Fri, 13 Dec 2002 15:14:10 GMT
Yes Micheal you've got it.  

Let me warn you though.  In the scenario 
I was giving you there was a level of nesting that you don't have.  If you ever come across
the scenario where you need to have


You will find that putting 

logic:iterate id="foo.something"

will give you an error on the parsing of ID which was my problem. And you will have to follow
the syntax I have given you earlier.  Just a 
Heads up. 

Good Luck in the future.


 --- On Fri 12/13, Michael Olszynski  wrote:From: Michael Olszynski [mailto:]To:, bdeluca1@iwon.comDate: Fri, 13 Dec 2002 10:37:41 +0100Subject:
Re: Struggling with indexed/repeating input fieldsHi Brian,I didnīt really get everything
what u wrote. (Itīs a problem of my badenglish, 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 notsubmit 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;    }   
   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;
   }private String FromHour;}**************************************************************************+In
my jsp I had following iterate Tag:property="timeProofList">       indexed="true"/>
So, I declare an "element" which comes from my timeProofForm with the methodgetTimeProofList.
(This returnes a vector of TimeProofTableBeans)So in the html:text struts goes to element.getfromHour
and gets the value ofthis fromHour Property in the TimeProofTableBean.But I never could press
submit to get the changes fromHourīsNow I tried to give id the name of the get/set method
of timeProofForm. Andnow I could read my data back! Itīs working. Hereīs my change:property="timeProofList">
      maxlength="2" indexed="true"/>  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 inputvalue="11">Itīs somehow logic, that it must
work like this. Because the timeProofListis the name of the get/set Method of the Formbean.
So I want to have theelement [0] ind this returned vedtor array. And from the element 0 I
want toget/set the fromHour property.I hope this also helps somebody.Take care Michael--Fehlerfreie
Software wirkt weniger komplex und diskreditiert damit denEntwickler!----- Original Message
-----From: "Brian DeLuca" To: Sent: Thursday, December 12, 2002 11:53 PMSubject: RE: Struggling
with indexed/repeating input fields> Michael,>> Please Let me know if something doesn't
make sense. I have included mynotes 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 bearwith 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 straightString
[] you ask.  Good question it is answered in how you need to set upthe subsequent Html:text
tag */>> Text tag:> " />>> This seems to be extreme.  I agree but it works.
 Let's go through why allthis madness.>> Most doc says that while iterating make name=(Iterate
id).  That is finein bean write but not here.  Html:text and other use BaseTagField which
willstart writing you> Well that is just not good in the request process the method populatebeanhas
no concept of anItem, It is not defined in the form so it won't populateit, in fact you will
never know it is not a hard error, the processor justkeeps going and forgets it.>> The
next interesting piece here is the fact that you need some wrapperclass for String []. Why?
 Simple when you hear it, There is *NO*getter/Setter for a String.  Make Sense?  And you need
the propertyattribute in HTML:TEXT tag (TLD Rule -- REQUIRED) I tried> tricking it by using
property="" That doesn't help. because the resultinghtml will look like this.>> NOTICE:
 the "." after the index -- Throws off the populate bean processalso 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 inthe PageContext and
if value is null it makes a call toRequestUtils.lookup( param's ) which ultimately makes a
call tofindAttribute(name) which returns null and throws a JSP exception.  Howeverif 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 avalue attribute.  This prevents the lookup unfortnately
we cannot see whatthe true value is> without using scriplet   Why do we have yo use sciptlet
-- Beacause thetag will not try an evaluate the value of the value tag so it must be donebefore
hand with scriptlet.>> Please let me know if there is some flaw in my process because
I don'tlike the solution seems messy since I have to create wrapper classes of allString items
that I normally would put in an array.>>> regards> Brian DeLuca>>>>>>>
 --- On Thu 12/12, Michael Olszynski  wrote:From: Michael Olszynski[mailto:]To:
struts-user@jakarta.apache.orgDate: Thu,12 Dec 2002 17:57:42 +0100Subject: Struggling with
indexed/repeating inputfieldsI saw a post in the thread
the same problem and I canīt get it working. Perhaps someone can helpme? Itīd be very nice.I
have the problems that the data in my formbean isnītupdated. I mean, I get the data form my
formbean in the jsp page. But when Iedit it and press submit, it is not updated. I get the
same data as I gotbefore.Do you see perhaps an error? (I reviewed it now 7 hours with thesample
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 theend of december. Thanks!!!!Take careMichael**************************************************************************************************************This
is my projekterfassung.jsp::        :**************************************************************************************************************My
struts-config.xml:          "-//ApacheSoftware Foundation//DTD Struts Configuration 1.0//EN""">name="timeProofForm"
javax.servlet.http.*;importorg.apache.struts.action.*;import de.proway.zerf.web.bean.*;*;import
de.proway.zerf.web.util.*;*;import java.util.*;import java.text.*;public
finalclass SaveTimeProofAction extends LoginCheckAction {    public ActionForwardperform(
ActionMapping mapping,    ActionForm form, HttpServletRequestrequest,    HttpServletResponse
res ) {        TimeProofFormBean tpf =(TimeProofFormBean) form;        System.out.println(tpf.toString());System.out.println(tpf.getVector().toString());
       for( int i=0; iSystem.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()  );  
     }        returnmapping.findForward(ne" );    }}**************************************************************************************************************ShowTimeProofAction.javapackage
de.proway.zerf.web.controller;importjavax.servlet.http.*;import org.apache.struts.action.*;importde.proway.zerf.web.bean.*;import*;importde.proway.zerf.web.util.*;import*;importjava.util.*;import
java.text.*;public final class ShowTimeProofActionextends LoginCheckAction {     public ActionForward
perform( ActionMappingmapping,    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.javapackagede.proway.zerf.web.bean;import
java.util.*;importorg.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()
{ returnemployeeID; }    public void setEmployeeID( int employeeID ) {this.employeeID = employeeID;
}    public int getProjectID() { returnprojectID; }    public void setProjectID( int projectID
) { this.projectID =projectID; }    private int employeeID;    private int projectID;    privateVector
vector = newVector();}**************************************************************************************************************TimeProofTableBean.javapackagede.proway.zerf.web.bean;import
java.util.*;;public class TimeProofTableBean implements Serializable{public
TimeProofTableBean(){}public String getFromHour(){        returnFromHour;    }public void
setFromHour(String FromHour){        this.FromHour= FromHour;    }public String getToHour(){
       return ToHour;    }publicvoid setToHour(String ToHour){        this.ToHour = ToHour;
   }publicString getFromMinute(){        return FromMinute;    }public voidsetFromMinute(String
FromMinute){        this.FromMinute =mMinute;    }public String getToMinute(){        return
ToMinute;    }publicvoid setToMinute(String ToMinute){        this.ToMinute =inute;    }public
String getDate(){        return Date;    }public voidsetDate(String Date){        this.Date
= Date;    }private StringFromHour;private String ToHour;private String FromMinute;private
StringToMinute;private String Date;}--Fehlerfreie Software wirkt weniger komplexund 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:> For additional commands, e-mail:--To unsubscribe, e-mail:
  For additional commands, e-mail: 

Can a Web portal forever change your life?
Win up to $25 Million on iWon - click here!

  • Unnamed multipart/alternative (inline, 7-Bit, 0 bytes)
View raw message