MG>answers prefixed by MG> > > > > here is an example of TaskAction_add-validation.xml: > > > > <!DOCTYPE validators PUBLIC > > "-//OpenSymphony Group//XWork Validator 1.0.2//EN" > > "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> > > <validators> > > <field name="task.name"> > > <field-validator type="requiredstring"> > > <message key="requiredstring"/> > > </field-validator> > > </field> > > </validators> > > > > http://struts.apache.org/2.0.14/docs/action-configuration.html > > > > you should use discrete atomic names for field name attribute so change > > > > I am not exactly sure why I have to use this vilidator in my case? MG>you want to enforce characteristics of the attributes of the form such as will the field will be required (vs optional)
> > > > > > <s:radio list="xx" name="task.steps[0].status" /> > > to > > <s:radio label="label" name="list" list= > > "#NameOfActionClass.NameOfMapinActionClassToPopulateFrom"/> > > > > http://struts.apache.org/2.0.14/docs/radio.html > > > > I know the common usage,but I am not sure how to set it with the Enum type. > > Just for my case,it seems that the "<s:radio label="label" name="list"list= > "#TaskStep.status"/>" does not work. MG>TaskStep needs to be an Action class..( a class that extends ActionSupport ) MG>status needs to be a Map located in TaskStep Action Class which will be used to populate values of the radio button > > > > > > > From: apachemav...@gmail.com > > > Date: Sun, 20 Mar 2011 19:20:54 +0800 > > > Subject: Fwd: update a complex object through struts2 > > > To: user@struts.apache.org > > > > > > > > -------------This post is orignal sent to Martin Gainty. > > > > > > It seems he maybe busy now,so I post it to the list and wonder if any > > other > > > guys can do me a favor. > > > > > > ------------------- > > > ---------- Forwarded message ---------- > > > From: maven apache <apachemav...@gmail.com> > > > Date: 2011/3/19 > > > Subject: Re: update a complex object through struts2 > > > To: Martin Gainty <mgai...@hotmail.com> > > > > > > > > > Thank you very much for your attention and patience. > > > > > > The following is my codes,after trying the whole afternoon,I just can > > make > > > the adding task page,thougth there is also some problem: > > > > > > > > > I have a class named Task. > > > > > > class Task{ > > > > > > private int id; > > > private String name; > > > private List<Operator> managers; //the operator who will be responsible > > > for this task > > > private List<TaskStep> steps; //the required steps to complete this > > > task > > > //getter and setter > > > } > > > > > > > > > class TaskStep{ > > > > > > private int id; > > > private String name; > > > private List<Operator> operators; //the operator who will directly do > > > this job > > > private Status status; // the status of this step(complted or not) > > > } > > > enum Status{ > > > ongoing,done; > > > } > > > > > > My Action TaskAction(used to update and add task) > > > class TaskAction extends ActionSupport{ > > > private int taskid; > > > private List<Operator> allOpInDb; > > > private Task task; > > > public String updatePage(){ > > > //retrive the Task of id "takid", > > > task=new TaskDaoImpl().queryById(taskid); // put it in the > > > valuestack,so it can be referd in thejsp page > > > //initization the allOpInDb > > > allOpInDb=new OperatorDaoImpl().list(); > > > return "updatePage"; > > > } > > > > > > public String update(){ > > > // > > > } > > > public String addPage(){ > > > //initization the allOpInDb > > > allOpInDb=new OperatorDaoImpl().list(); > > > } > > > > > > public String add(){ > > > // > > > } > > > } > > > > > > The struts.xml(core part) > > > <package name="task" extends="struts-default" > > > > <action name="task_*" class="TaskAction" method="{1}"> > > > <result name="updatePage">/jsp/updatePage.jsp</result> > > > <result name="update"></result> > > > <result name="addPage">/jsp/addPage.jsp</result> > > > <result name="add"></result> > > > </action> > > > </package> > > > > > > > > > > > > Now I have pages which are used to add/update a task(including its > > steps): > > > > > > By entering : http://xxxx/task_addPage; > > > I get the addpage: > > > <s:form action="task_add.action"> > > > <s:textfield name="task.name" label="Task Name"> > > > <s:select list="allOpInDb" listKey="id" listValue="name" multiple="true" > > > label="Manager" name="task.managers.id"/> > > > > > > Steps: > > > <!-- step01 --> > > > <table> > > > <tr> > > > <th>Step Name</th> > > > <th>Step Operators</th> > > > <th>Step Status</th> > > > </tr> > > > <tr> > > > <td><s:textfield name="task.steps[0].name"/></td> > > > <td> > > > <s:select list="allOpInDb" listKey="id" listValue="name" > > > multiple="true" name="task.steps[0].id" /> > > > </td> > > > <td> > > > <!-- Here,I do not know hwo to list the Status with the > > > radio button --> > > > <s:radio list="xx" name="task.steps[0].status" /> > > > </td> > > > </tr> > > > <!-- step02 --> > > > <tr> > > > <td><s:textfield name="task.steps[2].name"/></td> > > > <td> > > > <s:select list="allOpInDb" listKey="id" listValue="name" > > > multiple="true" name="task.steps[2].id" /> > > > </td> > > > <td> > > > <!-- Here,I do not know hwo to list the Status with the > > > radio button --> > > > <s:radio list="xx" name="task.steps[2].status" /> > > > </td> > > > </tr> > > > </table> > > > <input type="text" value="add more steps"> > > > </s:form> > > > > > > Question: > > > 1)when to add the "[index]" syntax? > > > For example: > > > "task.steps[0].id" use this syntax,but "task.managers.id" does not. > > > Both the steps and the managers are all java.uitl.List. I wonder why? > > > > > > 2)how to list the value of the enum type,in my case how to list > > > "ongoing","done" as two radio button in the page? > > > > > > > > > The above is the adding task page,and I have to build another > > page,updating > > > task. > > > > > > By entering :http://xxx/task_updatePage?taskid=1< > > http://xxx/task_updatePage> > > > > > I get the update page,It seems that it is more complex than the adding > > page: > > > > > > <s:form action="task_update.action"> > > > <s:textfield name="task.name" value="task.name" label="Task Name"> > > > <s:select list="allOpInDb" listKey="id" listValue="name" multiple="true" > > > label="Manager" name="task.managers.id" value="task.managers.id"/> > > > <table> > > > <tr> > > > <th>Step Name</th> > > > <th>Step Operators</th> > > > <th>Step Status</th> > > > <th> </th> > > > </tr> > > > <!-- Iterator the steps of this task(these steps have id in the db > > > yet) --> > > > <s:iterator value="task.steps"> > > > <tr> > > > <td><s:textfield name="xxx" value="#this.name"></td> > > > <td> > > > <s:select list="allOpInDb" listKey="id" listValue="name" > > > multiple="true" name="xxx" value="#this.operators"/> > > > </td> > > > <td> > > > <!-- Here,I do not know hwo to list the Status with the > > > radio button --> > > > <s:radio list="xx" name="xxx" value="#this.status"/> > > > </td> > > > <td> > > > <!--set the order of the steps --> > > > <a>Make this step up</a><br> > > > <a>Make this step down</a> > > > </td> > > > </tr> > > > </s:iterator> > > > </table> > > > </s:form> > > > > > > As you can see,in the form I can just read the value form the stack,but I > > do > > > not know how to set the "name" attribute of each input. > > > > > > Also,suppose all of these question are solved which I mean the value can > > be > > > sent to the server side,so a new object of "Task" will be created by > > > struts,since I am update this task,so this task must own a id in the db,I > > > have the following things to do: > > > 1)get the being updated Task from the db from the id. > > > 2)copy all the field attributes of the Task object created by struts to > > the > > > Task object in the db,this is crazy,since there are so many fields in the > > > task,and even is field "List<TaskStep>" also own in in the db,I may make > > a > > > duplicate object and save it to db. > > > > > > Any secury problem? > > > > > > BTW,the tag "s:select" with property of "multiple='true'" will take too > > much > > > space in the page if the "list" own a large size,any way to slove this? > >