wood burning stoves 2.0*
The moose likes Struts and the fly likes dynamic textareas with Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "dynamic textareas with Struts 2" Watch "dynamic textareas with Struts 2" New topic
Author

dynamic textareas with Struts 2

Haitao Lok
Greenhorn

Joined: May 05, 2008
Posts: 8
I am learning Struts 2 and trying to add textareas dynamically with <s:textarea> tag in a jsp page (by clicking a button 'add more'). Can anyone please provide an example?

thanks in advance,

Haitao
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

If you want to add text fields on the browser, you have to use client-side JavaScript like this.
Name the fields using indexed properties and Struts will handle putting the collection in your JavaBean.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Haitao Lok
Greenhorn

Joined: May 05, 2008
Posts: 8
thanks for your response. sorry I didn't make myself clear here.

In my jsp file, I have the following (with struts tags)

<s:textfield key="subject" name="subject1"/>
<s:textfield key="level" name="level1"/>

I need to add a button on the page so that when I hit it, the browser will display another pair of the textfields

<s:textfield key="subject" name="subject2"/>
<s:textfield key="level" name="level2"/>


I understand javascript can generate pure html dynamically but not struts stuff, which is what baffles me.

Haitao
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Originally posted by Haitao Lok:
I understand javascript can generate pure html dynamically but not struts stuff, which is what baffles me.


On the browser side, there is no "struts stuff". Do a "view source" on a browser-rendered Struts JSP page and you'll see plain old HTML.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: dynamic textareas with Struts 2
 
Similar Threads
Swing: Unable to bring down the size of JPanel
Struts 2 / Tiles / Tiny MCE
adding text to end of list
Split a frame
How to reference a component?