Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

dynamic textareas with Struts 2

 
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
 
Bartender
Posts: 9612
16
Mac OS X Linux 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: 9612
16
Mac OS X Linux 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.
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic