簡體   English   中英

帶有圖像struts2的復選框

[英]Checkboxlist with image struts2

我將嘗試將圖像放在這樣的復選框列表中

<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">

但是我需要在一個字段中傳遞一個列表,以將其像“ true,false”一樣保存在數據庫中。

我會這樣嘗試

<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">'
                   }"

/>

但這不起作用。 救命

該錯誤可能在<img/>標記聲明中:當您打開第一個雙引號時 ,您正在關閉list屬性。

將它們放在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;>'
  }"
/>

我不確定Struts2是否會轉義這些值; 如果可以的話,唯一的機會就是擴展標簽。

要在一個字符串行中提交值,請在兩個復選框上使用相同的名稱,並且evento.eve_tarjeta_cred變量必須為字符串。 使用<label>標簽為復選框創建圖像標簽。

注意:未經檢查的復選框( 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>

我這樣解決了,在我的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">

在我的動作中,我聲明了帶有get和set的全局變量“ tarjetas”

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

並在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