I think there is an even easier solution.

Code below...

Java (the Array)

import java.util.ArrayList;
import org.apache.commons.beanutils.LazyDynaBean;

public class MyLazyArray extends ArrayList {
           private Class persistentClass;
           public MyLazyArray(){
                       this.persistentClass = LazyDynaBean.class;
           }

           public MyLazyArray(Class persistentClass){
                       this.persistentClass = persistentClass
           }           

           @SuppressWarnings("unchecked") // J2SE 5.0
           public Object get(int index) {
                       while (index >= super.size()){
                                   try{
 
super.add(persistentClass.newInstance());
                                   }catch(Exception e){
                                               throw new
IllegalArgumentException("no defualt constructor for
"+persistentClass.getName());  
                                   }
                       }
                       return super.get(index);
           }
}

Config (the form)
<form-bean name="myForm">

      type="org.apache.struts.validator.LazyValidatorForm">

      <form-property name="children"
type="se.alex.utils.struts.MyLazyArray">

      </form-property>

</form-bean>

JSP, it is very important that u use the var="children" to map the
attribute named children in the form otherwise no update is done.

<c:forEach var="children" items="${myForm.children}">

   <html:text property="id" name="children" indexed="true" /> 

   <html:text property="title" name="children" indexed="true" /> 

   <html:text property="order" name="children" indexed="true" />

</c:forEach>

/robert

________________________________

From: Brian Holzer [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 23, 2006 3:15 PM
To: struts-user@jakarta.apache.org
Subject: Fwd: logic:iterate

 

Hey Hans,

    I think you might want to use the nested tags for what you are
trying to do.  Depending on the version of struts you are using, the
nested taglib could be included with the Struts distribution.  Here is a
link to some tutorials etc. on the nested tags
http://www.keyboardmonkey.com/next/index.jsp

 

 

 

------------------------------------------------------------
Brian Holzer
IT Analyst
Saskatchewan Government Insurance
email: [EMAIL PROTECTED]
phone: (306) 751-1629
     fax: (306) 569-7683

>>> "Hans-Peter Petek" <[EMAIL PROTECTED]> 23/02/2006 4:24:12 am >>>
Hi,

does anyone knows a really good docu (with examples) how to use the
iteration (with indexed tags)?

Because my indexed iteration is not working, the first time the values
are
fine (loading), but after submitting the data, the changes are not
mapped to
the array (or arraylist).

Here is the problem again, maybe someone knows a good doc or has an idea
...?

I have modified the iteration from <logic:iterate id="right" ... to
<logic:iterate id="rightlist_ary" ... because that's my array I want to
have
filled, but after submitting the form I get ... 
[BeanUtils.populate]: java.lang.NullPointerException

any ideas? help would be great, thanks.


*** *** ***

i have a problem with the logic:iterate tag ... i want to show a list of
objects (which habe attributes with values of 0 or 1 or 2)

I want to show them in a list of radio-elements

OBJECT 1 0 1 2 0 1 2 0 1 2
OBJECT 20 1 2 0 1 2 0 1 2
...

where 0,1,2 is a radio-element (one of 0 or 1 or 2 can be choosen).



public class AuthRightForm extends ActionForm {

private Right[] rightlist_ary;

get / set ...

// after loading
rightlist_ary = new Right[10];
// filling rightlist_ary from DB ...
...


<logic:iterate id="right" name="authRightForm" indexId="idx"
property="rightlist_ary">
<tr>
<logic:present name="right">
<logic:notEmpty name="right">
<td><bean:write name="right"/>, Index = <bean:write name="idx"/>

<td><html:radio name="right" property="val_owner" value="0"
indexed="true"/></td>
<td><html:radio name="right" property="val_owner" value="1"
indexed="true"/></td>
<td><html:radio name="right" property="val_owner" value="2"
indexed="true"/></td>

</td>
</logic:notEmpty>
</logic:present>
</tr>
</logic:iterate>


The displaying of the values is working, so if Object 1, property 1 has
a
value of 2, the 3rd radio-element is selected - this works fine. But,
after
submitting the form, I do not see the changed values (if I change the
radio-buttons). The value of rightlist_ary is always null - so I do not
see
any objects in the list any more.

The request-object has values like that:
right[3].val_owner -> 1
right[2].val_owner -> 2
right[1].val_owner -> 1
...

Does anyone has a solution for that?

Thanks a lot
HP



**********DISCLAIMER**********

Reply via email to