File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts 2: Using annotations instead of struts.xml for result-type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2: Using annotations instead of struts.xml for result-type" Watch "Struts 2: Using annotations instead of struts.xml for result-type" New topic
Author

Struts 2: Using annotations instead of struts.xml for result-type

Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
I know that you can return custom objects using struts2 by specifying a declaration in your struts.xml file. I've done that, gotten that to work.

What I want to do is move away from that, and accomplish the same thing via annotations. If I have an action that is going to return a custom result type I would like to be able to do it. I played around a bit but haven't been able to get anything to work.



This doesn't work


This doesn't compile

Any thoughts?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please see the JavaRanch naming policy and change your display name to conform with this policy. Thanks!

As far as I know the "type" parameter still needs to be a valid, declared result type *name* (not class). So it'll be a string defined in XML (I don't know if you can do that without XML or not--the answer used to be no, but that may have changed by now).
Sita Marivada
Greenhorn

Joined: Apr 01, 2010
Posts: 14
If you want to return a plain jsp, you can write like

@Result(name="success", type="plaintext" location="myResult.jsp")

If you want to return a tile, you can write like

@Result(name="success", type="tiles" location="nameoftiledef")


Sita Putta
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2: Using annotations instead of struts.xml for result-type
 
Similar Threads
There is no Action mapped for namespace ... and action name ...
validate a bean property in struts 2 using Xwork framework
Struts2 tiles ActionClass not detected
Struts2 annotation validation
open a pdf inline using MIME in ie7