This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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")

 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!