2011/3/20 Martin Gainty <mgai...@hotmail.com>

>  Another common approach is to postfix the method name and set it off with
> an exclamation point (aka "bang"), underscore, or other special character.
>
>    - "action=TaskAction_add"
>    - "action=TaskAction_update"
>
> To use a postfix wildcard, just move the asterisk and add an underscore.
>
> <action name="TaskAction_*" class="TaskAction" method="{1}">
>
>  From the framework's perspective, a wildcard mapping creates a new
> "virtual" mapping with all the same attributes as a conventional, static
> mapping. As a result, you can use the expanded wildcard name as the name of
> validation, type conversion, and message resource files, just as if it were
> an Action name (which it is!).
>
>    - TaskAction_add-validation.xml
>    - TaskAction_update-conversion.xml
>
>
> 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?


>
> <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.

>
> use of iterators:
>
> <s:iterator value="OperatorDaoImpl.groups" status="groupStatus">
>      <tr class="<s:if test="#groupStatus.odd == true 
> ">odd</s:if><s:else>even</s:else>">
>
>          <td><s:property value="operator_name" /></td>
>          <td><s:property value="operator_customers" /></td>
>
>          <td>
>              <s:iterator value="customers" status="customerStatus">
>                  <s:property value="customerFullName" /><s:if 
> test="!#customerStatus.last">,</s:if>
>
>              </s:iterator>
>          </td>
>      </tr>
>  </s:iterator>
>
>
This is the usage of s:iterator.  I know it yet.

Now my biggest problem is how to collect information from the form and
create the nested object-- Task (including it TaskSteps,Operators,name
setted) by struts.




------------------
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 good ideas about this?


>  Martin Gainty
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
> Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
> Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
> dient lediglich dem Austausch von Informationen und entfaltet keine
> rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
> E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
>
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le 
> destinataire prévu, nous te demandons avec bonté que pour satisfaire informez 
> l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci 
> est interdite. Ce message sert à l'information seulement et n'aura pas 
> n'importe quel effet légalement obligatoire. Étant donné que les email 
> peuvent facilement être sujets à la manipulation, nous ne pouvons accepter 
> aucune responsabilité pour le contenu fourni.
>
>
>
>
>
>
> > 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>&nbsp;</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?
>

Reply via email to