• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Radio button issue

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a screen and one of the element looks like this


excellent,good,poor
Rating_criteria1 - 3 radio buttons
Rating_criteria2 - 3 radio buttons

User can choose one value for each rating(ie either excellent/good/poor).?

Should I create for each rating criteria a variable or it can be done in a better way?


Below is how my screen looks like

Rating_criteria1
<html:radio property="rc_1" value="1">
<html:radio property="rc_1" value="2">
<html:radio property="rc_1" value="3">

Rating_criteria2
<html:radio property="rc_2" value="1">
<html:radio property="rc_2" value="2">
<html:radio property="rc_2" value="3">
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you had 10 or 15 of these, I'd say using <logic:iterate> and indexed properties would be a better solution. However, with only two of them, I'd say your solution is the best one. It really isn't worth complicating your process with indexed properties for only two elements.

If you're interested in learning more about indexed properties, see the entry for it in the JavaRanch Struts FAQ
 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having 7 rating criteria, so i feel indexed property is the best way. I did not find any link for index properties. can you please provide me a sample link.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the link:

http://faq.javaranch.com/view?IndexedProperties

You can also search this forum on this topic, and you will find many threads discussing it.
[ February 26, 2007: Message edited by: Merrill Higginson ]
 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<form-property name="choices" type="com.company.Choices" />

com.company.Choices.java
public class Choices {
private String var_choices[] = {"1","2","3","4"};


public String[] getChoices() {
return choices;
}

public void setChoices( String [] choices) {
this.choices = choices;
}
}

inside my jsp

<%
Choices objChoices = new Choices ()
String choices [] = (String [])objChoices .getChoices();
%>

<tr>
<td>Rating Criterai 1</td>

<%for(int i = 0; i < choices.length; i++ ) { %>
<td>
<html:radio property="choices" value="<%=choices[i]%>" /></td>
<%} %>

</tr>


<tr>

<td>Rating Criterai 2</td>

<%for(int i = 0; i < choices.length; i++ ) { %>
<td>
<html:radio property="choices" value="<%=choices[i]%>" /></td>
<%} %>

</tr>

I get the radiobuttons but I want only one radio to be selected for each row . How do I dynamically change the property value. I am really confused.
PLs help


Excellent Good Fair Poor
RatingCriteria1
RatingCriteria2
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main mistake in the above code is that you are confusing the array of available options (1, 2, 3, 4, 5) with the array of options actually selected by one of the radio buttons, which should be the criteria selection, which is, from what you've said, an array of seven different values.

The Choices bean isn't really doing anything, so I'd suggest you just get rid of it. Below is a simple example:
Struts-config.xml

Action class

JSP

[ February 26, 2007: Message edited by: Merrill Higginson ]
reply
    Bookmark Topic Watch Topic
  • New Topic