• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamic textareas with Struts 2

 
Haitao Lok
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Haitao Lok
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic