How is that for a subject line?  I always wonder what I would search for
myself :working:

I had a guy tell me that a struts web tag was generating an absurd number of
method calls on his action/model.  After carefully considering his scenario,
I was able to experiment using the files below.  When the page is loaded a
single call is made to the getThings() which returns one instance of Thing. 
However, when the submit is clicked, the getThings() is called 33 times! 
Before I bury my head in code, can anyone see why this might be the case? 
The Parameters interceptor is in the stack one time and the generated HTML
is generating this single parameter:

<input type="text" name="things[0].name" value="foo"
id="mapBackedUIsaveList_things_0__name"/> 



Action:

public class ListAction extends BaseAction {

        private static List<Thing> things;
        public List<Thing> getThings() {
                if (things == null) {
                        things = new ArrayList();
                        things.addAll(Thing.getThings());
                }
                return things;
        }

        public void setThings(List<Thing> things) {
                this.things = things;
        }
        public String list() throws Exception {
                return SUCCESS;
        }
        public String saveList() throws Exception {
                return SUCCESS;
        }
}

Page:

<s:form action="mapBackedUIsaveList">
        <table>
                <tr>
                        <td>
                                Name
                        </td>
                </tr>
                <s:iterator value="things" status="status">
                        <tr>
                                <td>

                                </td>
                                <td>
                                        <s:textfield 
name="things[%{#status.index}].name"
                                                value="%{name}" />
                                </td>
                                <td>

                                </td>
                        </tr>
                </s:iterator>
        </table>
        <s:submit />
</s:form>

Bean:

public class Thing {

private String name;

get/set

}
-- 
View this message in context: 
http://www.nabble.com/Mapped-back-UI-and--status.index-driven-names-tp24057659p24057659.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to