• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

i am unable to figure out the problem with index

 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
vijay saraf
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Buzz......J Ranchies...........
Please Help Me ? i am stucked here......

Thanks,
Vijay Saraf
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
vijay saraf
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya again myself has solve the issue.

Thanks,
Vijay Saraf.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic