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
thanks
Need to Extend the struts tabletag.
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="existingAccountN umber"/>Ac count Number</td>
<td class="tableHeader"><bean: write name="result" property="legalCountry"/>C ountry</td >
<td class="tableHeader"><bean: write name="result" property="existingCurrency "/>Currenc y</td>
<td class="tableHeader"><bean: write name="result" property="orgTypeCd"/>Orga nization Type</td>
<td class="tableHeader" align="center"><bean:write name="result" property="branch"/>Branch< /td>
</logic:iterate>
</tr>
</logic:present>
<tr class="tableHeader">
<logic:present name="searchForm" property="results">
<logic:iterate id="result" name="searchForm" property="results">
<td height="20" class="tableHeader"><radio
<td class="tableHeader"><bean:
<td class="tableHeader"><bean:
<td class="tableHeader"><bean:
<td class="tableHeader"><bean:
<td class="tableHeader"><bean:
<td class="tableHeader" align="center"><bean:write
</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_R ESULTS");
It shall return a comma separated value of all checked legalEntityNames.
Let me know if it helps
<td height="20" class="tableHeader"><INPUT
In your Java class use
request.getParameterNames(
It shall return a comma separated value of all checked legalEntityNames.
Let me know if it helps
sorry it is
request.getParameterValues ("CHECKED_ RESULTS");
request.getParameterValues
ASKER
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">Accoun t Number</td>
<td class="tableHeader">Countr y</td>
<td class="tableHeader">Curren cy</td>
<td class="tableHeader">Organi zation 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:writ e name="result" property="legalEntityName" /></td>
<td class="details"><a href="/accntData.do"><bean :write name="result" property="existingAccountN umber"/></ a></td>
<td class="details"><bean:writ e name="result" property="legalCountry"/>< /td>
<td class="details"><bean:writ e name="result" property="existingCurrency "/></td>
<td class="details"><bean:writ e name="result" property="orgTypeCd"/></td >
<td class="details"><bean:writ e 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(sea rchForm.ge tLegalEnti tyName(),
searchForm.getOrgTypeCd(), searchForm .getExisti ngAccountN umber(),se archForm.g etBranch() );
searchForm.setResults(resu lts);
//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.
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">Accoun
<td class="tableHeader">Countr
<td class="tableHeader">Curren
<td class="tableHeader">Organi
<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
<td class="details"><bean:writ
<td class="details"><a href="/accntData.do"><bean
<td class="details"><bean:writ
<td class="details"><bean:writ
<td class="details"><bean:writ
<td class="details"><bean:writ
</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(sea
searchForm.getOrgTypeCd(),
searchForm.setResults(resu
//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 ?
ASKER
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">Accoun t Number</td>
<td class="tableHeader">Countr y</td>
<td class="tableHeader">Curren cy</td>
<td class="tableHeader">Organi zation 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:writ e name="result" property="legalEntityName" /></td>
<td class="details"><a href="/accntData.do"><bean :write name="result" property="existingAccountN umber"/></ a></td>
<td class="details"><bean:writ e name="result" property="legalCountry"/>< /td>
<td class="details"><bean:writ e name="result" property="existingCurrency "/></td>
<td class="details"><bean:writ e name="result" property="orgTypeCd"/></td >
<td class="details"><bean:writ e name="result" property="branch"/></font> </td>
</tr>
</TABLE>
</logic:iterate>
</logic:present>
So I will use your code in action class like :
request.getParameterValues ("selectAc count");// 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
<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">Accoun
<td class="tableHeader">Countr
<td class="tableHeader">Curren
<td class="tableHeader">Organi
<td class="tableHeader" align="center">Citigroup Branch</td>
</tr>
<tr bgcolor="white">
<td class="detailsCenter" align="center"><html:radio
<td class="details"><bean:writ
<td class="details"><a href="/accntData.do"><bean
<td class="details"><bean:writ
<td class="details"><bean:writ
<td class="details"><bean:writ
<td class="details"><bean:writ
</tr>
</TABLE>
</logic:iterate>
</logic:present>
So I will use your code in action class like :
request.getParameterValues
Server in my IDE is still uninstalled, I'm just trying to work on the problem before the project initiation. Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
A checkbox fits here much better than a radio button.