*
The moose likes Struts and the fly likes i am unable to figure out the problem with index Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "i am unable to figure out the problem with index" Watch "i am unable to figure out the problem with index" New topic
Author

i am unable to figure out the problem with index

vijay saraf
Ranch Hand

Joined: Jan 08, 2005
Posts: 141
Hello All,
i am unable to figure out the problem ;
See here is my application classes & code
one bean name as UserRoleMasterBean : having fields 'id' , 'role' with simple getter & setter.
one extension bean as UerRoleMasterExt : having fields 'UserRoleMasterBean' ,'checked' ( for check box ) along with getter & setter
one form bean as UserRoleMasterForm : having array of UerRoleMasterExt[ ] with getter & setter by index

in display jsp i have putted code as bellow

<logic:iterate id="lUserRoleMasterExt" name="UserRoleMasterForm" property="userRoleMasterExt">
<tr>
<td width="20%" class="TDData" align="Center"><bean:write name="lUserRoleMasterExt" property="userRoleMasterBean.id" /></td>
<td width="60%" class="TDData" align="left"><html:text name="lUserRoleMasterExt" property="userRoleMasterBean.role" /></td>
<td width="20%" class="TDData" align="Center"><html:checkbox name="lUserRoleMasterExt" property="checked"></html:checkbox></td>
</tr>
</logic:iterate>


while in LookupDispatchAction's edit method i have putted code as bellow :

UserRoleMasterForm userRoleForm = (UserRoleMasterForm) form;
UserRoleMasterExt[] roleArray = userRoleForm.getUserRoleMasterExt();
System.out.println(" roleArray is "+roleArray.length);
if(roleArray !=null && roleArray.length>0){
for(int i=0;i<roleArray.length;i++){
UserRoleMasterExt lUserRoleMasterExt = roleArray[i];
if(lUserRoleMasterExt.getChecked()){
UserRoleMasterBean lUserRoleMasterBean = lUserRoleMasterExt.getUserRoleMasterBean();
//check duplicate & Update the bean
}
}
}

the display is working fine but while on update it is not working
the problem is i am getting roleArray length zero always.
should i have to place index also in property of <td>'s ?
If any one have good example/link for index display and saving please reply.
However i have read all the threads related to index.

Thanks,
Vijay Saraf.
[ November 24, 2006: Message edited by: vijay saraf ]

Thanks
Vijay Saraf.
vijay saraf
Ranch Hand

Joined: Jan 08, 2005
Posts: 141
on changing the display as

<logic:iterate id="lUserRoleMasterExt" name="UserRoleMasterForm" property="userRoleMasterExt" indexId="index">
<tr>
<td width="20%" class="TDData" align="Center"><html:text name="UserRoleMasterForm" property="userRoleMasterExt[${index}].userRoleMasterBean.id" /></td>
<td width="60%" class="TDData" align="left"><html:text name="UserRoleMasterForm" property="userRoleMasterExt[${index}].userRoleMasterBean.role" /></td>
<td width="20%" class="TDData" align="Center"><html:checkbox name="UserRoleMasterForm" property="userRoleMasterExt[${index}].checked"></html:checkbox></td>
</tr>
</logic:iterate>


i am getting exception as
exeption : javax.servlet.ServletException: BeanUtils.populate
root cause : java.lang.ArrayIndexOutOfBoundsException

in my UserRoleMasterForm the default size of array is zero .
please help me.

Thanks,
Vijay Saraf
vijay saraf
Ranch Hand

Joined: Jan 08, 2005
Posts: 141
Buzz......J Ranchies...........
Please Help Me ? i am stucked here......

Thanks,
Vijay Saraf
Christian Nash
Ranch Hand

Joined: Jan 17, 2006
Posts: 107
Hi,
Maybe this will help.
one bean name as UserRoleMasterBean : having fields 'id' , 'role' ,'checked' ( for check box ) along with getter & setter
one form bean as UserRoleMasterForm : having array of UserRoleMasterBean[ ] with getter & setter

Here userRoleMasterExt is the collection of UserRoleMasterBean with getter & setter




- Christian
vijay saraf
Ranch Hand

Joined: Jan 08, 2005
Posts: 141
thanks Christian for your valuable reply.
but the scenario is as
UserRoleForm having array of UserRoleMasterExt
UserRoleMasterExt is having UserRoleMasterBean along with CheckBoxex
and then UserRoleMasterBean having id and role as property.
any way......
well i think , i should go for complete tutorial for struts first then come to forum.

Thanks,
Vijay Saraf.
[ November 27, 2006: Message edited by: vijay saraf ]
vijay saraf
Ranch Hand

Joined: Jan 08, 2005
Posts: 141
ya again myself has solve the issue.

Thanks,
Vijay Saraf.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Sorry vijay...I was (as I suspect many others) away from the board for the past several days taking advantage of a long Thanksgiving Day weekend. It looks like your issue is related to indexed properties...a fairly hot topic (or at least confusing topic) that has generated lots of recent threads.

- Brent
vijay saraf
Ranch Hand

Joined: Jan 08, 2005
Posts: 141
Any way Mr.Brent,
I have read your thread having example, 2-3 times,That was a good one.
as i am just learning struts,so i have changed my code and eliminated the extra beans & extension bean and merged into one.
but my view with indexed property is that it is easy to implement List s instead of Arrays.

Thanks,
Vijay Saraf.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i am unable to figure out the problem with index
 
Similar Threads
dynamic number of struts:checkbox
Display Check Boxes & Dropdowns in Struts with search results
Iterator and multibox
how to use- html:checkbox - and iterate it through - logic:iterate
printing in table format using logic:iterate and bean:write