struts 2:捕获对番石榴表(TreeBasedTable)的修改 [英] struts 2 : Capturing modifications to a guava table (TreeBasedTable) in action
问题描述
有一个对象(ObjectA),其中有另一个对象(ObjectB).在对象B内有一个Guava TreeBasedTable
.此表具有一个字符串,作为行键,列键,而另一个对象"ObjectC"作为值.该表已使用<s:iterator/>
和<s:textfield/>
标记显示在jsp上,并且已正确显示(<s:textfield/>
内的值"正确,但名称"不正确).
There is an object (ObjectA) which has another object inside (ObjectB). There is a Guava TreeBasedTable
inside the Object B. This Table has a string as row-key,column-key and another object "ObjectC" as value. This table has been displayed on the jsp using the <s:iterator/>
and <s:textfield/>
tags and it is being displayed correctly (the "values" inside the <s:textfield/>
are correct but the "names" are not).
现在,修改<s:textfield/>
时出现问题.如何在动作类的ObjectC中捕获修改后的值?
Now, the problem arises when the <s:textfield/>
is modified. How do we capture the modified values inside ObjectC in the action class?
public class ObjectA implements Serializable {
private Integer attr1;
private List<ObjectB> objB;
//...getters and setters....
public class ObjectB implements Serializable {
private Integer attr11;
private Table<String,String,ObjectC> allPFields;
// ...getters and setters....
public class ObjectC implements Serializable {
private Integer attr111;
public String attr112;
// ...getters and setters....
jsp代码:
<!-- language: lang-html -->
<s:iterator value="#objB.allPlainFields.row(#rowKey)" var="fieldMap"
status="fieldStatus">
<li><label><s:property value="#fieldMap.key" /></label><span>
<s:textfield name="<NOT SURE>" value="%{#fieldMap.value.attr12}" />
</span></li>
</s:iterator>
Guava
中的TreeBasedTable
类似于地图中的地图,我尝试执行allPFields[#outerkey][#innerkey].attr112
,但是没有用.
A TreeBasedTable
in Guava
is similar to a map inside a map, I tried doing allPFields[#outerkey][#innerkey].attr112
but, it didn't work.
显示具有数据库中现有值的屏幕时的对象结构
The object structure when the screen is displayed with existing values in the database
<!-- language: lang-java -->
objA
objBList ArrayList<E> (id=668)
elementData Object[10] (id=7438)
[0] objB (id=7439)
allPFields TreeBasedTable<R,C,V> (id=7443)
backingMap TreeMap<K,V> (id=8116)
cellSet null
columnComparator NaturalOrdering (id=503)
columnKeySet null
columnMap null
factory TreeBasedTable$Factory<C,V> (id=8117)
rowKeySet null
rowKeySet StandardRowSortedTable$RowKeySortedSet (id=8118)
rowMap StandardRowSortedTable$RowSortedMap (id=8119)
rowMap null
values null
"allPFields"看起来像下面这样:
And the "allPFields" looks like the following in action:
{OuterKey1=
{InnerKey1=ObjectC[attr111=31, attr112=Hi there],
InnerKey2=ObjectC[attr111=40, attr112=How are you]
}
}
上面的"allPFields"值已从IDE控制台中获取.
The "allPFields" value above has been picked up from the IDE console.
推荐答案
正如我在另一个问题中告诉您的那样,我从未使用过Guava TreeBasedTable
;
As I told you in your other question, I've never used Guava TreeBasedTable
;
但是,根据官方Guava文档,
TreeBasedTable
,其中is essentially backed by a TreeMap<R, TreeMap<C, V>>