简体   繁体   English

Stripe不会将事件与{$ event}绑定

[英]Stripe does not bind de event with {$event}

I'm new to stripes, so I'm sorry if it is a easy question, right now I have this class: 我是条纹的新手,所以很抱歉这是一个简单的问题,现在我有这个课程:

 ....
 import net.sourceforge.stripes.action.DefaultHandler;
 import net.sourceforge.stripes.action.DontValidate;
 import net.sourceforge.stripes.action.ForwardResolution;
 import net.sourceforge.stripes.action.HandlesEvent;
 import net.sourceforge.stripes.action.RedirectResolution;
 import net.sourceforge.stripes.action.Resolution;
 import net.sourceforge.stripes.action.UrlBinding;
 import net.sourceforge.stripes.integration.spring.SpringBean;
 import net.sourceforge.stripes.validation.ValidationMethod;
 import net.sourceforge.stripes.validation.ValidationState;

@UrlBinding("/role/{$event}")
public class RoleActionBean extends BaseActionBean {

    @DefaultHandler @DontValidate
    @HandlesEvent("add")
    public Resolution listrole() {
        ...
        return new ForwardResolution("/jsp/role/list.jsp");
    }

    @HandlesEvent("add") @DontValidate
    public Resolution addrole() {
        ...
        return new ForwardResolution("/jsp/role/add.jsp");
    }

    @HandlesEvent("save")
    public Resolution saverole() 
    {
        ...
    }

    @HandlesEvent("view") @DontValidate
    public Resolution viewrole() {
        ...
    }

    @HandlesEvent("edit") @DontValidate
    public Resolution editrole() {
        ...
    }

    @HandlesEvent("update")
    public Resolution updaterole() {
        ...
    }

    @HandlesEvent("delete")
    public Resolution deleterole() {
        ...
    }



    @ValidationMethod(on={"save", "update"}, when=ValidationState.ALWAYS)
    public void validarDatosrole(){
        ... 
    }


    @ValidationMethod(on={"save", "update"}, when=ValidationState.ALWAYS)
    public void validarDatosrole2(){
        ...
    }

    ...
}

But when I try to, access the ActionBean to the url: 但是,当我尝试访问URL时,请访问ActionBean:

/role/add /角色/添加

Or any other of the events, I get the 404, I'm trying to get more clean URL so it will be more easy to restrict the users which action can use with spring security, before I have it working with: 或其他任何事件,我得到404,我试图获取更干净的URL,以便在我使用它之前更容易地限制用户可以在spring security中使用的操作:

@UrlBinding("/role.html")

and going to the URL: 并转到URL:

role.html?add role.html?添加

I'm not sure what I'm doing wrong, please help me, thanks in advance. 我不确定自己在做什么错,请帮助我,谢谢。

I believe it is because you have two handler methods for the add event. 我相信这是因为您为add事件有两个处理程序方法。 This causes stripes to fail to startup with the following exception (and then respond to all requests with a 404 because the servlet failed to start up) 这将导致条带无法启动,并出现以下异常(然后由于Servlet无法启动而用404响应所有请求)

2016-05-27 08:53:22,850 FATAL {main} [] net.sourceforge.stripes.controller.StripesFilter Could not instantiate specified Configuration. Class name specified was [net.sourceforge.stripes.config.RuntimeConfiguration].
net.sourceforge.stripes.exception.StripesRuntimeException: Problem instantiating default configuration objects.
    at net.sourceforge.stripes.config.DefaultConfiguration.init(DefaultConfiguration.java:210)
    at net.sourceforge.stripes.config.RuntimeConfiguration.init(RuntimeConfiguration.java:276)
    at net.sourceforge.stripes.controller.StripesFilter.createConfiguration(StripesFilter.java:137)
    at net.sourceforge.stripes.controller.StripesFilter.init(StripesFilter.java:103)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:298)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:119)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4076)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4730)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: net.sourceforge.stripes.exception.StripesRuntimeException: Could not instantiate configured ActionResolver of type [UIActionResolver]. Please check the configuration parameters specified in your web.xml.
    at net.sourceforge.stripes.config.RuntimeConfiguration.initializeComponent(RuntimeConfiguration.java:257)
    at net.sourceforge.stripes.config.RuntimeConfiguration.initActionResolver(RuntimeConfiguration.java:119)
    at net.sourceforge.stripes.config.DefaultConfiguration.init(DefaultConfiguration.java:102)
    ... 20 more
Caused by: net.sourceforge.stripes.exception.StripesRuntimeException: The ActionBean class example.site.actions.help.RecordsAction declares multiple event handlers for event 'add'
    at net.sourceforge.stripes.controller.AnnotatedClassActionResolver.processMethods(AnnotatedClassActionResolver.java:233)
    at net.sourceforge.stripes.controller.AnnotatedClassActionResolver.addActionBean(AnnotatedClassActionResolver.java:152)
    at net.sourceforge.stripes.controller.AnnotatedClassActionResolver.init(AnnotatedClassActionResolver.java:119)
    at net.sourceforge.stripes.controller.NameBasedActionResolver.init(NameBasedActionResolver.java:125)
    at net.sourceforge.stripes.config.RuntimeConfiguration.initializeComponent(RuntimeConfiguration.java:253)
    ... 22 more

dhensche is correct that you have too many add handlers in the code you posted. dhensche是正确的,因为您发布的代码中有太多的添加处理程序。

If we assume that's just a copying error and your ActionBean was usable prior to your UrlBinding change, I think you may want to look at your servlet mapping configuration. 如果我们假设这只是一个复制错误,并且您的ActionBean在更改UrlBinding之前可用,那么我认为您可能希望查看servlet映射配置。

Since your link will no longer contain ".action", web requests may not know how to reach the StripesDispatcher, and that's why you're getting a 404 response. 由于您的链接将不再包含“ .action”,因此Web请求可能不知道如何到达StripesDispatcher,这就是为什么您收到404响应的原因。

This blog post has a detailed example of what you're trying to do: Clean and usable URLs in Stripes 这篇博客文章详细介绍了您要执行的操作: Stripes中干净且可用的URL

Also, you might want to consider naming your resolution methods to match the events they handle, and ditching the HandlesEvent annotations. 另外,您可能要考虑命名解析方法以匹配它们处理的事件,并放弃HandlesEvent注释。 Then it won't be possible to accidentally define duplicate handlers. 这样就不可能意外地定义重复的处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM