Hi here is another question:
I searched the internet for information about the radio tag, and this is all I found so I put it in my code

<s:radio name="..." list="myArray"  />

The above displays all the elements of the array with radio buttons. My problem is that they are not being aligned when they are displayed.

This is my problem:
I have an iterator and a list with objects:

<s:iterator value="listOfObjects">
  <s:property="property_1">
  <s:property="property_2">
  <s:property="property_3">
   
<code to be added />
</s:iterator>

The above creates a table and each row has the properties of each object in the list. I want each row, to have a radio button at the last column. All the radio buttons will have the Same name and value will be one of the properties of the object in each line. But I cannot use the struts 2 radio tag: <s:radio name="..." list="myArray" /> If I write this:

<s:iterator value="listOfObjects">
  <s:property="code">
  ................
  <s:radio name="selectedCode" list="myArray"  />
</s:iterator>

In each row I will have all the elements of the array.
I now how to do this using for-loop and simple html radio tag. Also I know how to do it with Struts 1 radio button tag. If I remember correctly you can iterate and create in each row a single radio button and take the values from the object your are iterating.

But in Struts 2 the "list" attribute is mandatory in the radio tag. So I cannot create a single radio button and I don't know how to iterate the "listOfObjects" in order to create a single radio button in each row.
The tag: <s:radio name="..." list="myArray" /> put all the radios in One table cell.

If you understand my problem any help will be appreciated

Ok I have managed to solve this one too:

I was using this:

<s:iterator value="listOfObjects">
  <s:property="code">
  ................
  <s:radio name="selectedCode" list="listOfObjects"  />
</s:iterator>

The above created a list of radios in each line:

Instead this was needed:

<s:iterator value="listOfObjects">
  <s:property="code">
  ................
  <s:radio name="selectedCode" list="{code}"  />
</s:iterator>

With the above I declare ONE sinlge radio, so as the iterator progresses each line has 1 radio. As for the value of the radio I took this example: http://struts.apache.org/2.x/docs/how-do-i-render-a-single-radio-button.html

commented: Nicely done +12

Radios en diferente línea
Ésto es fácil pero a mi me tomo tiempo averiguarlo. Pondré la solución esperando alguien encuentre éste tema para resolver sus dudas.


1. Crea las siguientes carpetas en el directorio WEB-INF/classes/template
1. Create the following folders into the directory WEB-INF as follow WEB-INF/classes/template

2. Ahora crea una carpeta con el nombre de tu tema que podría ser "radiovertical" y quedaría de la siguiente manera: WEB-INF/classes/template/radiovertical
2. Create a folder called "verticalradio" like this WEB-INF/classes/template/verticalradio

3. En la carpeta "rediovertical" crea un archivo llamado theme.properties y dentro del archivo colocas la siguiente línea: parent=simple
3. Into the folder "verticalradio" create a file called theme.properties and put into it thene next line: parent=simple

4. Copia el archivo "radiomap.ftl" del archivo .jar struts2-core.jar. El archivo .ftl debe estar en el siguiente directorio dentro del .jar/template/simple/radiomap.ftl
4. Copy the "radiomap.ftl" file inside the struts2-core.jar file. The .ftl file should be in the directory struts2-core.jar/template/simple/radiomap.ftl

5. Copia el archivo en tu carpeta WEB-INF/classes/template/radiovertical
5. Copy radiomap.ftl file to WEB-INF/classes/template/verticalradio

6. Abre el archivo y busca la siguiente linea: <input type="radio"<#rt/>
6. Open the radiomap.ftl file and search this line: <input type="radio"<#rt/>

7. Ahora reemplaza la línea:<input type="radio"<#rt/> por <br><input type="radio"<#rt/>
7. Replace the line: <input type="radio"<#rt/> with : <br><input type="radio"<#rt/>


8. Para hacer uso del tema "radiovertical" sólo tienes que poner tu radio en la página .jsp como ssigue <s:radio theme="radiovertical" list="bla bla" etc etc></s:radio>
8. Now in your .jsp page you have to put the struts2 radio tag like this
<s:radio theme="verticalradio" list="yourlist"></s:radio>

thats all.

1) This is a 5 month old thread.
2) This thread is marked as solved. I have already found and written the solution, that does what you are trying to describe. Also, since then I have become a lot better in Struts 2 to require any help.
3) Also using <br> to do the formatting isn't a very good solution. It is better to use <div> or at least a <table><tr><td>
4) Write things only in English. No one is going to bother to "read between the lines" and find where the English are

javaAddict,
you are so good in Struts 2 now that you don't need any help except that you solution does not work since <s:property="code">
is syntaxically incorrect...
Johnxjean took the time to translate probably something he found in spanigh ont he web, so nice of you to thank him as you did. Modesty will certainly not kill you...

javaAddict,
you are so good in Struts 2 now that you don't need any help except that you solution does not work since <s:property="code">
is syntaxically incorrect...
Johnxjean took the time to translate probably something he found in spanigh ont he web, so nice of you to thank him as you did. Modesty will certainly not kill you...

After 9 months I assure you I found the solution. And the code is correct because a) It runs and b) because I am not going to post the entire jsp of hundreds of lines, nor it is necessary to post the exact variable names. The part I posted was sufficient for someone who knows to be able to pick it up. It was an example of how I get it to work. I am not going to post the exact code that I developed for my company
And:
As I stated the solution was found and I don't believe that what you posted was any bit constructive.

Radios en diferente línea
Ésto es fácil pero a mi me tomo tiempo averiguarlo. Pondré la solución esperando alguien encuentre éste tema para resolver sus dudas.


1. Crea las siguientes carpetas en el directorio WEB-INF/classes/template
1. Create the following folders into the directory WEB-INF as follow WEB-INF/classes/template

2. Ahora crea una carpeta con el nombre de tu tema que podría ser "radiovertical" y quedaría de la siguiente manera: WEB-INF/classes/template/radiovertical
2. Create a folder called "verticalradio" like this WEB-INF/classes/template/verticalradio

3. En la carpeta "rediovertical" crea un archivo llamado theme.properties y dentro del archivo colocas la siguiente línea: parent=simple
3. Into the folder "verticalradio" create a file called theme.properties and put into it thene next line: parent=simple

4. Copia el archivo "radiomap.ftl" del archivo .jar struts2-core.jar. El archivo .ftl debe estar en el siguiente directorio dentro del .jar/template/simple/radiomap.ftl
4. Copy the "radiomap.ftl" file inside the struts2-core.jar file. The .ftl file should be in the directory struts2-core.jar/template/simple/radiomap.ftl

5. Copia el archivo en tu carpeta WEB-INF/classes/template/radiovertical
5. Copy radiomap.ftl file to WEB-INF/classes/template/verticalradio

6. Abre el archivo y busca la siguiente linea: <input type="radio"<#rt/>
6. Open the radiomap.ftl file and search this line: <input type="radio"<#rt/>

7. Ahora reemplaza la línea:<input type="radio"<#rt/> por <br><input type="radio"<#rt/>
7. Replace the line: <input type="radio"<#rt/> with : <br><input type="radio"<#rt/>


8. Para hacer uso del tema "radiovertical" sólo tienes que poner tu radio en la página .jsp como ssigue <s:radio theme="radiovertical" list="bla bla" etc etc></s:radio>
8. Now in your .jsp page you have to put the struts2 radio tag like this
<s:radio theme="verticalradio" list="yourlist"></s:radio>

thats all.

Appreciate the translation, the steps are very intuitive.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.