Vita Rara: A Life Uncommon

I found a method that works, partially though

I am searching for a way to edit a list of entities without using the Map, too.
I tried the method in http://struts.apache.org/2.x/docs/type-conversion.html
Use some format like this in the jsp page:

<s:iterator value="myEntities" id="bean">
<stextfield name="myEntities(%{bean.id}).value" />
</s:iterator>

But it is not working, neither to display the data in jsp page or return value to the list after submit, I played with it and found that if I change it like this:

<s:iterator value="myEntities" id="bean">
<stextfield name="myEntities('%{bean.id}').value" />
</s:iterator>

It is able to display the right value in form, but still can't return value to the list in Action. The List is always reset to null.

Then I figure out a way as follows to make it work in both display and save back to the list in Action.

<s:iterator value="myEntities" status="status">
<s:textfield name="%{myEntities['+#status.index+'].value}" />
</s:iterator>

But I found out that it still create a new instance of myEntities, and save all the values in form to the new myEntities. If you don't display some filed in the form, the field will be null, and the old data is gone. I haven't try your 'Map' solution yet, does your method keep the old data in myEntities even you don't display them in the jsp page?

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
  • Allowed HTML tags: <a> <img> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <h1> <h2> <h3>
  • Lines and paragraphs break automatically.
More information about formatting options