struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bart Busschots <>
Subject OK ... I'm almost there ..... just not quite yet
Date Tue, 01 Aug 2006 18:54:25 GMT
OK ... I have a simple two-step for for allowing a user of our system (a 
teacher) to create a group of students in our system. The first step 
asks the teacher to enter some basic information about the group as a 
whole, specifically, the name, the group type (a dropdown), a group 
description (a text area) and the number of students in the group. The 
second step then asks the teacher to enter the names of all the 
students. The obvious thing to note is that the number of text areas on 
the second page is dynamic. So, after some messing around I decided to 
store that information as a list of Strings in the form bean so my form 
looks like this in strutsconfig:

<form-bean name="createStudentGroupForm" 
   <form-property name="groupName" type="java.lang.String" />
   <form-property name="noStudents" type="java.lang.String" />
   <form-property name="groupType" type="java.lang.String" />
   <form-property name="wikiText" type="java.lang.String" />
   *<form-property name="studentNames" type="java.lang.String[]" />*

The first form submits to an action that populates the studentNames 
field like so:
    //get the dynamic form
    DynaValidatorForm theForm = (DynaValidatorForm)form;

    //get the details from the form
    String groupType = (String)theForm.get("groupType");
    int numStudents = Integer.parseInt(((String)theForm.get("noStudents")));

    //prepare the list of default student names
    String students[] = new String[numStudents];
    for(int i = 0; i < numStudents; i++) {
      students[i] = "Student " + (i + 1);

    //insert into the form
    theForm.set("studentNames", students);

I then try to render the text areas in my JSP like so:

  <html:form action="/mentor/createNamedStudentGroup" 
styleClass="vtie_form" onsubmit="encodeNames()">

  <ul class="form_element_list">
   <jsp:useBean id="createStudentGroupForm" scope="session" 
type="org.apache.struts.validator.DynaValidatorForm" />
   <logic:iterate id="student" name="createStudentGroupForm" 
    <li><html:text property="studentNames" indexed="true" /></li>

I do get out 5 text areas as you would expect but the values are messed 
up. Here is the source generated:

<li><input type="text" name="org.apache.struts.taglib.html.BEAN[0].studentNames"
value="[Ljava.lang.String;@1a175b" /></li>
<li><input type="text" name="org.apache.struts.taglib.html.BEAN[1].studentNames"
value="[Ljava.lang.String;@1a175b" /></li>
<li><input type="text" name="org.apache.struts.taglib.html.BEAN[2].studentNames"
value="[Ljava.lang.String;@1a175b" /></li>
<li><input type="text" name="org.apache.struts.taglib.html.BEAN[3].studentNames"
value="[Ljava.lang.String;@1a175b" /></li>
<li><input type="text" name="org.apache.struts.taglib.html.BEAN[4].studentNames"
value="[Ljava.lang.String;@1a175b" /></li>

As you can see I seem to be getting close to what I want but I'm not 
there just yet :(

Any pointers of where I've gone wrong would be greatly appreciated.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message