简体   繁体   English

使<s:checkboxlist>的选项在struts2中垂直显示

[英]Making the options of a <s:checkboxlist> display vertically in struts2

*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 folder with name vertical-checkbox containing the modified .ftl file of my customized check box list.I am unable to display the customized check box My code in JSP is *我需要我的复选框列表选项垂直显示而不是默认的水平显示。我在名称模板的src文件夹中创建了一个文件夹,另一个名为vertical-checkbox的文件夹包含我自定义复选框的修改后的.ftl文件list.I我无法显示自定义复选框我在JSP中的代码是

  <s:checkboxlist theme="vertical-checkbox" label="Which of the following are states of India"
                            name="states"
                                list="#{'01':'January','02':'February','03':'March','04':'April',
    '05':'May'}"
      />

Please advice where I am getting wrong. 请告诉我出错的地方。

Normally the struts checkboxlist in struts2 diaply the check boxes horizontally. 通常,struts2中的struts checkboxlist会水平显示复选框。 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 为了将其对齐为垂直,我们必须执行以下操作

  1. You have to create a directory template in your src folder 您必须在src文件夹中创建目录模板

  2. Create a folder with the name of the template you want to create (vertical-checkbox) 创建一个文件夹,其中包含您要创建的模板的名称(vertical-checkbox)

  3. 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. 将struts-2.1.6 / src / core / src / main / resources / template / simple / checkboxlist.ftl文件复制到此目录中此文件的内容如下。 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 标签你想要或喜欢这个链接: http//codeglobe.blogspot.com/2009/09/struts2-align-check-box-vertical.html

  4. <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. 唯一的区别是,您必须在此处指定主题,该主题与您在项目的src文件夹中的模板目录中创建的目录相同。

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: 所以,我通过css做到了:

<s:checkboxlist
  name="myCheckboxList"
  ... />

which results in html-elements like this: 这导致像这样的html元素:

<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: 使复选框垂直的CSS看起来像这样:

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". 选择器声明“在每个带有包含'myCheckboxList-'的for-属性的标签之后,并且内容状态”添加换行符(“\\ A”)并确保保留空格“。

You can see here: http://klyuty.blogspot.it/2011/03/creating-vertical-orientation-for.html I think this is the simplest and clear way. 你可以在这里看到: http//klyuty.blogspot.it/2011/03/creating-vertical-orientation-for.html我认为这是最简单明了的方法。

  1. Create folder template in WEB-INF/classes folder of application. 在应用程序的WEB-INF / classes文件夹中创建文件夹模板。
  2. Create folder simple in WEB-INF/classes/template folder (or another folder for other theme). 在WEB-INF / classes / template文件夹(或其他主题的其他文件夹)中创建简单文件夹。
  3. Copy file checkboxlist.ftl from struts2-core.jar library (that one, with located in simple theme folder in jar archive). 从struts2-core.jar库复制文件checkboxlist.ftl(那个,位于jar存档中的简单主题文件夹中)。
  4. In this file after the closing of this label string (see the link for more detail): 在关闭此标签字符串后的此文件中(有关详细信息,请参阅链接):
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 在这段代码中,“vertical”是css样式,我们将在strust2页面中使用,并且
is a separator between two checkboxes in our list. 是列表中两个复选框之间的分隔符。

  1. On struts2 page with s:checkboxlist use style "vertical" for make a vertical list orientation: 在带有s:checkboxlist的struts2页面上,使用样式“vertical”来制作垂直列表方向:

see this website: http://mikeski.net/site/node/16 看到这个网站: http//mikeski.net/site/node/16

basically, you just need to: 基本上,你只需要:

  1. open up the file checkboxlist.ftl 打开文件checkboxlist.ftl
  2. it will contain 3 lines, the middle line uses the checkboxlist.ftl from the simple theme. 它将包含3行,中间行使用简单主题中的checkboxlist.ftl。 Comment the line that says: 评论说:

     <#include "/${parameters.templateDir}/simple/checkboxlist.ftl" /> 
  3. Then copy the freemarker code that is referenced in the above URL. 然后复制上述URL中引用的freemarker代码。

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: 如果没有看到修改后的.ftl文件,很难说出问题所在,但一般的解决方案是:

  • Copy checkboxlist.ftl over to a new directory (eg, .../template) 将checkboxlist.ftl复制到新目录(例如,... / template)
  • In the copied file, add a break between the checkboxLabel class and the iterator: 在复制的文件中,在checkboxLabel类和迭代器之间添加一个中断:

     <label ... class="checkboxLabel"> <br> </@s.iterator> 
  • Reference/include the new .../template/checkboxlist.ftl to override the standard checkboxlist.ftl. 引用/包含新的... / template / checkboxlist.ftl以覆盖标准的checkboxlist.ftl。

If I recall correctly the above can also be done in CSS, but I forgot the details. 如果我没记错,以上也可以在CSS中完成,但我忘记了细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM