aspose file tools*
The moose likes Struts and the fly likes Radio button issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Radio button issue" Watch "Radio button issue" New topic
Author

Radio button issue

shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
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">
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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


Merrill
Consultant, Sima Solutions
shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Jan 04, 2007
Posts: 124
<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

Joined: Feb 15, 2005
Posts: 4864
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Radio button issue
 
Similar Threads
Question on dynamically generated radio buttons
help with radio buttons
Radio Button values
Redrawing the UI
How to disable html:checkbox based on html:radio selection