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) tpf.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( "done" );
}}**************************************************************************************************************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( "done" );
}}**************************************************************************************************************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 = FromMinute; }public
String getToMinute(){ return ToMinute; }public void setToMinute(String
ToMinute){ this.ToMinute = ToMinute; }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!
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.
(Works well in the Value attribute otherwise you will have to use toString() ).
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 fooBean;
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.
<logic:iterate id="anItem" name="fooForm" property="fooBean.fooBar">
/* 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:
<html:text name="fooBean.fooBar"
property="item"
value="<%= anItem.getItem() %>" />
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 others use BaseTagField which will start writing
<input name="something" here we need the something to be fooBean.fooBar *NOT* anItem.
if you use id you will see resulting html like
<input type="text" name="anItem[0].item" value="something">
Well that is just not good in the request process as 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.
<input type="text" name="fooBean.fooBar[0]." value="">
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 <%= anItem.getItem() %>
Why do we have to 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]
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>