简体   繁体   English

带有图像struts2的复选框

[英]Checkboxlist with image struts2

I'll try to put an image in my checkboxlist like this 我将尝试将图像放在这样的复选框列表中

<s:checkbox name="evento.eve_tarjeta_cred1" id="chkAmex" />
<img alt="10" src="./images/tarjetasCredito/amex.png">
<s:checkbox name="evento.eve_tarjeta_cred2" id="chkCmr" />
<img alt="10" src="./images/tarjetasCredito/cmr.png">

But i need to pass a list in one field to save it in my DB like "true,false". 但是我需要在一个字段中传递一个列表,以将其像“ true,false”一样保存在数据库中。

I'll try in this way 我会这样尝试

<s:checkboxlist id="chkTarjeta" name="evento.eve_tarjeta_cred" 
        list="{
            '<img alt="10" src="./images/tarjetasCredito/amex.png">',
            '<img alt="10" src="./images/tarjetasCredito/cmr.png">'
                   }"

/>

but it doesn't work. 但这不起作用。 HELP 救命

The error is probably in the <img/> tags declaration: when you open the first double quote , you are closing the list attribute. 该错误可能在<img/>标记声明中:当您打开第一个双引号时 ,您正在关闭list属性。

Put them in the Action (and read the values with a getter from the list attribute), or try escaping them manually; 将它们放在Action中(并从list属性中使用getter读取值),或尝试手动转义它们;

<s:checkboxlist id="chkTarjeta" name="evento.eve_tarjeta_cred" 
  list="{
    '<img alt=&quot;10&quot; src=&quot;./images/tarjetasCredito/amex.png&quot;>',
    '<img alt=&quot;10&quot; src=&quot;./images/tarjetasCredito/cmr.png&quot;>'
  }"
/>

I'm not sure if Struts2 will escape the values or not; 我不确定Struts2是否会转义这些值; if it will, the only chance would be to extend the Tag. 如果可以的话,唯一的机会就是扩展标签。

To submit values in one string line use the same names on both checkboxes and your evento.eve_tarjeta_cred variable must be a String. 要在一个字符串行中提交值,请在两个复选框上使用相同的名称,并且evento.eve_tarjeta_cred变量必须为字符串。 Use <label> tags to create labels of image for checkboxes. 使用<label>标签为复选框创建图像标签。

Note: that unchecked chekboxes ( false values) won't be submitted. 注意:未经检查的复选框( false值)将不会提交。

<label>
  <s:checkbox name="evento.eve_tarjeta_cred" id="chkAmex" />
  <img alt="10" src="./images/tarjetasCredito/amex.png" />
</label>

<label>
  <s:checkbox name="evento.eve_tarjeta_cred" id="chkCmr" />
  <img alt="10" src="./images/tarjetasCredito/cmr.png" />
</label>

I solved it like this, in my JSP i got this 我这样解决了,在我的JSP中我得到了

<s:checkbox name="t1" id="chkAmex" />
<img alt="10" src="./images/tarjetasCredito/amex.png">

<s:checkbox name="t2" id="chkCmr" />
<img alt="10" src="./images/tarjetasCredito/cmr.png">

and in my Action i declare a global variable "tarjetas", with get and set, obviously 在我的动作中,我声明了带有get和set的全局变量“ tarjetas”

tarjetas = t1 + "," + t2;
evento.setEve_tarjeta_cred(tarjetas);
eventoservice.RegistraEvento(evento);

and to show it in Update case, just do this 并在Update情况下显示它,只需执行此操作

String[] tarjetasArray = evento.getEve_tarjeta_cred().split(",");
            for (int i = 0; i < tarjetasArray.length; i++) {
                t1 = tarjetasArray[0];
                t2 = tarjetasArray[1];
            }

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

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