I have been trying to integrate Tiles with Struts 2 annotation based action but it's not working correctly.
As I don't have struts-config.xml
and in every tutorial available at web they are referencing it with struts-config.xml
.
First is it possible to integrate annotation based struts action with tiles. If yes then how?
@Action(value="/login",results={@Result(name="success",location="/home",type=TilesResult.class),
@Result(name="login",location="/jsp/userLogin.jsp")})
public String execute() {
This is what my code is but it always gives me error in MyEclipse at TilesResult.class
that
Type mismatch: cannot convert from Class<TilesResult> to String
I have dependency in my pom:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>2.1.8</version>
</dependency>
Can anyone help me how to add tiles in annotation based actions
I used type="tiles"
instead of type=TilesResult.class
then it has given me below exception
Caused by: The Result type [tiles] which is defined in the Result annotation on the class [class com.actions.LoginAction] or determined by the file extension or is the default result type for the PackageConfig of the action, could not be found as a result-type defined for the Struts/XWork package [com.actions#convention-default#] - [unknown location]
at org.apache.struts2.convention.DefaultResultMapBuilder.createResultConfig(DefaultResultMapBuilder.java:422)
at org.apache.struts2.convention.DefaultResultMapBuilder.createFromAnnotations(DefaultResultMapBuilder.java:394)
at org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:202)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:800)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:586)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:318)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)