You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Lukasz Lenart (JIRA)" <ji...@apache.org> on 2008/05/17 12:06:05 UTC
[jira] Issue Comment Edited: (WW-1866) Add annotation support for
Action Method
[ https://issues.apache.org/struts/browse/WW-1866?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43871#action_43871 ]
lukasz03 edited comment on WW-1866 at 5/17/08 3:05 AM:
------------------------------------------------------------
Hi,
I added simple implementation for that, you can use @Action annotation at class level and the same annotation at method level, patch below. You can use it like that:
@Action(name = "index") // execute() will be called
@Results
({
@Result(name = EmployeeAction.LIST, value = "/jsp/employees/list.jsp")
})
public class EmployeeAction extends ActionSupport {
protected static final String LIST = "list";
private EmployeeService employeeService;
private Collection<Employee> employees;
public String execute {
employees = employeeService.findAll();
return LIST;
}
@Action(name = "list")
public String doList() {
employees = employeeService.findAll();
return LIST;
}
}
******************************** patch ***************************************
Index: src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java
===================================================================
--- src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java (revision 657312)
+++ src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java Sat May 17 11:37:44 CEST 2008
@@ -21,33 +21,30 @@
package org.apache.struts2.config;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Modifier;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.*;
-
-import javax.servlet.ServletContext;
-
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
-import com.opensymphony.xwork2.config.ConfigurationProvider;
import com.opensymphony.xwork2.config.PackageProvider;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
-import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.ResolverUtil;
-import com.opensymphony.xwork2.util.TextUtils;
import com.opensymphony.xwork2.util.ResolverUtil.ClassTest;
-import com.opensymphony.xwork2.util.location.LocatableProperties;
+import com.opensymphony.xwork2.util.TextUtils;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import javax.servlet.ServletContext;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.*;
+
/**
* ClasspathPackageProvider loads the configuration
* by scanning the classpath or selected packages for Action classes.
@@ -365,7 +362,18 @@
.addResultConfigs(new ResultMap<String,ResultConfig>(cls, actionName, defaultResultType))
.build();
pkgConfig.addActionConfig(actionName, actionConfig);
+ for (Method m : cls.getMethods()) {
+ if (m.isAnnotationPresent(org.apache.struts2.config.Action.class)) {
+ org.apache.struts2.config.Action methodAnn = m.getAnnotation(org.apache.struts2.config.Action.class);
+ actionName = methodAnn.name();
+ ActionConfig.Builder builder = new ActionConfig.Builder(actionPackage, actionName, cls.getName())
+ .addResultConfigs(new ResultMap<String,ResultConfig>(cls, actionName, defaultResultType));
+ builder.methodName(m.getName());
+ actionConfig = builder.build();
+ pkgConfig.addActionConfig(actionName, actionConfig);
- }
+ }
+ }
+ }
/**
* Finds or creates the package configuration for an Action class.
was (Author: lukasz03):
Hi,
I add simple implementation for that, you can use @Action annotation at class level and the same annotation at method level, patch below. You can simple use it like that:
@Action(name = "index") // execute() will be called
@Results
({
@Result(name = EmployeeAction.LIST, value = "/jsp/employees/list.jsp")
})
public class EmployeeAction extends ActionSupport {
protected static final String LIST = "list";
private EmployeeService employeeService;
private Collection<Employee> employees;
public String execute {
employees = employeeService.findAll();
return LIST;
}
@Action(name = "list")
public String doList() {
employees = employeeService.findAll();
return LIST;
}
}
******************************** patch ***************************************
Index: src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java
===================================================================
--- src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java (revision 657312)
+++ src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java Sat May 17 11:37:44 CEST 2008
@@ -21,33 +21,30 @@
package org.apache.struts2.config;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Modifier;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.*;
-
-import javax.servlet.ServletContext;
-
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
-import com.opensymphony.xwork2.config.ConfigurationProvider;
import com.opensymphony.xwork2.config.PackageProvider;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
-import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.ResolverUtil;
-import com.opensymphony.xwork2.util.TextUtils;
import com.opensymphony.xwork2.util.ResolverUtil.ClassTest;
-import com.opensymphony.xwork2.util.location.LocatableProperties;
+import com.opensymphony.xwork2.util.TextUtils;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import javax.servlet.ServletContext;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.*;
+
/**
* ClasspathPackageProvider loads the configuration
* by scanning the classpath or selected packages for Action classes.
@@ -365,7 +362,18 @@
.addResultConfigs(new ResultMap<String,ResultConfig>(cls, actionName, defaultResultType))
.build();
pkgConfig.addActionConfig(actionName, actionConfig);
+ for (Method m : cls.getMethods()) {
+ if (m.isAnnotationPresent(org.apache.struts2.config.Action.class)) {
+ org.apache.struts2.config.Action methodAnn = m.getAnnotation(org.apache.struts2.config.Action.class);
+ actionName = methodAnn.name();
+ ActionConfig.Builder builder = new ActionConfig.Builder(actionPackage, actionName, cls.getName())
+ .addResultConfigs(new ResultMap<String,ResultConfig>(cls, actionName, defaultResultType));
+ builder.methodName(m.getName());
+ actionConfig = builder.build();
+ pkgConfig.addActionConfig(actionName, actionConfig);
- }
+ }
+ }
+ }
/**
* Finds or creates the package configuration for an Action class.
> Add annotation support for Action Method
> ----------------------------------------
>
> Key: WW-1866
> URL: https://issues.apache.org/struts/browse/WW-1866
> Project: Struts 2
> Issue Type: Improvement
> Components: Plugin - CodeBehind
> Affects Versions: 2.0.6
> Reporter: Anderson M. C. de Souza
> Fix For: Future
>
>
> Annotation support for action methods would be a very nice feature to have. I know it's not a basic configuration cenario, but I think it would help a lot "use case" based applications, which many times use one class per use case to handle actions.
> Thanks,
> Anderson Souza
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.