You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dean Pullen <de...@msp-uk.com> on 2007/08/30 17:48:26 UTC

Struts 2 Radio button - seperate value/label

Hi guys.

 

I can't work out via the Struts 2 documentation how to make a radio
button have a separate value and label from a given Map.

 

I'm trying:

<s:radio list="%{options}" name="questionOne"  theme="simple" />

 

Where 'options' is a HashMap<Integer, String>

 

What I get out on the JSP is one radio button only, with the following
text as the label:

{1=Yes, 2=No, 3=Maybe}

 

What I want is three radio buttons each with 1,2,3 as their values
respectively, and yes,no,maybe as their labels - retrieved from a Map.

 

How do I do this?

 

Thanks in advance.

 

 


RE: Struts 2 Radio button - seperate value/label

Posted by Dean Pullen <de...@msp-uk.com>.
Well as usual, although I spent a couple of hours trying to get it work,
as soon as I post to a mailing list I discover the answer....
So here is how I got it to work for future reference.

Created an Object like so:

public class RadioModel
{
	private int name;
	private String answer;

	public RadioModel()
	{
	}

	public RadioModel(int name, String answer)
	{
		this.name = name;
		this.answer = answer;
	}

	public int getName()
	{
		return name;
	}

	public void setName(int name)
	{
		this.name = name;
	}

	public String getAnswer()
	{
		return answer;
	}

	public void setAnswer(String answer)
	{
		this.answer = answer;
	}
}

Created a list of these:
List<RadioModel> options = new ArrayList<RadioModel>();
(then added the relevant values)

Then used this in the JSP:

<s:radio list="%{options}" listKey="name" listValue="answer"
name="question" theme="simple" />

Et voila.

-----Original Message-----
From: Dean Pullen [mailto:dean.pullen@msp-uk.com] 
Sent: 30 August 2007 16:48
To: user@struts.apache.org
Subject: Struts 2 Radio button - seperate value/label

Hi guys.

 

I can't work out via the Struts 2 documentation how to make a radio
button have a separate value and label from a given Map.

 

I'm trying:

<s:radio list="%{options}" name="questionOne"  theme="simple" />

 

Where 'options' is a HashMap<Integer, String>

 

What I get out on the JSP is one radio button only, with the following
text as the label:

{1=Yes, 2=No, 3=Maybe}

 

What I want is three radio buttons each with 1,2,3 as their values
respectively, and yes,no,maybe as their labels - retrieved from a Map.

 

How do I do this?

 

Thanks in advance.

 

 



Scanned by MailDefender - managed email security from intY -
www.maildefender.net

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org