Link to home
Start Free TrialLog in
Avatar of KirtipurItagol
KirtipurItagol

asked on

iterating radio buttons

hi experts, i have a search button and it will display a list of results on the same page. Now I want to display a radio button on each list of record in the jsp using struts tag. how can i achieve this? That way I can check any of the displayed result for further manipulation.
thanks
Avatar of mrigank
mrigank

Need to Extend the struts tabletag.
Avatar of KirtipurItagol

ASKER

any other options?? Here's my tag:
<tr class="tableHeader">
<logic:present name="searchForm" property="results">
      <logic:iterate id="result" name="searchForm" property="results">
 <td height="20" class="tableHeader"><radio button appears below this header></td>
 <td class="tableHeader"><bean:write name="result" property="legalEntityName"/>Legal Entity Name</td>
 <td class="tableHeader"><bean:write name="result" property="existingAccountNumber"/>Account Number</td>
 <td class="tableHeader"><bean:write name="result" property="legalCountry"/>Country</td>
 <td class="tableHeader"><bean:write name="result" property="existingCurrency"/>Currency</td>
 <td class="tableHeader"><bean:write name="result" property="orgTypeCd"/>Organization Type</td>
<td class="tableHeader" align="center"><bean:write name="result" property="branch"/>Branch</td>
</logic:iterate>
</tr>
</logic:present>
Use a checkbox

<td height="20" class="tableHeader"><INPUT TYPE=CHECKBOX NAME="CHECKED_RESULTS" value="<bean:write name="result" property="legalEntityName"/>"></td>


In your Java class use
request.getParameterNames("CHECKED_RESULTS");

It shall return a comma separated value of all checked legalEntityNames.

Let me know if it helps

sorry it is

request.getParameterValues("CHECKED_RESULTS");
My Bad. Actually the code goes like this:
This is my table columns:
<logic:present name="searchForm" property="results">
      <logic:iterate id="result" name="searchForm" property="results">
<TABLE cellSpacing=1 cellPadding=0 width="100%" border=0>

<tr class="tableHeader">
 <td height="20" class="tableHeader"></td>
 <td class="tableHeader">Legal Entity Name</td>
 <td class="tableHeader">Account Number</td>
 <td class="tableHeader">Country</td>
 <td class="tableHeader">Currency</td>
 <td class="tableHeader">Organization Type</td>
<td class="tableHeader" align="center">Citigroup Branch</td>
</tr>

<tr bgcolor="white">
And this is how it will iterate when it fetches data from the database in the same jsp page:


 <td class="detailsCenter" align="center"><html:radio property="selectAccount"/></td>
 <td class="details"><bean:write name="result" property="legalEntityName"/></td>
 <td class="details"><a href="/accntData.do"><bean:write name="result" property="existingAccountNumber"/></a></td>
 <td class="details"><bean:write name="result" property="legalCountry"/></td>
 <td class="details"><bean:write name="result" property="existingCurrency"/></td>
 <td class="details"><bean:write name="result" property="orgTypeCd"/></td>
 <td class="details"><bean:write name="result" property="branch"/></font></td>      
</tr>
Am I doing it correctly?? By the way in the action form i have getters and setters for all the form fields. And in my action class I've:
public class SearchAction extends Action{
      public ActionForward execute(ActionMapping mapping, ActionForm form,
               HttpServletRequest request, HttpServletResponse response)
               throws IOException, ServletException {      
         
               
                ArrayList results = new ArrayList();
                        SearchDAO objDAO = new SearchDAO();

               
                searchForm searchForm = (searchForm) form;
                //perform  search based on what criteria was entered
                results = objDAO.getSearchResult(searchForm.getLegalEntityName(),
                              searchForm.getOrgTypeCd(),searchForm.getExistingAccountNumber(),searchForm.getBranch());
           
                searchForm.setResults(results);
               
                //forward control to this actions input page
                return mapping.getInputForward();
                        
      }
}

First of all I'm wondering whether i'm doing it correctly and second of all I'm not totally sure about iterating through the radio buttons. help me out folks.
Did  you try the approach that I have posted ?
mrigank, i want to display the result on a table in a same jsp with four search criteria. Upon fetching datas, it will display the results in six columns in the same page with a radio button on each result. So it would be something like this after the user clicks the submit button:

<logic:present name="searchForm" property="results">
      <logic:iterate id="result" name="searchForm" property="results">
<TABLE cellSpacing=1 cellPadding=0 width="100%" border=0>

<tr class="tableHeader">
 <td height="20" class="tableHeader"></td>
 <td class="tableHeader">Legal Entity Name</td>
 <td class="tableHeader">Account Number</td>
 <td class="tableHeader">Country</td>
 <td class="tableHeader">Currency</td>
 <td class="tableHeader">Organization Type</td>
<td class="tableHeader" align="center">Citigroup Branch</td>
</tr>

<tr bgcolor="white">

 <td class="detailsCenter" align="center"><html:radio property="selectAccount"/></td>
 <td class="details"><bean:write name="result" property="legalEntityName"/></td>
 <td class="details"><a href="/accntData.do"><bean:write name="result" property="existingAccountNumber"/></a></td>
 <td class="details"><bean:write name="result" property="legalCountry"/></td>
 <td class="details"><bean:write name="result" property="existingCurrency"/></td>
 <td class="details"><bean:write name="result" property="orgTypeCd"/></td>
 <td class="details"><bean:write name="result" property="branch"/></font></td>      
</tr>

</TABLE>
</logic:iterate>
 </logic:present>

So I will use your code in action class like :
request.getParameterValues("selectAccount");//this will get the radio button and in the jsp page, with iterate tag, will iterate with each result. Is that right?
Server in my IDE is still uninstalled, I'm just trying to work on the problem before the project initiation. Thanks
ASKER CERTIFIED SOLUTION
Avatar of mrigank
mrigank

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and also in the form bean i have to have getters and setters for the selectAccount, isn't that right?? But why not radio button??
you can do that. For checkboxes, if the box is not checked ,  then you get a null else a not  null value. That should be your check.

A checkbox fits here much better than a radio button.