• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1540
  • Last Modified:

<logic:iterate> and <logic:radio> confusion

Hi Friends,
Right now,I iterate over an ArrayList that gets populated form the arrayForm class and produce 2 radio buttons.But I want to conditionalize it,so that if param=1,then only first radio button should show up.If param=2,second radio button should show up.I am passing the param value in the url.So rite now,I have this:

<logic:iterate id="arrayList" name="arrayForm" property="arrayList">
 <tr>
    <td>
         <html:radio idName="arrayList" property="array" value="value"/>
   </td>                                    
         <logic:equal parameter="param" value="1">                  
                <logic:equal name="arrayList" property="value" value="XYZ">
         </logic:equal>
   <td>
        <bean:write name="arrayList" property="label"/>
   </td>
   </logic:equal>
                        
   <logic:equal parameter="param" value="2">      
  <logic:equal name="arrayList" property="value" value="ABC">
  </logic:equal>
  <td>
  <bean:write name="arrayList" property="label"/>
   </td>
   </logic:equal>
                        
</tr>
</logic:iterate>


So,please tell me how to remove that <logic:iterator> tag because,if i remove it,then this starts causing problems:

<html:radio idName="arrayList" property="array" value="value"/>

And,for the <bean:write>  too,I want to show only one label at a time,like this works:

<bean:write name="arrayForm" property="arrayList[1].label"/>

is this correct???

Please help
0
harmeek_80
Asked:
harmeek_80
  • 4
  • 4
1 Solution
 
fargoCommented:
the way you are using logic:equal is not correct. Two logic equal tags should be nested..but in your case it is not.

Solution:
// just define a bean with label as XYZ (default)
<bean:define id="label" value="XYZ" />                

// now do the parameter handling
<logic:equal parameter="param" value="1">
        <bean:define id="label" value="XYZ" />                
</logic:equal>

<logic:equal parameter="param" value="2">
        <bean:define id="label" value="ABC" />                
</logic:equal>

then just use
<td>
         <html:radio idName="arrayList" property="array" value="value"/>
   </td>                              
   <td>
        <bean:write name="label"/>
   </td>
0
 
harmeek_80Author Commented:
Thanks fargo,
But the problem is that solution I jus cannot define any label in the bean write,the names are stored in a labelvaluebean object stored inside the arraylist,so how to do that...pls help.

 
0
 
fargoCommented:
may be u need something like this (i couldn't understand much from your last post)
 
<logic:iterate id="arrayList" name="arrayForm" property="arrayList">
 <tr>
    <td>
         <html:radio idName="arrayList" property="array" value="value"/>
   </td>                              
         <logic:equal parameter="param" value="1">              
                <logic:equal name="arrayList" property="value" value="XYZ">
                  <td>
                       <bean:write name="arrayList" property="label"/>
                  </td>
              </logic:equal>
         </logic:equal>
                   
       <logic:equal parameter="param" value="2">    
              <logic:equal name="arrayList" property="value" value="ABC">
              <td>
                    <bean:write name="arrayList" property="label"/>
              </td>
             </logic:equal>
     </logic:equal>
</tr>
</logic:iterate>
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
harmeek_80Author Commented:
Thats the exact same thing,I am doing.But my question is ,thatproduces 2 radio buttons,so how can i remove that iteration logic ,so that it produces only one radio button at a time depending upon the conditions i inpu..thanks
0
 
harmeek_80Author Commented:
I got that solved fargo,can u please answer this one:

Hi Friends,
I read in a parameter in struts like this:

<logic:equal parameter="param" value="1">      



But,how to access this "param" inside the block,like i want to do this:

<logic:equal name="addForm" property="arrayList[param].value" value="XYZ">



instead of doin this,that i have right now,

<logic:equal name="addForm" property="arrayList[1].value" value="XYZ">



Any help would be appreciated.Thanks in Advance.
0
 
fargoCommented:
this link is exactly what u need.
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=58&t=004311

moreover try to do the parameter handling or set for the LabelValueBean in the action class in action form.
read the second section of the posted link and u are all set.
0
 
harmeek_80Author Commented:
Hi fargo,
Let me increase the points first..I have gone thru that link.But I need this exactly:

I have an arraylist that i populate using labelvaluebean objects and pass it to my jsp.In my jsp i access it as:

 <logic:equal name="addForm" property="arrayList[0].value" value="XYZ">

 But I don't want to hardcore the index variable,so how can I put the value using a variable,something like this:

 <% int s = 0; %>
 <logic:equal name="addForm" property="arrayList[<%=s%>].value" value="XYZ">

 When i try that, its throwing exceptions,please help.

 Even this is not working:
 <bean:define id="param" value="0"/>
 <logic:equal name="addForm" property="arrayList[<bean:write name="param" />].value" value="XYZ">

Please help.
0
 
fargoCommented:
have u tried this
 <logic:equal name="addForm" property="<%= ((LabelValueBean)arrayList.get(0)).getValue()%>" value="XYZ">
if u directly want the value on the label or something, u need to implement that method in the bean and use it straightforward as above without using index (this will make u get rid of iteration)

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now