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

      1. <tfoot id='BNxLW'></tfoot>
        <legend id='BNxLW'><style id='BNxLW'><dir id='BNxLW'><q id='BNxLW'></q></dir></style></legend>

        Struts 2 s:select tag 动态id

        Struts 2 s:select tag dynamic id(Struts 2 s:select tag 动态id)

        <tfoot id='TMgd6'></tfoot>
      2. <legend id='TMgd6'><style id='TMgd6'><dir id='TMgd6'><q id='TMgd6'></q></dir></style></legend>

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

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

              <tbody id='TMgd6'></tbody>

                  <bdo id='TMgd6'></bdo><ul id='TMgd6'></ul>
                  本文介绍了Struts 2 s:select tag 动态id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在一个 JSP 页面和一个按钮中有多个不同类型的字段.这些字段是根据从我创建的元数据表中获取的信息生成的.

                  I have multiple fields of various types in a JSP page and one button. These fields are generated based on the info got from a metadata table that I have created.

                  由于我不知道存在多少和什么类型的字段,我给他们动态的id.我在我的 JSP 中使用 Struts 2 标签.

                  Since I don't know how many and what type of fields are present, I am giving dynamic id's to them. I am using Struts 2 tags in my JSP.

                  问题出在 <s:select> 标签上:当我在 id 属性中给出 scriplet 时,它会显示以下错误:

                  The issue is with the <s:select> tag: when I give scriplet within the id attribute, it displays the following error :

                  org.apache.jasper.JasperException:/success.jsp(83,12) 需要引用符号

                  org.apache.jasper.JasperException: /success.jsp(83,12) quote symbol expected

                  <s:if test="%{#masterColDO.controlType=='dropdown'}">
                      <s:select styleClass="login-textbox" 
                                     style="width:130px"  
                                      list="#masterColDO.validation"     
                                      name="chngdColumnValues" 
                                        id=<%="columnId" + count%> />
                  </s:if> 
                  <s:else>
                      <input type=<s:property value="#masterColDO.controlType" /> 
                            class="login-textbox " 
                             name="chngdColumnValues" 
                               id=<%="columnId" + count%> />
                  </s:else>
                  

                  Javascript如下:

                  Javascript is as follows:

                  var addUpdateBtnId = document.getElementById('addUpdateBtnId');
                  addUpdateBtnId.value='Update';
                  addUpdateBtnId.onclick = function() {
                      onClickUpdateBtn(rowIndex);
                  };
                  var selectedUpdateRow = xmlhttp.responseText.split(",");
                  for(var i = 0; i < selectedUpdateRow.length; i++){
                      var columnElementId = "columnId"+i;
                      document.getElementById(columnElementId).value = selectedUpdateRow[i];
                  }
                  document.getElementById("columnId"+(primaryKeyPos-1)).readOnly = true;
                  

                  推荐答案

                  Scriptlets 是旧的做事方式,你应该避免在 JSP 中编写 Java 代码;
                  Struts2 仅使用它的标签和 OGNL 帮助您实现相同的目标.

                  Scriptlets are the old way of doing things, you should avoid writing Java code in JSP's at all;
                  Struts2 helps you achieving the same goals using its tags and OGNL only.

                  <input/> 部分正在工作,因为您在 HTML 标记内注入了 scriptlet,这是允许的.

                  The <input /> part is working because you are injecting a scriptlet inside an HTML tag, that is allowed.

                  <s:select/> 部分不起作用,因为您在 Struts2 标记内注入了 scriptlet,这是不允许的.

                  The <s:select /> part is not working because you are injecting a scriptlet inside an Struts2 tag, that is not allowed.

                  为了让它工作,你应该使用 OGNL 中的 #attr 语法来访问 ScriptletsJava 变量code> 并在 Page Context 中推送由你,像这样(完全未经测试):

                  To make it work, you should use #attr syntax in OGNL to access the Java variables declared in Scriptlets and pushed by you in the Page Context, like this (completely untested):

                  <%
                      for (int counter=0;counter<myList.size();counter++) {
                         // pushing it into the pageContext
                         pageContext.setAttribute("counter",counter);
                  %>
                          <s:select cssClass="login-textbox" 
                                    cssStyle="width:130px" 
                                        list="#masterColDO.validation" 
                                        name="chngdColumnValues"      
                                          id="%{'columnId' + #attr['counter']}" />
                  <%    
                      }
                  %>
                  

                  但是,即使技术上可行,也不鼓励这样做.为此,您应该使用纯 Struts2 方式,如下所示:

                  However, even if it's technically possible, it is discouraged. You should use the pure Struts2 way for that, that would be the following:

                  <s:iterator value="myList" status="ctr">
                      <s:select cssClass="login-textbox" 
                                cssStyle="width:130px" 
                                    list="#masterColDO.validation" 
                                    name="chngdColumnValues" 
                                      id="%{'columnId' + #ctr.index}" />
                  </s:iterator>
                  

                  <小时>

                  P.S: Struts 标签没有任何 styleClass 属性;你可以使用 cssClass 和/或 cssStyle;
                  而且,如果 controlType 是一个字符串,你应该使用 .equals 而不是 ==: <s:if test="%{#masterColDO.controlType.equals('dropdown')}">.


                  P.S: Struts tags doesn't have any styleClass attribute; you can use cssClass and/or cssStyle;
                  And, if controlType is a String, you should use .equals instead of ==: <s:if test="%{#masterColDO.controlType.equals('dropdown')}">.

                  这篇关于Struts 2 s:select tag 动态id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)

                • <small id='ZY59h'></small><noframes id='ZY59h'>

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

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

                        • <bdo id='ZY59h'></bdo><ul id='ZY59h'></ul>
                            <tfoot id='ZY59h'></tfoot>