You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tommy Pham <to...@gmail.com> on 2014/02/19 06:21:28 UTC

Need help with Annotations Tutorial @ cwiki

Hi folks,

I just finished the Annotations Tutorial at Struts's cwiki [1] and ran into
a bit of a problem.  I was wondering if someone could please shed a light
on.  Here's my dev environment:

Windows 8.1 x64
Oracle/Sun JDK 1.7.0_45
Tomcat 7.0.50
Struts 2.3.16
Eclipse Kepler SR-1


The tutorial project works fine when my packages within src/main/java is
different (ie. annotations.*) from my group + artifact (ie.
local.workgroup.tutorial.struts2).  If it matches, it errors reporting
unmapped actions:

--------------------------------------------------------------------------------
snippet from pom.xml:

<groupId>local.workgroup.tutorial.struts2</groupId>
<artifactId>annotations</artifactId>
<packaging>war</packaging>
--------------------------------------------------------------------------------
Works with below package:

package annotations.actions;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;

public class HelloAction extends ActionSupport {
  //...
}
--------------------------------------------------------------------------------
Errors when package is:

package local.workgroup.tutorial.struts2.actions;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;

public class HelloAction extends ActionSupport {
  //...
}

****************************************************************

Here's a brief error:

Struts has detected an unhandled exception:
  *Messages*:
There is no Action mapped for namespace [/] and action name [hello]
associated with context path [/annotations].



Looking at the /annotations/config-browser/index.action, there are no
actions listed under default namespace.  However, under the /actions
namespace:
Actions in /actions

   - hello<http://localhost:8080/annotations/config-browser/showConfig.action?namespace=%2Factions&actionName=hello>
   - register<http://localhost:8080/annotations/config-browser/showConfig.action?namespace=%2Factions&actionName=register>
   - register-input<http://localhost:8080/annotations/config-browser/showConfig.action?namespace=%2Factions&actionName=register-input>



If I tried /annotations/actions/hello.action, I get this error:

Struts has detected an unhandled exception:
  *Messages*:
No result defined for action
local.workgroup.tutorial.struts2.actions.HelloAction and result success


Even though the class is:


package local.workgroup.tutorial.struts2.actions;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;

public class HelloAction extends ActionSupport {

private static final long serialVersionUID = 1L;

private static final Logger logger = Logger.getLogger(HelloAction.class
.getName());

private String message;

public String execute() throws Exception {

logger.info("In execute method of class Hello");

message = "Hello from Struts 2 with no XML configuration.";

return SUCCESS;
}

public void setMessage(String message) {
this.message = message;
}

public String getMessage() {
return message;
}
}




The convention plugin doc also uses similar package naming method [3]. Did
I name the packages wrong or did I just stumble on a bug in 2.3.16?  Is
there a small print somewhere that I may missed regarding not able to use
package naming method similar to group ID + artifact ID in pom.xml?  If I
use struts.xml for the previous tutorials and not used convention plugin,
the package naming works fine.


Thanks,
Tommy


[1] https://cwiki.apache.org/confluence/display/WW/Struts+2+Annotations
[2] http://localhost:8080/annotations/config-browser/actionNames.action
[3] http://struts.apache.org/release/2.1.x/docs/convention-plugin.html

Re: Need help with Annotations Tutorial @ cwiki

Posted by Tommy Pham <to...@gmail.com>.
On Tue, Feb 18, 2014 at 10:55 PM, Lukasz Lenart <lu...@apache.org>wrote:

> 2014-02-19 6:21 GMT+01:00 Tommy Pham <to...@gmail.com>:
> > package local.workgroup.tutorial.struts2.actions;
>
> You are mixing the same locators and Struts doesn't know how to handle
> this. I mean it knows but it will create additional namespace
> /actions. Below you have default locators, change them just to
> action,actions
>
> struts.convention.package.locators = action,actions,struts,struts2
>
> http://struts.apache.org/release/2.3.x/docs/convention-plugin.html
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
>
Hi Łukasz,

Thanks for the reply.  Modifying the web.xml to:

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>struts.devMode</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>struts.convention.package.locators</param-name>
<param-value>action,actions</param-value>
</init-param>
</filter>

Did the trick!


Kind regards,
Tommy

Re: Need help with Annotations Tutorial @ cwiki

Posted by Lukasz Lenart <lu...@apache.org>.
2014-02-19 6:21 GMT+01:00 Tommy Pham <to...@gmail.com>:
> package local.workgroup.tutorial.struts2.actions;

You are mixing the same locators and Struts doesn't know how to handle
this. I mean it knows but it will create additional namespace
/actions. Below you have default locators, change them just to
action,actions

struts.convention.package.locators = action,actions,struts,struts2

http://struts.apache.org/release/2.3.x/docs/convention-plugin.html


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org