You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kevin DBS Kevin DBS <kn...@yahoo.com.hk> on 2002/06/20 08:19:59 UTC
problem with indexed textbox
Indexed (or with same name) textboxes in html cannot synchronize with
an action form
==== Problem ====
Hi! I would like to synchronize textbox data between some indexed
(or same name) textboxes in a jsp with an action form using struts 1.1b1.
For example, I would like to have two textboxes in html with the same
name "desc". When the user submits the form, the action form can
retrieve the content of these two textboxes in some way (e.g. an array).
==== Solutions ?!? ====
There are many solutions that I found:
1. Represent each column in the jsp with an array
( Ted Husted http://jguru.com/forums/view.jsp?EID=749162 )
2. Represent each row in the jsp as an object
( Venky Krishna http://jguru.com/forums/view.jsp?EID=905444 )
( Warwick Boote http://www.mail-archive.com/struts-user@jakarta.apache.org/msg13568.html )
3. Assign the names of the textboxes to "desc[0]" "desc[1]"
and provide indexed setter/getter methods
setXXX(int, ...) and getXXX(int) in the action form
( Jeff Hamilton http://jguru.com/forums/view.jsp?EID=749162 )
4. Represent each column in the jsp with an array, then use
iterate tag
( Ted Husted http://www.jguru.com/faq/view.jsp?EID=915898 )
In summary, what I found that only approach 3 works
perfectly but it will includes some scriptlet in the jsp.
Do you know is there any better approach (e.g. without adding
scriptlets to jsp?)?
Thank you very much!!!!
Best regards,
Kevin, Yuen Ka Nang
knyuendbs@yahoo.com.hk
---------------------------------
Do You Yahoo!?
至Hit手機鈴聲 全城火熱下載!
Download the HOTTEST ringtones from Yahoo!
Re: problem with indexed textbox
Posted by Kevin DBS Kevin DBS <kn...@yahoo.com.hk>.
I solved it!!! Answer to myself... =P
The best solution is Approach 5 -- use <nested> tag
library in struts.
Struts nested tags are introduced in struts 1.1,
therefore,
I highly suggest you to upgrade to struts 1.1.
The solution is similar to Approach 2:
In my action form, I represent each "desc" with a
SearchFormEntry
class object (actually the SearchFormEntry is an inner
class of
SearchForm).
public class SearchFormEntry {
private String desc;
public void setDesc(String desc) {
this.desc = desc;
}
public String getDesc() {
return this.desc;
}
}
And the action form SearchForm.java provides
setter/getter method:
public SearchFormEntry[] getEntry()
public void setEntry(SearchFormEntry[] entry)
Now, what approach 5 differs from approach 2 is that
in the jsp file, I use an *nested* iterate tag:
Desc:<br>
<nested:iterate property="entry">
<nested:text property="desc"/><br>
</nested:iterate>
and then it works perfectly!!!
Better than approach 3!! No scriptlet is needed!!!
You may take a look at my approach 5 at:
http://www20.brinkster.com/strutstest/index.html
Actually, I have learnt the solution from the
NeXt nested tag tutorial in keyboardmonkey:
http://www.keyboardmonkey.com/pilotlight/index.jsp
Cool!!
Best regards,
Kevin, Yuen Ka Nang
knyuendbs@yahoo.com.hk
--- Kevin DBS Kevin DBS <kn...@yahoo.com.hk>
的郵件內容:>
> Indexed (or with same name) textboxes in html cannot
> synchronize with
> an action form
>
> ==== Problem ====
>
> Hi! I would like to synchronize textbox data between
> some indexed
> (or same name) textboxes in a jsp with an action
> form using struts 1.1b1.
> For example, I would like to have two textboxes in
> html with the same
> name "desc". When the user submits the form, the
> action form can
> retrieve the content of these two textboxes in some
> way (e.g. an array).
>
> ==== Solutions ?!? ====
>
> There are many solutions that I found:
>
> 1. Represent each column in the jsp with an array
> ( Ted Husted
> http://jguru.com/forums/view.jsp?EID=749162 )
>
> 2. Represent each row in the jsp as an object
> ( Venky Krishna
> http://jguru.com/forums/view.jsp?EID=905444 )
> ( Warwick Boote
>
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg13568.html
> )
>
> 3. Assign the names of the textboxes to "desc[0]"
> "desc[1]"
> and provide indexed setter/getter methods
> setXXX(int, ...) and getXXX(int) in the action
> form
> ( Jeff Hamilton
> http://jguru.com/forums/view.jsp?EID=749162 )
>
> 4. Represent each column in the jsp with an array,
> then use
> iterate tag
> ( Ted Husted
> http://www.jguru.com/faq/view.jsp?EID=915898 )
>
> In summary, what I found that only approach 3 works
> perfectly but it will includes some scriptlet in the
> jsp.
> Do you know is there any better approach (e.g.
> without adding
> scriptlets to jsp?)?
>
> Thank you very much!!!!
>
> Best regards,
> Kevin, Yuen Ka Nang
> knyuendbs@yahoo.com.hk
>
>
>
>
> ---------------------------------
> Do You Yahoo!?
> 至Hit手機鈴聲 全城火熱下載!
> Download the HOTTEST ringtones from Yahoo!
>
_________________________________________________________
Do you Yahoo!?
至Hit手機鈴聲 全城火熱下載
Download the HOTTEST ringtones from Yahoo!
http://ringtone.yahoo.com.hk
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>