Struts navigation involves the use of the ActionForward
, which can either be created
programmatically or loaded from the action mapping using ActionMapping.findForward()
.
Strecks supports ActionForward
-based navigation in two ways. It supports implicit transparent
use of ActionMapping.findForward()
via one set of controller implementations. An alternative
set of controller implementations use the @NavigateForward
annotation, which leaves the
developer free to choose a navigation implementation strategy.
An example of implicit ActionForward
-based navigation is shown below.
/**
* Strecks navigation with implicit ActionMapping.findForward()
*/
@Controller(name = BasicController.class)
public class ExampleBasicAction implements BasicAction
{
private String message;
public String execute()
{
message = "Successfully executed " +
ExampleBasicAction.class.getName();
return "success";
}
public String getMessage()
{
return message;
}
}
In the above example, the controller will call ActionMapping.findForward()
using the
result of execute()
.
An alternative to this is to use the @NavigateForward
annotation, as shown below:
/**
* Strecks with @NavigateForward annotation (returning String)
*/
@Controller(name = NavigableController.class)
public class ExampleNavigableAction implements NavigableAction
{
private String message;
public void execute()
{
message = "Navigation using @Navigate annotation in "
+ ExampleNavigableAction.class.getName();
}
@NavigateForward
public String getResult()
{
return "success";
}
public String getMessage()
{
return message;
}
}
The big difference between the two is that in the second example, the navigation mechanism is not built into the controller action to action bean interface. The following would also be a valid navigation implementation:
/**
* Strecks with @NavigateForward annotation (returning ActionForward)
*/
@Controller(name = NavigableController.class)
public class ExampleNavigableAction implements NavigableAction
{
private String message;
public void execute()
{
message = "Navigation using @Navigate annotation in "
+ ExampleNavigableAction.class.getName();
}
@NavigateForward
public ActionForward getResult()
{
return new ActionForward("/WEB-INF/result.jsp");
}
public String getMessage()
{
return message;
}
}
Navigation can even be supported using a custom annotation.
Strecks offers this flexibility to open up the possibility of other navigation mechanisms, including, for example,
rendering of Spring MVC View
implementations.