This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Struts and the fly likes Displaying radio button in <tr> (Next Line) in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Displaying radio button in <tr> (Next Line) in Struts 2" Watch "Displaying radio button in <tr> (Next Line) in Struts 2" New topic

Displaying radio button in <tr> (Next Line) in Struts 2

Abdul Mujeeb Md

Joined: Aug 25, 2008
Posts: 26

How do we display the Radio buttons aligned vertically using Struts 2 Tag. The default implementation populates it in a horizontal format.

Ajit Amitav Das
Ranch Hand

Joined: Dec 14, 2005
Posts: 49
Struts2 uses FTL (freemarker template) internally to render components.

In your case for radio buttons it uses "radiomap.ftl" for generating the HTML code.

This file will be present in struts default jar file, extract this file and modify accordingly as per your customization put a break tag after each iteration of the collection items.

Create a folder named as theme under your webapp project and create a folder named as XYZ(example : radiovertical) under that theme folder and put your modifed radiomap.ftl file under XYZ folder.

radiomap.ftl is a big file to mention so just putting code snippet how to do this: modifed code are mentioned in bold font.

<@s.iterator value="parameters.list">
<#if parameters.listKey??>
<#assign itemKey = stack.findValue(parameters.listKey)/>

// rest of the code which I have deleted for wrapping it in a small conversation.

<label for="${}${itemKeyStr?html}"><#rt/>
<br /><br />

After all these changes use your theme (XYZ ) for struts radio tag as follows:

<s:radio theme="radioVertical" of the things here />

This will create each item in a new line.

Hope this will give you some valid information and technique to use/customize struts tag.

Warm Regards<br />Ajit Amitav Das<br />SCJP 1.5
Abdul Mujeeb Md

Joined: Aug 25, 2008
Posts: 26
Thanks Ajit. That works
John Sears

Joined: Sep 15, 2009
Posts: 14
Hmmm I ran into this problem too. Is there no way to do it declaratively without creating additional file structure? Ideally there ought to be an easier way to get vertical radio lists...
I agree. Here's the link:
subject: Displaying radio button in <tr> (Next Line) in Struts 2