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
JSP Code
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:
****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:
In ObjectCList
class:
In JSP
:
When the form is submitted, updateTreeMap
method of the action
is called. The map is printed as mentioned here :
}
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
.
Or annotate testTreeMap
with com.opensymphony.xwork2.util.Element
annotation to tell Struts2 what type are elements inside map.
这篇关于Struts2:更新“对象列表"的值在地图内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!