<i id='7iC16'><tr id='7iC16'><dt id='7iC16'><q id='7iC16'><span id='7iC16'><b id='7iC16'><form id='7iC16'><ins id='7iC16'></ins><ul id='7iC16'></ul><sub id='7iC16'></sub></form><legend id='7iC16'></legend><bdo id='7iC16'><pre id='7iC16'><center id='7iC16'></center></pre></bdo></b><th id='7iC16'></th></span></q></dt></tr></i><div id='7iC16'><tfoot id='7iC16'></tfoot><dl id='7iC16'><fieldset id='7iC16'></fieldset></dl></div>
  • <legend id='7iC16'><style id='7iC16'><dir id='7iC16'><q id='7iC16'></q></dir></style></legend>
    1. <tfoot id='7iC16'></tfoot>

      <small id='7iC16'></small><noframes id='7iC16'>

          <bdo id='7iC16'></bdo><ul id='7iC16'></ul>
      1. 如何在 Struts2 中获取特定的未选中复选框

        How to get the specifc unchecked checkboxes in Struts2(如何在 Struts2 中获取特定的未选中复选框)
          <tbody id='SVWTY'></tbody>

          <i id='SVWTY'><tr id='SVWTY'><dt id='SVWTY'><q id='SVWTY'><span id='SVWTY'><b id='SVWTY'><form id='SVWTY'><ins id='SVWTY'></ins><ul id='SVWTY'></ul><sub id='SVWTY'></sub></form><legend id='SVWTY'></legend><bdo id='SVWTY'><pre id='SVWTY'><center id='SVWTY'></center></pre></bdo></b><th id='SVWTY'></th></span></q></dt></tr></i><div id='SVWTY'><tfoot id='SVWTY'></tfoot><dl id='SVWTY'><fieldset id='SVWTY'></fieldset></dl></div>

            <legend id='SVWTY'><style id='SVWTY'><dir id='SVWTY'><q id='SVWTY'></q></dir></style></legend>

              <small id='SVWTY'></small><noframes id='SVWTY'>

            • <tfoot id='SVWTY'></tfoot>

              • <bdo id='SVWTY'></bdo><ul id='SVWTY'></ul>
                1. 本文介绍了如何在 Struts2 中获取特定的未选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我在某些特定操作上打印了一些文档以及一些复选框(默认情况下,当页面加载时,某些复选框会被选中).

                  In my application I am printing some document along with some checkboxes (Some checkboxes get checked by default when page loads) on some specific action.

                  现在用户将选中一些复选框或取消选中一些.并点击更新按钮.

                  Now user will Check some checkboxes Or may uncheck some. And clicks on update button.

                  现在我的要求是我想要未选中的复选框值.

                  例如:

                  当页面第一次加载时,有 5 个复选框被选中大约 700 个复选框中的默认值;

                  When the page loads first time there are 5 checkboxes checked by default out of some 700 check boxes;

                  现在用户将取消选中 2 个复选框并单击提交.

                  now user will uncheck 2 checkboxes and clicks on submit.

                  我的要求在这里 我想要那 2 个我的操作类中未选中的复选框值.

                  My requirement is here I want those 2 unchecked checkboxes values in my action class.

                  我正在使用 Struts2 打印这些文档.我正在使用 Struts2-jQgrid,我尝试使用 Struts2 CheckboxInterceptor 来获取未选中的复选框,但它给了我所有未选中的复选框,而不仅仅是所需的复选框(改变状态的复选框).p>

                  I am using Struts2 to print those documents. I'm using Struts2-jQgrid, I have tried Struts2 CheckboxInterceptor to get the unchecked ones but it's giving me all the unchecked checkboxes, not only the desired ones (the ones that changed their state).

                  推荐答案

                  假设您从迭代自定义对象列表开始,

                  Assuming you start by iterating a List of custom objects,

                  private List<MyCustomObject> myList;
                  

                  并且您的自定义对象具有例如.boolean isChecked()String getValue() 方法,

                  and that your custom object has eg. boolean isChecked() and String getValue() methods,

                  您可以在目标操作中使用两个不同的列表:一个用于未选中但现在已选中的项目,另一个用于已选中但现在未选中的项目强>:

                  you could use two different Lists in the destination Action: one for the items that were unchecked and now are checked, and another one for items that were checked and now are unchecked:

                  private List<String> itemsThatHaveBeenChecked;
                  private List<String> itemsThatHaveBeenUnchecked;
                  

                  然后在页面中,您应该使用经典复选框来获取选中项,并使用隐藏输入来存储未选中项的值,使用 javascript 激活其值,与复选框值相反(必须没有名称):

                  then in the page you should use a classic checkbox to get the checked items, and an hidden input to store the value of the unchecked items, activating its value with javascript as opposite to the checkbox value (that must have no name):

                  <s:iterator value="myList" status="ctr">
                      <s:if test="!isChecked()">
                          <!-- I'm not checked, need to catch only if I will be checked -->
                          <s:checkbox id = "checkbox_%{#ctr.index}" 
                              fieldValue = "%{getValue()}"
                                   value = "false" 
                                    name = "itemsThatHaveBeenChecked" />
                      </s:if>
                      <s:else>
                          <!-- I'm checked, need to catch only if I will be unchecked -->
                          <input type = "checkbox" 
                                   id = "<s:property value="%{'checkbox_'+#ctr.index}"/>"
                              checked = "checked"
                                class = "startedChecked" />
                          <!-- hidden trick -->
                          <input type = "hidden" 
                                   id = "hidden_<s:property value="%{'checkbox_'+#ctr.index}"/>" 
                                value = "<s:property value="%{getValue()}"/>"         
                                 name = "itemsThatHaveBeenUnchecked" 
                             disabled = "disabled" />            
                      </s:else> 
                  </s:iterator>
                  
                  <script>
                      /* Enable the hidden field when checkbox is unchecked, 
                        Disable the hidden field when checkbox is checked    */
                      $(function() {
                          $("input[type='checkbox'].startedChecked").change(function () {
                              $("#hidden_"+this.id).prop({disabled : this.checked});
                          });
                      });
                  </script>
                  

                  这样您将只获得两个列表中所需的值.

                  This way you will get only the values needed in both Lists.

                  这篇关于如何在 Struts2 中获取特定的未选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What are valid deviceNames for Chrome emulation testing with Protractor?(使用 Protractor 进行 Chrome 模拟测试的有效设备名称是什么?)
                  Protractor Check if Element Does Not Exist(量角器检查元素是否不存在)
                  Protractor e2e Tests Login Redirection(Protractor e2e 测试登录重定向)
                  Explain about async/ await in Protractor(解释 Protractor 中的 async/await)
                  Protractor browser.wait doesn#39;t wait(量角器 browser.wait 不等待)
                  How to use Protractor with Angular 2?(如何在 Angular 2 中使用量角器?)

                  <small id='1WclS'></small><noframes id='1WclS'>

                    <tbody id='1WclS'></tbody>
                      <bdo id='1WclS'></bdo><ul id='1WclS'></ul>
                        <legend id='1WclS'><style id='1WclS'><dir id='1WclS'><q id='1WclS'></q></dir></style></legend>
                        <i id='1WclS'><tr id='1WclS'><dt id='1WclS'><q id='1WclS'><span id='1WclS'><b id='1WclS'><form id='1WclS'><ins id='1WclS'></ins><ul id='1WclS'></ul><sub id='1WclS'></sub></form><legend id='1WclS'></legend><bdo id='1WclS'><pre id='1WclS'><center id='1WclS'></center></pre></bdo></b><th id='1WclS'></th></span></q></dt></tr></i><div id='1WclS'><tfoot id='1WclS'></tfoot><dl id='1WclS'><fieldset id='1WclS'></fieldset></dl></div>

                          1. <tfoot id='1WclS'></tfoot>