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

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

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

          <bdo id='PNmsB'></bdo><ul id='PNmsB'></ul>
      1. Struts2:更新“对象列表"的值在地图内

        Struts2: Updating the values of a quot;List Of Objectsquot; inside a Map(Struts2:更新“对象列表的值在地图内)
        • <bdo id='YE0sm'></bdo><ul id='YE0sm'></ul>

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

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

                <tfoot id='YE0sm'></tfoot>
                  <tbody id='YE0sm'></tbody>
                <legend id='YE0sm'><style id='YE0sm'><dir id='YE0sm'><q id='YE0sm'></q></dir></style></legend>
                1. 本文介绍了Struts2:更新“对象列表"的值在地图内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  There is an object ObjectA which has a list of ObjectB. There is a TreeMap inside the ObjectB. This TreeMap has a String as key and a List of another object ObjectC as value. This TreeMap and the list inside has been displayed on the jsp using the s:iterator and s:textfield and it is being displayed correctly. i.e. the "values" inside the s:textfield are correct. Now, the problem arises when the textfield is modified. How do we capture the modified values inside ObjectC in the action class? With the code given here, the key ("Key1") comes in the action but the value is null.

                  Java Code

                  public class ObjectA implements Serializable {
                  private Integer attr1;
                  private List<ObjectB> objB;
                  //...getters and setters....
                  public class ObjectB implements Serializable {
                  private Integer attr11;
                  private TreeMap<String,List<ObjectC>> allPlainFields;
                  // ...getters and setters....
                  public class ObjectC implements Serializable {
                  private Integer attr111;
                  public String attr112;
                  // ...getters and setters....
                  

                  JSP Code

                  <s:iterator value="objA.objB" var="currentObjB" status="currentGroupStatus">
                  
                    <s:iterator value="#currentObjB.allPlainFields" var="parentMap" status="headerStatus">
                       <s:iterator value="#parentMap.value" var="fieldList" status="fieldStatus">
                  
                         <s:textfield  name="objA.objB[%{#currentGroupStatus.index}].allPlainFields['%{#parentMap.key}'][%{#fieldStatus.index}].attr112"/>
                  
                  
                  </s:iterator>                       
                  
                   </s:iterator> 
                  

                  HTML rendered: <input type="text" id="review-act1_objA_objB_0__allPlainFields_'Key1'__6__attr112" value="Correct Value" name="objA.objB[0].allPlainFields['Key1'][0].attr112">

                  The object structure in the "VAriables" view of eclipse shows:

                  objA    Object A  (id=955)  
                  objB    ArrayList<E>  (id=966)  
                      elementData Object[10]  (id=967)    
                          [0] ObjectB  (id=968)   
                              allPlainFields  TreeMap<K,V>  (id=972)  
                                  comparator  null    
                                  descendingMap   null    
                                  entrySet    TreeMap$EntrySet  (id=979)  
                                  keySet  null    
                                  modCount    1   
                                  navigableKeySet null    
                                  root    TreeMap$Entry<K,V>  (id=980)    
                                  size    1   
                                  values  null    
                  
                          [1] ObjectB  (id=969)   
                          [2] ObjectB  (id=970)   
                          [3] ObjectB  (id=971)   
                          [4] null    
                          [5] null    
                          [6] null    
                          [7] null    
                          [8] null    
                          [9] null    
                      modCount    4   
                      size    4   
                  

                  ****In the Eclipse "Variables" view, the value for allPlainFields is**:** {Key1=}

                  EDIT(27-Feb-2013):

                  Tried this but didn't work. The values appear on jsp but when submitted, they don't come in action:

                  In Action class:

                  private TreeMap<String,ObjectCList> testTreeMap = new TreeMap<String,ObjectCList>();
                  //get,set and setting two keys in map "mykey1" and "mykey2"
                  

                  In ObjectCList class:

                  private ArrayList<ObjectC> paramMdlList;
                   //default constructor, get, set
                  

                  In JSP:

                  <s:form id="test-map" method="post">
                  <s:iterator value="testTreeMap" var="pMap" status="hStatus">
                       <li><label><s:property value="%{#pMap.key}" /></label> 
                          <s:iterator value="%{#pMap.value.paramMdlList}" var="pList" status="innerStatus">
                              <s:textfield name="testTreeMap['%{#pMap.key}'].paramMdlList[%{#innerStatus.index}].attr111"/>
                              <s:textfield name="testTreeMap['%{#pMap.key}'].paramMdlList[%{#innerStatus.index}].attr112"/> 
                  
                          </s:iterator>
                  
                  
                      </li>
                  
                  </s:iterator>
                  <s:submit value=" " type='button' id="btnh1" action="saveTreeMap">
                              <span>Save TreeMap</span>
                  </s:submit>
                  </s:form>
                  

                  When the form is submitted, updateTreeMap method of the action is called. The map is printed as mentioned here :

                  public String updateTreeMap(){
                  
                      for (Map.Entry<String, ObjectCList> entry : testTreeMap.entrySet())
                      {
                          System.out.println(entry.getKey() + "/" + entry.getValue());
                      }
                  
                      return SUCCESS;
                  

                  }

                  What is "printed" : mykey1/ mykey2/ i.e. null values

                  The screen below shows values coming in jsp

                  解决方案

                  According to your latest update. If you are using TreeMap Struts2 cannot correctly determine type of elements inside it. Change declaration of testTreeMap from TreeMap to Map.

                  private Map<String,ObjectCList> testTreeMap = new TreeMap<String,ObjectCList>();
                  

                  Or annotate testTreeMap with com.opensymphony.xwork2.util.Element annotation to tell Struts2 what type are elements inside map.

                  @Element(value = ObjectCList.class)
                  private TreeMap<String,ObjectCList> testTreeMap = new TreeMap<String,ObjectCList>();
                  

                  这篇关于Struts2:更新“对象列表"的值在地图内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的游戏框架.有什么建议吗?)
                      <i id='5P5OS'><tr id='5P5OS'><dt id='5P5OS'><q id='5P5OS'><span id='5P5OS'><b id='5P5OS'><form id='5P5OS'><ins id='5P5OS'></ins><ul id='5P5OS'></ul><sub id='5P5OS'></sub></form><legend id='5P5OS'></legend><bdo id='5P5OS'><pre id='5P5OS'><center id='5P5OS'></center></pre></bdo></b><th id='5P5OS'></th></span></q></dt></tr></i><div id='5P5OS'><tfoot id='5P5OS'></tfoot><dl id='5P5OS'><fieldset id='5P5OS'></fieldset></dl></div>
                        <tbody id='5P5OS'></tbody>

                      • <small id='5P5OS'></small><noframes id='5P5OS'>

                          <bdo id='5P5OS'></bdo><ul id='5P5OS'></ul>
                          <tfoot id='5P5OS'></tfoot>
                            <legend id='5P5OS'><style id='5P5OS'><dir id='5P5OS'><q id='5P5OS'></q></dir></style></legend>