*I need my check box list option to display vertically instead of the default horizontal display.I have created a folder in my src folder in the name templates and another f
see this website: http://mikeski.net/site/node/16
basically, you just need to:
it will contain 3 lines, the middle line uses the checkboxlist.ftl from the simple theme. Comment the line that says:
<#include "/${parameters.templateDir}/simple/checkboxlist.ftl" />
Then copy the freemarker code that is referenced in the above URL.
I did that, and it worked for me. It will display your checkbox on its own individual line.
Without seeing the modified .ftl file it's difficult to tell where things go wrong, but the general solution is:
In the copied file, add a break between the checkboxLabel class and the iterator:
<label ... class="checkboxLabel">
<br>
</@s.iterator>
Reference/include the new .../template/checkboxlist.ftl to override the standard checkboxlist.ftl.
If I recall correctly the above can also be done in CSS, but I forgot the details.
I tried the answer supplied here, but it did not work as I'd hoped, I lost the label on the list, and also other formatting disappeared. So, I did it through css:
<s:checkboxlist
name="myCheckboxList"
... />
which results in html-elements like this:
<input type="checkbox" id="myCheckboxList-1" ... />
<label for="myCheckboxList-1" ...
<input type="checkbox" id="myCheckboxList-2" ... />
<label for="myCheckboxList-2" ...
The CSS for making the checkboxes vertical then looks like this:
label[for*=myCheckboxList-]:after {
content:"\A"; white-space:pre;
}
The selector states that "after each label with a for-attribute containing 'myCheckboxList-'", and the contents state "add a linebreak ("\A") and make sure that whitespaces are preserved".
Normally the struts checkboxlist in struts2 diaply the check boxes horizontally. In most of application we want to display the check boxes vertically (line by line). For aligning this as vertical we have to do the following
You have to create a directory template in your src folder
Create a folder with the name of the template you want to create (vertical-checkbox)
Copy the struts-2.1.6/src/core/src/main/resources/template/simple/checkboxlist.ftl file to this directory content of this file is as follows. Before the you have to put a
tag as you want or like this link:
http://codeglobe.blogspot.com/2009/09/struts2-align-check-box-vertical.html
<s:checkboxlist list="urlist" name="selectedValues" listKey="id" listValue="descrption" theme="vertical-checkbox"></s:checkboxlist>
This will give you a vertical check box list. The only difference is that here you have to specify the theme which is same as the directory you have created in the template directory in the src folder of your project.
You can see here: http://klyuty.blogspot.it/2011/03/creating-vertical-orientation-for.html I think this is the simplest and clear way.
for="${parameters.name?html}-${itemCount}" class="checkboxLabel">${itemValue?html}
and before string:
</@s.iterator>
add this (in between):
<#if parameters.cssStyle?exists>
<#if "${parameters.cssStyle?html}" == "vertical">
<br/><#rt/>
</#if>
</#if>
In this code "vertical" is css style, that we will use in strust2 page, and
is a separator between two checkboxes in our list.
On struts2 page with s:checkboxlist use style "vertical" for make a vertical list orientation: