File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterate a bean object and show radio button on some condition

 
lokesh pushpa
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the second link when you Google for "jsp conditional"

Next time, please try to SearchFirst (<-- click)
 
lokesh pushpa
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic