繁体   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