wood burning stoves 2.0*
The moose likes Struts and the fly likes Iterate a bean object and show radio button on some condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Iterate a bean object and show radio button on some condition" Watch "Iterate a bean object and show radio button on some condition" New topic
Author

Iterate a bean object and show radio button on some condition

lokesh pushpa
Greenhorn

Joined: Nov 21, 2011
Posts: 23


Hi All ,

I have one Bean object and it contains no# fields(One of the field is Boolean) . I am iterating each field and printing those values in JSP. There are two radio button(need to be display in jsp) and those field would be checked/unchecked depending upon the Boolean value . Please help me in this .

DTO call is

class Service
{

private String serviceName;
private String serviceUrl;
private String serviceDescription;
private String serviceId;
private boolean enrolled;
}

And my Bean object is
ServiceBean {

// Variable used to store the Service
private Service[] serviceListArray;

//Variable used to store the Service List
private Service service;

// Setter and Getter methods

}

JSP cocde -

<logic:iterate id="service" indexId="index" name="serviceBean" property="serviceListArray">

// What should be be my code for radio button
</itearte>


Please help me in this
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

This is the second link when you Google for "jsp conditional"

Next time, please try to SearchFirst (<-- click)


Junilu - [How to Ask Questions] [How to Answer Questions]
lokesh pushpa
Greenhorn

Joined: Nov 21, 2011
Posts: 23
Junilu Lacar wrote:This is the second link when you Google for "jsp conditional"

Next time, please try to SearchFirst (<-- click)


Thanks Junilu for your quick respond,

But my requirement is some thing different .
I have one arrayList and it conatins one DTO object , I am doing iteration on that arrayList and i have to display the radio button.. using <html:radio >...

Please let me know if i am clearly posted the query
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

lokesh kumarputta wrote:
But my requirement is some thing different .
I have one arrayList and it conatins one DTO object , I am doing iteration on that arrayList and i have to display the radio button.. using <html:radio >...


1. A boolean is better represented by a checkbox (checked = true, unchecked = false). You can have a radio button group with two radio buttons for (Yes/No, True/False, Go/No go, Accept/Decline, etc...) but why take up more space than you need to?
2. Since you use the logic:iterate tag, it looks like you're using Struts, correct? Then read up on the Struts bean tags that render either checkboxes or radio buttons
3. One arraylist that contains one DTO is a very bad design that I have seen many times and I can't for the life of me understand why it comes up as often as it does in code. In Struts, you should just use an ActionForm (Struts1) or an extension of ActionSupport (Struts2). Do you have only one DTO? If so, then why are you putting it into an ArrayList? And why ArrayList specifically instead of a List (you should always prefer to program to interfaces, not concrete implementations).
4. The Struts Tags documentation should have some examples of how your rendered checkbox or radio buttons can have a preselected state based on the values in a bean.
lokesh pushpa
Greenhorn

Joined: Nov 21, 2011
Posts: 23
Junilu Lacar wrote:
lokesh kumarputta wrote:
But my requirement is some thing different .
I have one arrayList and it conatins one DTO object , I am doing iteration on that arrayList and i have to display the radio button.. using <html:radio >...


1. A boolean is better represented by a checkbox (checked = true, unchecked = false). You can have a radio button group with two radio buttons for (Yes/No, True/False, Go/No go, Accept/Decline, etc...) but why take up more space than you need to?
2. Since you use the logic:iterate tag, it looks like you're using Struts, correct? Then read up on the Struts bean tags that render either checkboxes or radio buttons
3. One arraylist that contains one DTO is a very bad design that I have seen many times and I can't for the life of me understand why it comes up as often as it does in code. In Struts, you should just use an ActionForm (Struts1) or an extension of ActionSupport (Struts2). Do you have only one DTO? If so, then why are you putting it into an ArrayList? And why ArrayList specifically instead of a List (you should always prefer to program to interfaces, not concrete implementations).
4. The Struts Tags documentation should have some examples of how your rendered checkbox or radio buttons can have a preselected state based on the values in a bean.



Hi Junilu , Please find my comments

1. COuld you please elaborate lil bit more in first point
2.Yes i am using struts 1.2
3. That arrayList contains number of DTOs.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Hi Lokesh,

If you had caught me at some other time, I might go into more detail or even go into a mini-tutorial. As it is, I'm on vacation right now (I'm just waiting for everyone else here to wake up and get ready to head out) so I'm going to ask you to ShowSomeEffort first and read up on the documentation available for Struts.
lokesh pushpa
Greenhorn

Joined: Nov 21, 2011
Posts: 23
Junilu Lacar wrote:Hi Lokesh,

If you had caught me at some other time, I might go into more detail or even go into a mini-tutorial. As it is, I'm on vacation right now (I'm just waiting for everyone else here to wake up and get ready to head out) so I'm going to ask you to ShowSomeEffort first and read up on the documentation available for Struts.


Thanks Junilu , Here it goes

<c:choose>
<c:when test="${isEnrolled}">
<html:radio property="enrolled" value="true" name="service"/>Yes
<html:radio property="enrolled" value="false" name="service"/>No
</c:when>
<c:otherwise>
<html:radio property="enrolled" value="false" name="service"/>Yes
<html:radio property="enrolled" value="true" name="service"/>No

</c:otherwise>
</c:choose>
 
Don't get me started about those stupid light bulbs.
 
subject: Iterate a bean object and show radio button on some condition
 
Similar Threads
How to keep selected radio button after page refresh
using html:radio
Enable dynamic inputText
Showing the first record by press a button
Please help me regarding the forms selection