簡體   English   中英

從jsp到struts2動作類獲取禁用的真實數據

[英]getting disabled true data from jsp to struts2 action class

我在我的jsp中有disabled=true文本框和combox框。

當我嘗試將這些值映射回行動時,它們就消失了。

我不想再次打電話給DB了。

如何將這些disabled=true textboxescombo boxes的數據值設置為hidden values

謝謝你。

禁用元素的值不與表單一起提交的屬性不是struts2的問題,而是HTML行為。 要處理此行為,請使用以下實現:

  1. 使用readonly =“readonly”屬性來防止修改而不是使用禁用。 (這不適用於少數元素)
  2. 使用onfocus =“return false”可以防止任何對html元素的關注。 這樣可以防止修改它們的價值。 您可以使用CSS使這些元素看起來像只讀或禁用。
  3. 在禁用元素之前,請創建一個隱藏元素並附加要禁用的元素的值。 這將確保項目被提交。

有關select元素,請參閱以下實現。 您可以使用s:select的id屬性來設置select元素的html id。

<select id="demoSelect" class="readonly">
    <option value="0">A</option>
    <option value="1">B</option>
    <option value="2" selected="selected">C</option>
    <option value="3">D</option>
    <option value="4">E</option>
    <option value="5">F</option>
</select>
<input type="hidden" value="2" name="demoSelectDefault"/>

jQuery的:

$(document).ready(

    function() {
        $("select.readonly").live('change', function() { //live() makes sure that this is executed if you apply the class to the element even after the initial load. So, if you set the readonly class to a select element, you are done.
            var selectElement = this;       
            $("input[type=hidden][name=" + this.id + "Default]").each( //This is implemented in case of multiple select support. You will need to select nothing at first and then make this select each of this element
                function() {
                    selectElement.value = this.value;
                }
            );

        });
    }

);

這里,當你使用struts實現它時,填充s:select,然后使用s:hidden元素生成相應的默認值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM