Struts2 select標籤 設定Class屬性產生的html代碼中select沒有class屬性問題

來源:互聯網
上載者:User

是因為struts2中select標籤沒有class這項,代替的是使用cssClass項目,例如:

<s:select cssClass=“left”  list=”myselectList” name=”selectName” id=”selectId” value=”selectValue”>

其實看struts2的源碼就會發現struts2產生select標籤時不會去取名為class的參數,而是去取名為cssClass的參數來產生class="?"。

struts2中select標籤,首先list屬性是必選的,是下拉式清單的值,一般情況下是一個list

其中value屬性代表是option的值,一般情況下是list的對象的一個屬性值,

headerKey,headerValue是第一下拉式功能表的顯示名稱和值

cssClass:等效於<select class=”dd”>

cssStyle:等效與<select style=”width:190px”>

size代表下拉帶菜單的顯示的條數,預設是1

但是Struts2 checkboxlist設定cssClass屬性標籤也是沒用的,還是要看源碼就能明白:

開啟checkboxlist.ftl看,內容如下: 

    <input type="checkbox" name="${parameters.name?html}" value="${itemKeyStr?html}" id="${parameters.name?html}-${itemCount}"<#rt/>  

            <#if tag.contains(parameters.nameValue, itemKey)>  

     checked="checked"<#rt/>  

            </#if>  

            <#if parameters.disabled?default(false)>  

     disabled="disabled"<#rt/>  

            </#if>  

            <#if parameters.title??>  

     title="${parameters.title?html}"<#rt/>  

            </#if>  

            <#include "/${parameters.templateDir}/simple/scripting-events.ftl" />  

            <#include "/${parameters.templateDir}/simple/common-attributes.ftl" />  

    /> 

根本沒有cssClass參數進行設定。 

  添加下面的內容,在替換struts2包中的  checkboxlist.ftl 檔案就可以了: 

<#if parameters.cssClass??>     

     class="${parameters.cssClass?html}"<#rt/>     

</#if>

  完整的ftl檔案如下: 

    <#assign itemCount = 0/>  

    <#if parameters.list??>  

        <@s.iterator value="parameters.list">  

            <#assign itemCountitemCount = itemCount + 1/>  

            <#if parameters.listKey??>  

                <#assign itemKey = stack.findValue(parameters.listKey)/>  

            <#else>  

                <#assign itemKey = stack.findValue('top')/>  

            </#if>  

            <#if parameters.listValue??>  

                <#assign itemValue = stack.findString(parameters.listValue)?default("")/>  

            <#else>  

                <#assign itemValue = stack.findString('top')/>  

            </#if>  

    <#assign itemKeyitemKeyStr=itemKey.toString() />  

    <input type="checkbox" name="${parameters.name?html}" value="${itemKeyStr?html}" id="${parameters.name?html}-${itemCount}"<#rt/>  

            <#if tag.contains(parameters.nameValue, itemKey)>  

     checked="checked"<#rt/>  

            </#if>  

            <#if parameters.disabled?default(false)>  

     disabled="disabled"<#rt/>  

            </#if>  

            <#if parameters.title??>  

     title="${parameters.title?html}"<#rt/>  

            </#if>  

            <#if parameters.cssClass??>     

            class="${parameters.cssClass?html}"<#rt/>     

            </#if>     

            <#include "/${parameters.templateDir}/simple/scripting-events.ftl" />  

            <#include "/${parameters.templateDir}/simple/common-attributes.ftl" />  

    />  

    <label for="${parameters.name?html}-${itemCount}" class="checkboxLabel">${itemValue?html}</label>  

        </@s.iterator>  

    <#else>  

         

    </#if>  

    <input type="hidden" id="__multiselect_${parameters.id?html}" name="__multiselect_${parameters.name?html}" value=""<#rt/>  

    <#if parameters.disabled?default(false)>  

     disabled="disabled"<#rt/>  

    </#if>  

     />  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.