You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andreas Hartmann <an...@freenet.de> on 2006/04/12 19:47:50 UTC
creating html:text-forms on the fly
Hello,
I've got a lot of html:text forms, which are created on the fly -
therefore I don't know during programming, which getter and setter-methods
will be needed. I assume, it works by using arrays.
<logic:iterate property="value" id="entry" indexId="ctr" >
<html:text name="entry" property='<%="value["+ctr+"]"%>' >
</logic:iterate>
In the ActionForm:
ArrayList <String> value=new ArrayList<String>();
public String getValue(int id) {return value.get(id);}
public void setValue(String value, int id) {value.set(id,value);}
Is this correctly?
Would it be possible to operate with a Hashtable, too?
Something like:
In the ActionForm
Hashtable <String,String> hash = new Hashtable <String,String>();
Hashtable <String,String> hash getHashtable (return hash;)
public String getValue(String key) {return hash.get(key);}
public String setValue(String value, String key) {hash.put(key,value);}
In the jsp:
<logic:iterate property="hashtable" id="key" >
<html:text name="key" property="value" >
</logic:iterate>
How could the Hashtable be directly accessed in the jsp without the
iterate-tag (literal and with a method)?
<html:text name="hashtable" property="??">
I would be very glad if anybody could give me some advice, how to do these
things.
Kind regards,
Andreas Hartmann
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: creating html:text-forms on the fly
Posted by Andreas Hartmann <an...@freenet.de>.
Hello Rick,
I implemented your idea for unknown <html:text - forms by using a Object
list, which is iterated in the jsp-file. The object provides getter and
setter Methods and the data. Presentation is working fine as expected.
There came up a problem with accessing the <html:text-forms with
java-script, because all names of the <html:text-form are now the same
(from property=""). I solved this problem by accessing the <html:text-form
via array-index in java-script, which I gave to the object (must be
dynamically, too).
Until now, I didn't implement the evaluation of the objects. But this
should be no problem as the presentation does work already I suppose.
Thanks for your help and your internet site, which helps people like me to
implement own forms.
Kind regards,
Andreas Hartmann
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: creating html:text-forms on the fly
Posted by Rick Reumann <ri...@gmail.com>.
Andreas Hartmann wrote:
> Hello,
>
> I've got a lot of html:text forms, which are created on the fly -
> therefore I don't know during programming, which getter and setter-methods
> will be needed. I assume, it works by using arrays.
>
> <logic:iterate property="value" id="entry" indexId="ctr" >
> <html:text name="entry" property='<%="value["+ctr+"]"%>' >
> </logic:iterate>
More than likely you really don't need or want to dynamically create
properties. (You couldn't do it like you were doing above anyway.)
What you probably want to do is simply use a List or a Map as the
property itself in the ActionForm and make sure then you populate your
List or Map with regular beans. You beans are 'nested' in the List or
Map. I have a tutorial showing this here
http://www.learntechnology.net/struts-nested.do
If you can give more specifics of exactly what you are trying to
capture, I can help out more.
--
Rick
http://www.learntechnology.net
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org