Re: how to write json/xml output using struts 2 and rest + convention plugin
I'm not familiar with this application but simply look at the documentation for the struts2-json-plugin, you can specify a json result and you can specify include and exclude parameters (so you just return the part(s) of your Action you want). In this way you could define a new map, put a key of "results" with a value of "New order created successfully" and return it quite easily. If the struts2 document is insufficient there are plenty of examples also on StackOverflow, so take a look there too (Including many annotation based examples). On Thu, Oct 4, 2012 at 4:21 PM, Jane Wayne wrote: > i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for today. > i am trying to understand and study the rest struts2-rest-showcase > webapp. > > in the rest showcase, the OrdersController class has the following method. > > public String editNew() { > model = new Order(); > return "editNew"; > } > > the user is taken to orders-editNew.jsp. on this page, the form posts > to: action="%{#request.contextPath}/orders". the action to handle this > form is as follows. > > public HttpHeaders create() { > ordersService.save(model); > addActionMessage("New order created successfully"); > return new DefaultHttpHeaders("success").setLocationId(model.getId()); > } > > at this point, the user is taken to orders-index.jsp. however, i do > not want to take the user to this page. i instead want to write a > JSON/XML message back saying something (just like the action message) > to indicate success/failure. how do i do this? > > i imagine my client application posting data to: /orders/new > and then receiving some JSON message: > { "results" : "New order created successfully" } > > any help is appreciated. > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
how to write json/xml output using struts 2 and rest + convention plugin
i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for today. i am trying to understand and study the rest struts2-rest-showcase webapp. in the rest showcase, the OrdersController class has the following method. public String editNew() { model = new Order(); return "editNew"; } the user is taken to orders-editNew.jsp. on this page, the form posts to: action="%{#request.contextPath}/orders". the action to handle this form is as follows. public HttpHeaders create() { ordersService.save(model); addActionMessage("New order created successfully"); return new DefaultHttpHeaders("success").setLocationId(model.getId()); } at this point, the user is taken to orders-index.jsp. however, i do not want to take the user to this page. i instead want to write a JSON/XML message back saying something (just like the action message) to indicate success/failure. how do i do this? i imagine my client application posting data to: /orders/new and then receiving some JSON message: { "results" : "New order created successfully" } any help is appreciated. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: overriding framework components
> 2012/10/4 Davis, Chad : > > And, since I think I saw your name on some comments in the TextProvider, > I wonder what constructors get invoked when the TextProvider is injected in > the TextProviderFactory on ActionSupport. The default TextProviderSupport > has references to locale provider and a class, which can be set via a > constructor. But I suspect the DI must only use the parameterless > constructor. Is this true? In what cases do those other constructors get > invoked? > > Yeah, it was my first bigger addition to Struts 2 ;-) It isn't an optimal one > ;-) > Hey, no apologies needed. Beggars can't be choosers ;) The struts 2 code is some of the best code I work with . . . so I'm not complaining. > Anyway, you're right. DI will use the default constructor, the others are used > in other places (TextProviderFactory and ) - that's why it isn't an optimal > solution. DI supports also constructor injections, in the same way as property > injection, just add @Inject to constructor. > I'll check this out and get back to you. There's another bit, a complication perhaps, in that I'm trying to extend the ActionSupport, not replace it. My use case is that some folks before my time wrote their own i18n layer instead of using the framework's and I want to layer those text lookups in front of the framework's own. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: implementaiton advise on custom TextProvider
2012/10/4 Davis, Chad : > So, I want to have the framework use my own custom TextProvider. Since the > framework uses DI to inject such things, I've been able to have my own custom > TextProvider injected into the system. Now, I'm encountering some other > issues related to how to correctly initialize my custom provider. > > ActionSupport#getTextProviderSupport() uses the TextProviderFactory to obtain > it's instance of a support object. Since it uses the di to inject this into > the factory, my custom version is correctly injected. However, I need to > initialize my custom support object with a resource that it needs to conduct > its business. Note, the default TextPRoviderSupport also needs a couple of > resources, and those are initialized in the factory's createInstance( Class > class, LocaleProvider provider ). So, while I've injected my own class, > there doesn't seem to be a clean way to make sure that it's initialized > properly. Should I extend the factory to handle my class and init it too? > Doesn't seem very DI-ish . . . hardcoding type specific init logic, I mean. > > Or should I create an interceptor that will inject the correct resources into > my text support object? ActionSupport base on property injections so you cannot base on anything which is injectable - you cannot use getTextProvider during initialisation time (construction time). You can implement your own ActionSupport with constructor injected TextProvider that should solve your problem. Regards -- Łukasz + 48 606 323 122 http://www.lenart.org.pl/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: overriding framework components
2012/10/4 Davis, Chad : > And, since I think I saw your name on some comments in the TextProvider, I > wonder what constructors get invoked when the TextProvider is injected in the > TextProviderFactory on ActionSupport. The default TextProviderSupport has > references to locale provider and a class, which can be set via a > constructor. But I suspect the DI must only use the parameterless > constructor. Is this true? In what cases do those other constructors get > invoked? Yeah, it was my first bigger addition to Struts 2 ;-) It isn't an optimal one ;-) Anyway, you're right. DI will use the default constructor, the others are used in other places (TextProviderFactory and ) - that's why it isn't an optimal solution. DI supports also constructor injections, in the same way as property injection, just add @Inject to constructor. Regards -- Łukasz mobile +48 606 323 122 http://www.lenart.org.pl/ Warszawa JUG conference - Confitura http://confitura.pl/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
implementaiton advise on custom TextProvider
So, I want to have the framework use my own custom TextProvider. Since the framework uses DI to inject such things, I've been able to have my own custom TextProvider injected into the system. Now, I'm encountering some other issues related to how to correctly initialize my custom provider. ActionSupport#getTextProviderSupport() uses the TextProviderFactory to obtain it's instance of a support object. Since it uses the di to inject this into the factory, my custom version is correctly injected. However, I need to initialize my custom support object with a resource that it needs to conduct its business. Note, the default TextPRoviderSupport also needs a couple of resources, and those are initialized in the factory's createInstance( Class class, LocaleProvider provider ). So, while I've injected my own class, there doesn't seem to be a clean way to make sure that it's initialized properly. Should I extend the factory to handle my class and init it too? Doesn't seem very DI-ish . . . hardcoding type specific init logic, I mean. Or should I create an interceptor that will inject the correct resources into my text support object? - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: overriding framework components
> > Here you have the full list of extension points > > http://struts.apache.org/2.x/docs/plugins.html#Plugins-ExtensionPoints > Excellent. Thank you. And, since I think I saw your name on some comments in the TextProvider, I wonder what constructors get invoked when the TextProvider is injected in the TextProviderFactory on ActionSupport. The default TextProviderSupport has references to locale provider and a class, which can be set via a constructor. But I suspect the DI must only use the parameterless constructor. Is this true? In what cases do those other constructors get invoked?
Re: Struts2 authentication, validation, and roles
2012/10/3 Ken McWilliams : > Asking for the consideration of a struts2 feature enhancement. > > The roles interceptor depends on container based security, it is a bit > of a pain to set up and portability is complicated by needing to cover > more documentation steps (how to secure your application on Glassfish, > Weblogic, Tomcat...). This is container security and of course not > Struts2s issue but it would be nice it we could use the roles > interceptor by defining a > org.apache.struts2.interceptor.PrincipalProxy implementation and > specifying it with a struts2 constant: > > value="com.example.MyPrincipalProxyImpl"/> //default would be > org.apache.struts2.servlet.interceptor.ServletPrincipalProxy > > There is only a few place (that I know of) where the PrincipalProxy > interface aught to be used where currently the request is being used > (aught to be used if implementing this feature). That is in the > "servletConfig" interceptor when setting the PrincipalAware interface > of an action and in the roles interceptor. > > It is not too much work to implement our own interceptors to > facilitate role based access but I think this would be helpful to many > and does not seem to require a radical change to S2 internals, so I > thought I would bring this up in the user forum to see what others > think. I thought a bit more about that and this can be achieved by a PrincipalProvider (as TextProvider) which can be injected onto interceptors or any other place. It will produce PrincipialProxy base on HttpServletRequest, eg. PrincipialProvider#getPrincipialProxy(HttpServletRequest) Regards -- Łukasz mobile +48 606 323 122 http://www.lenart.org.pl/ Warszawa JUG conference - Confitura http://confitura.pl/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org