Posts

Exception Configuration Information

Image
Exception mappings is a powerful feature for dealing with an Action class that throws an Exception. The core idea is that an Exception thrown during the Action method can be automatically caught and mapped to a predefined Result. This declarative strategy is especially useful for frameworks, like Hibernate and Acegi, that throw RuntimeExceptions. As with many other parts of the framework, an Interceptor is needed to activate the exception mapping functionality. Below is a snippet from struts-default.xml which has the exception mapping already activated. snippet of struts-default.xml ... < interceptors >      ...      < interceptor name = "exception" class = "com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor" />      ... </ interceptors > < interceptor-stack name = "defaultStack" >      < interceptor-ref name = "exception" /...

About Unknown Handlers

Unknown Handler stacks are available from Struts 2.1 on. Unkown Handlers Unknown Handlers are classes that implement the com.opensymphony.xwork2.UnknownHandler interface, and are called by the framework, when an unknown action, result, or method are executed. To define an unknown handler, create a class implementing the mentioned interface, and add a bean definition to your struts.xml: < bean type = "com.opensymphony.xwork2.UnknownHandler" name = "handler" class = "myclasses.SomeUnknownHandler" /> Stacking Unknown Handlers Multiple unknown handlers can be defined, using the unknown-handler-stack tag: < bean type = "com.opensymphony.xwork2.UnknownHandler" name = "handler1" class = "com.opensymphony.xwork2.config.providers.SomeUnknownHandler" /> < bean type = "com.opensymphony.xwork2.UnknownHandler" name = "handler2" class = "com.opensymphony...

Everything about Result Configuration

Image
When an action class method completes, it returns a String. The value of the String is used to select a result element. An action mapping will often have a set of results representing different possible outcomes. A standard set of result tokens are defined by the ActionSupport base class. Predefined result names String SUCCESS = "success" ; String NONE    = "none" ; String ERROR   = "error" ; String INPUT   = "input" ; String LOGIN   = "login" ; Of course, applications can define other result tokens to match specific cases. Returning ActionSupport.NONE (or null ) from an action class method causes the results processing to be skipped. This is useful if the action fully handles the result processing such as writing directly to the HttpServletResponse OutputStream. Result Elements The result element has two jobs. First, it provides a logical name. An Action can pass back a token like "suc...

Action Configuration

Image
The action mappings are the basic "unit-of-work" in the framework. Essentially, the action maps an identifier to a handler class. When a request matches the action's name, the framework uses the mapping to determine how to process the request. Action Mappings The action mapping can specify a set of result types, a set of exception handlers, and an interceptor stack. Only the name attribute is required. The other attributes can also be provided at package scope. A Logon Action <action name= "Logon" class = "tutorial.Logon" >    <result type= "redirectAction" >Menu</result>    <result name= "input" >/Logon.jsp</result> </action> When using Convention Plugin the action mapping can be configured with annotations: A Logon Action with annotations package tutorial @Action ( "Logon" ) // actually that is not necessary as it is added by convent...