DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23332>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23332

RadioGroup tag to avoid using scriplet expressions with nested iterators

           Summary: RadioGroup tag to avoid using scriplet expressions with
                    nested iterators
           Product: Struts
           Version: 1.1 Final
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Custom Tags
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


I believe that there is a need for the RadioGroup tag. If the radio tag us 
iused inside nested iterate tags then the scriplets is the only (?) solution 
currently to get it working. Here is an example.

The jsp operates on the collection of the Question instances. And each
question has a list of pre-defined answers to choose from. The idea is
to list all of the questions and then collect the answers chosen. The
"list" and "text" types are working (generating both
name="questions[x].answer", where x is the index of the question) but
radio does not.

If indexed="true" is specified, then each pre-defined radio answer has
a name="questions[x].answer" WHERE x is the index of the PRE-DEFINED
ANSWER from the predefinedAnswers iterator (not from the questions
iterator).

If indexed attribute is not specified, then the input field name is
rendered just as name="answer".

Here is the relevant portion of the jsp:

<logic:iterate id="questions" property="questions"
name="questionSetForm">

  <logic:equal name="questions" property="type" value="list">
    <div>It's a list</div>
    <html:select name="questions" property="answer" indexed="true">
      <html:optionsCollection name="questions"
property="predefinedAnswers" value="id" label="label"/>
    </html:select>
  </logic:equal>
  
  <logic:equal name="questions" property="type" value="text">
    <div>It's a text</div>
    <html:text name="questions" property="answer" indexed="true" />
  </logic:equal>
  
  <logic:equal name="questions" property="type" value="radio">
    <div>It's a radio choice</div>
    <logic:iterate id="predefinedAnswer" property="predefinedAnswers"
name="questions">
      <html:radio name="questions" property="answer" value="id"
idName="predefinedAnswer">
        <bean:write name="predefinedAnswer" property="label" />
      </html:radio>
    </logic:iterate>
  </logic:equal>

</logic:iterate>

The questionSetForm class defines only one property that hold a
collection of Question instances:

  public List getQuestions() {
    return questions;
  }

  public void setQuestions(List questions) {
    this.questions = questions;
  }

The Question class defines the following relevant properties (along
with corresponding get/set methods):
  private Integer id = null;
  private Integer questionSetId = null;
  private String type = null;
  //Holds the collection of the PredefinedAnswer instances
  private List predefinedAnswers = null; 
  private String label = null;
  private String answer = null;

The PredefinedAnswer class defines the id and label properties used to
render the list of choices.

The only solution (work around, rather) that comes to mind is to add the 
indexId attribute to the external loop and use its value in the radio property:

  <logic:iterate id="questions" property="questions" name="questionSetForm" 
indexId="index">
...
            <html:radio property="<%= \"questions[\"+ index +\"].answer\"%>" 
value="id" idName="predefinedAnswer">

I believe that this example demonstrates the need to the RadioGroup tag that 
would work similar to the existing Select tag by defining the name of the 
property there.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to