struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ed Griebel" <edgrie...@gmail.com>
Subject Re: Some JSP Taglib help needed
Date Tue, 01 Aug 2006 16:45:37 GMT
You could try something like:

<html:form action="....>
<c:foreach begin='0' end='${endval}' varStatus='idx'>
  <html-el:text property='student_name_${idx.count}'/>
</c:foreach>

But, why not make the student_name an array? The code below should
work, I havent' compiled it and I usually iterate thru a list of beans
not scalar Strings, but it should be close.
- Declare the element in the formbean as <form-property
name="student_name" type="java.util.List"/> or create student_name as
a java.util.List if using a POJO for an ActionForm
- Create a setup action that is called before the JSP is initially
rendered which  does a '((MyFormType)form).student_name = new
java.util.ArrayList();'
- In the JSP form:
<html:form action="...>
<c:foreach begin='0' end='${endval}' varStatus='idx'>
  <html-el:text property="student_name[${idx.index}]"/>
</c:foreach>
...
</html:form>

-ed

On 8/1/06, Bart Busschots <bart-lists@so-4pt.net> wrote:
> I want to do some thing that I think should be simple but I can't figure
> out how to do it with the Struts taglibs. So far I've never used a
> single scriptlet and I don't want to start now.
>
>
> I have a number stored in a bean which I can get at just fine (tested
> with bean:write).
>
> What I need to do is loop from 1 to that number and print a text area
> for each element in that range. Were the number three I should get the
> following output:
>
> <input type="text" name="student_name_1"  />
> <input type="text" name="student_name_2"  />
> <input type="text" name="student_name_3"  />
>
> Can I do that easily with a taglib?
>
> To put this into context, I have a two-step form, on the first form the
> user enters the number of students in their class (as well as other
> info) and then on the second page the user is presented with the
> appropriate number of text areas to allow them to enter the names of
> each of their students. Because I'm can't think of a better way to do it
> I'm submitting the list of names in a single hidden form field separated
> by :. I was going to use Java Script to suck all the names from the text
> areas, encode them and then stick the details in the hidden form field
> in an onsubmit action. Perhaps there is a better "struts" way to do
> this. If anyone has any advice I'm entirely open to changing the way I'm
> doing this.
>
> Thanks for your time and help,
>
> Bart.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message