You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bart Busschots <ba...@so-4pt.net> on 2006/08/01 18:21:38 UTC

Some JSP Taglib help needed

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


Re: Some JSP Taglib help needed

Posted by Al Eridani <al...@gmail.com>.
On 8/1/06, Bart Busschots <ba...@so-4pt.net> wrote:
> I can't see how to use the foreach tag in my case.

<c:forEach var="i" begin="${1}" end="${numberOfItems}">

  ...

  <input  type="text" name="<c:out value="name_of_box_${i}" />" value="" />

  ...

</c:forEach>

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


Re: Some JSP Taglib help needed

Posted by Bart Busschots <ba...@so-4pt.net>.
I can't see how to use the foreach tag in my case. I have no collection 
to loop through, just a number of times I need to loop and I need to 
access this "counter" within my loop. I immediately thought of the 
c:foreach and logic:iterate tags but can't see how to make them work in 
this case.

Bart.

Al Eridani wrote:
> On 8/1/06, Bart Busschots <ba...@so-4pt.net> wrote:
>
>> 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.
>
> <c:forEach>
>
> ---------------------------------------------------------------------
> 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


Re: Some JSP Taglib help needed

Posted by Al Eridani <al...@gmail.com>.
On 8/1/06, Bart Busschots <ba...@so-4pt.net> wrote:

> 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.

<c:forEach>

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


Re: Some JSP Taglib help needed

Posted by Bart Busschots <ba...@so-4pt.net>.
Thanks for that Ed,

I was thinking that it would make sense to have the form element be a 
list of some sort, however, can the StrutsValidator deal with validating 
all the elements of a variable list?

Thanks for your help,

Bart.


Ed Griebel wrote:
> 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 <ba...@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
>


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


Re: Some JSP Taglib help needed

Posted by Ed Griebel <ed...@gmail.com>.
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 <ba...@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