You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jake Vang <va...@googlemail.com> on 2010/06/29 13:28:22 UTC

convention plugin requires setting @Result explicitly

i have an Action class in the package
com.company.web.struts.actions.admin.LoginAction. inside LoginAction,
i use Annotation to specify the Action (i.e. @Action(value="/login")
on a method. according to the documentation at,
http://struts.apache.org/2.1.8.1/docs/convention-plugin.html, this
should map to /admin/login (i.e.
http://localhost:8080/webapp/admin/login, on Tomcat). however, i keep
seeing the message below.

No result defined for action
com.company.web.struts.actions.admin.LoginAction and result success

this message goes away if i specify the result explicitly (i.e.
@Action(value="/login",results={@Result(name="success",location="login-success.jsp")}).
BUT, why do i have to explicitly specify the result? doesn't this
defeat the purpose of the Convention plugin?

for all my Action classes, so far, and using the Convention plugin, i
just simply specify @Action(value="/something"), and it is smart
enough to forward to /something-success.jsp, /something-error.jsp,
/something-input.jsp, etc... without any explicit setting of the
@Result. any ideas is appreciated.

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


Re: convention plugin requires setting @Result explicitly

Posted by Jake Vang <va...@googlemail.com>.
i've been reading the doc over and over. and something is not working.
according to the doc, you can specify the Namespace and ResultPath in
the package-info.java file.

@Namespace("/admin")
package my.package

theoretically, all action class under this package (just this package
and no sub-packages) will now have this default namespace. however,
annotating at the package level inside package-info.java does not
work. i keep getting the exception "No result defined for action ...
and result success" for my action class. the URL mapping is working
(it says so in the doc), but now it is having trouble finding the
resource (i.e. login-success.jsp). from reading the doc, the
convention plugin will look for the resource in
/WEB-INF/content/admin/login-success.jsp. but this is not the case, it
will actually look for the resource in
/WEB-INF/content/login-success.jsp. unless you explicitly use the
@Result annotation, then it will look at the default result path. but
that is annoying because you have already specified the Namespace at
the package level, but now you have to explicitly specify the view at
the method level? completely doesn't make any sense to me at all.

when i annotate Namespace at the class/Action level, then everything
works as intended. the expected location of the resource is read (i.e.
/WEB-INF/content/admin/login-success.jsp). i guess i will have to live
with this approach for now and annotate the namespace for every
action.

@Namespace("/admin")
public class LoginAction

if anyone has a good explanation please share. i've consulted 3
different books but unfortunately, they only deal with XML files. it's
kinda silly that there are few published reference material outside of
the struts 2 website dealing with annotations and the convention
plugin.



On Tue, Jun 29, 2010 at 7:28 AM, Jake Vang <va...@googlemail.com> wrote:
> i have an Action class in the package
> com.company.web.struts.actions.admin.LoginAction. inside LoginAction,
> i use Annotation to specify the Action (i.e. @Action(value="/login")
> on a method. according to the documentation at,
> http://struts.apache.org/2.1.8.1/docs/convention-plugin.html, this
> should map to /admin/login (i.e.
> http://localhost:8080/webapp/admin/login, on Tomcat). however, i keep
> seeing the message below.
>
> No result defined for action
> com.company.web.struts.actions.admin.LoginAction and result success
>
> this message goes away if i specify the result explicitly (i.e.
> @Action(value="/login",results={@Result(name="success",location="login-success.jsp")}).
> BUT, why do i have to explicitly specify the result? doesn't this
> defeat the purpose of the Convention plugin?
>
> for all my Action classes, so far, and using the Convention plugin, i
> just simply specify @Action(value="/something"), and it is smart
> enough to forward to /something-success.jsp, /something-error.jsp,
> /something-input.jsp, etc... without any explicit setting of the
> @Result. any ideas is appreciated.
>

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