the "dynamic namespace assignment" ListPeopleAction example package org.apache.struts2.showcase.person; import java.util.ArrayList; import java.util.List; import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result;
@ParentPackage("person") @Namespace(value="listPerson") //theoretically this should change namespace from /person to /listPerson @Results({ @Result(name="list", location="list-people.action", type="redirect"), @Result(name="input", location = "list-people.action", type="redirect"), @Result(name="success", location = "listPerson.jsp", type="redirect") //produces No result defined for action org.apache.struts2.showcase.person.NewPersonAction and result input //com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375) //@Result(name="input", location="/person/editPerson.jsp"), }) public class ListPeopleAction extends ActionSupport { private static final long serialVersionUID = 3608017189783645371L; PersonManager personManager; List people = new ArrayList(); public void setPersonManager(PersonManager personManager) { this.personManager = personManager; } public String execute() { people.addAll(personManager.getPeople()); return SUCCESS; } public List getPeople() { return people; } public int getPeopleCount() { return people.size(); } } theoretically listPerson namespace is supposed to replace default assigment of 'person' so lets take a look at behavior once struts-showcase webapp is loaded: http://localhost:8080/struts2-apps/person I see the original 2 menu options: 1) Create a new Person 2) List all persons I want to see if the /listPerson is assigned is working so I click on 2)List all persons and the dispatcher takes me to http://localhost:8080/struts2-apps/person/listPeople.action listPeople.action is correct because @Result(name="input", location = "list-people.action", type="redirect") but the dynamic re-assigment of namespace /person to listPerson has not taken plac I then correct address bar http://localhost:8080/struts2-apps/listPerson/listPeople.action and am displayed 404 by dispatcher 2 possible courses of action 1)redact @Namespace since it doesnt invoke JDKProxy to redirect namespace 'person' to 'listPerson' 2)is there a way to change xwork ObjectFactory to not use ProxyObjectFactory or CGLIB but the JDK Proxy change: <xwork> <bean type="com.opensymphony.xwork2.ObjectFactory" name="default" class="com.opensymphony.xwork2.ProxyObjectFactory" /> to a factory which will implement JDK Proxy e.g: // Implement interface Class<?> clazz = Class.forName("Namespace"); Object listenerInstance = Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[]{clazz}, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if(method.getName().equals("onReceive")){ System.out.println("ARGS: " + (Integer)args[0] + ", " + (Integer)args[1]); return 1; } else return -1; } }); Thoughts? Martin ------------------------------------------------------------------------------------------------------------- The key to prevent a hacked email account is to change password more than every 5 years.. > From: mgai...@hotmail.com > To: user@struts.apache.org > Subject: RE: Using Struts2 Rest Plugin with deep cascading actions > Date: Sat, 24 Jan 2015 18:38:43 -0500 > > > > > > Date: Sat, 24 Jan 2015 15:24:49 +0530 > > Subject: Re: Using Struts2 Rest Plugin with deep cascading actions > > From: ghotankaru...@gmail.com > > To: user@struts.apache.org > > > > Well after doing some research on designing rest api ***best practices*** I > > realized I was doing something wrong. > > > > For getting all companies, we must use > > > > http://localhost/company > > > > For getting all locations of that company we can use > > > > http://localhost/company/111/locations > > > > For anything else to get from any particular location we can use > > > > http://localhost/company/locations/111 - to get location details > > ****(/company/ only in namespacing ) > > > > http://localhost/company/locations/111/contacts - to get location contacts > > > > etc............. > > > > > > Now question is how do we implement namespacing in struts2 rest api??? > > > > As by default all actions are @root right? > > > > can we have @namespace(value="/company/") annotation in Location Action???? > > > > But this does not work for me, it redirects to company action only and says > > no method available. > > > > Or we must not use such namespacing and its better to use > > http://localhost/location instead of http://localhost/company/location > > > > Please suggest. > > MG>you need to specify the namespace attribute in <package specification > MG>http://www.mkyong.com/struts2/struts-2-namespace-configuration-example-and-explanation > MG>there is a movement to add more "annotation based specifications" at > ActionClass level in the new Struts 3.x > MG>if you make a request in Struts JIRA and add a testcase then one of or > more of us will follow thru if this feasible > MG>https://issues.apache.org/jira/secure/Dashboard.jspa > > > > > On Fri, Jan 23, 2015 at 4:20 PM, Amol Ghotankar <ghotankaru...@gmail.com> > > wrote: > > > > > hi, > > > > > > I was trying out struts2 rest plugin and found it really cool. > > > > > > But was just wondering how will this work with action cascading ? i.e > > > > > > So When using http://localhost/company it goes to companyAction and > > > executes respective mapped methods > > > > > > But how do we organize work when we > > > http://localhost/company/1/locations/2/contact/2/ ??? > > > > > > Will these be methods in same class? Class will grow too big & if not how > > > does it get mapped to contactAction and pass values their? > > > > > > How about more complex case where we have > > > http://localhost/company/1/locations/2/contact/2/order/2/transaction/1/payment > > > or something like this??? > > > > > > Domain objects are hibernate entities when company has locations has > > > contacts has orders has transaction has payments? > > > > > > or should the rest url be something different and simplified? like > > > http://localhost/order/2/transaction/1/payment but still has issues > > > mapping things and reusing actions? > > > > > > Am I missing something in rest plugin? > > > > > > -- > > > > > > > > > > > > *With Best Regards,* > > > > > > Amol Ghotankar > > > Technical Lead > > > M: +91 9960 980 419 <http://www.cursivetech.com> > > > > > > > > > > > -- > > > > > > > > *With Best Regards,* > > > > Amol Ghotankar > > Technical Lead > > M: +91 9960 980 419 <http://www.cursivetech.com> >