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

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
0
KirtipurItagol
Asked:
KirtipurItagol
  • 6
  • 4
1 Solution
 
mrigankCommented:
Need to Extend the struts tabletag.
0
 
KirtipurItagolAuthor Commented:
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>
0
 
mrigankCommented:
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

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
mrigankCommented:
sorry it is

request.getParameterValues("CHECKED_RESULTS");
0
 
KirtipurItagolAuthor Commented:
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.
0
 
mrigankCommented:
Did  you try the approach that I have posted ?
0
 
KirtipurItagolAuthor Commented:
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
0
 
mrigankCommented:
Replace <html:radio property="selectAccount"/>

with


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


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

and try it  out.
Am just sugesting to use a checkbox.
0
 
KirtipurItagolAuthor Commented:
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??
0
 
mrigankCommented:
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.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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