struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From St├ęphane Zuckerman <stephane.zucker...@gmail.com>
Subject Highly dynamic forms
Date Tue, 07 Jun 2005 13:53:56 GMT
Hello,

Here's the question for the short version (below you'll find some 
lengthier explanations ...) :

I'd like to render a list of groups of radio buttons. Said list has a 
variable length. So my data structure looks like :

[ [radio1,radio2,radio3], [radio1,radio2,radio3,radio4], ...]

I am currently using Struts 1.2.4. Is there a way of rendering these 
groups of radio buttons without upgrading my version of Struts ?

------------

For the detailed explanation :

I'm trying to render a form with fields which aren't defined by advance. 
More precisely, I have a List (an ArrayList) of custom objects, which 
are described like this :

public class MyField {
     private String type, group;
     private Object data;
     // then the accessors follow ...
}

The "type" attribute contains which kind of field is to be rendered 
(radio, text, checkbox, etc.). The "group" attribute enables me to know 
which information is answered. For example :

I have two objects that are to be filled by the user, a text field, and 
a radio field. So my list of MyField objects will look something like :

[ {"radio", "g1", (ArrayList object)}, {"text", "", (String object)} ]

Now, what I need is to not only render the radio buttons part (which I 
eventually managed), but also to get a way to have the submission 
succeed ! :-)

Here is a very small example of JSP code :

<html:form action="/indices">
   <logic:iterate id="liste" name="indicesForm" property="liste"
                                                       indexId="i">
     <logic:iterate id="item" name="liste" indexId="j">
       <html:radio property="liste[${i}]" value="${item.value}"/>
       ${item.label}<br/>
     </logic:iterate>
   </logic:iterate>
   <html:submit/>
</html:form>

I voluntarily didn't use indexed properties, since I have to "play" with 
inner and outer loops' indexes. Although the form is rendered the right 
way, I can't submit info with it, I get an error that says :

"java.lang.NullPointerException: No indexed value for 'liste[2]'"

Since I use a List object, I suppose this isn't very surprising after all.

But then, what's the best way of doing that kind of stuff ?
-- 
St├ęphane Zuckerman

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


Mime
View raw message