2

在我们的一个页面上,我们添加了一个AbstractAjaxTimerBehavior(将潜在的新项目添加到一个Repeatingview)。执行的 AJAX 调用如下:

https://.../home/?0-1.IBehaviorListener.0-filteredContentHandler&random=0.38872813899070024

但是,由于随机部分,此 URL 不是静态的。我也不确定是否?0-1总是一样。

Wicket 1.5 或 Wicket 6(我们可能会升级到)有没有办法为某个呼叫设置静态 URL?


(此要求的原因是将此 URL 提供给 Siteminder (SSO),以便 SSO 会话忽略这些 URL 以保持 SSO 会话活动)。

4

1 回答 1

0

回答我自己的问题:

public class AjaxTimerBehaviorMapper extends AbstractComponentMapper {

    private final IRequestMapper wrappedMapper;

    private final String prefix;

    /**
     * @param rootRequestMapper
     */
    public AjaxTimerBehaviorMapper(IRequestMapper wrappedMapper, String prefix) {
        this.wrappedMapper = wrappedMapper;
        this.prefix = prefix;
    }

    @Override
    public IRequestHandler mapRequest(Request request) {
        Url url = request.getUrl();
        if (url.getSegments().size() >= 1 && url.getSegments().get(0).equals(this.prefix)) {
            url.removeLeadingSegments(1);
        }
        return this.wrappedMapper.mapRequest(request.cloneWithUrl(url));
    }

    @Override
    public int getCompatibilityScore(Request request) {
        return this.wrappedMapper.getCompatibilityScore(request);
    }

    @Override
    public Url mapHandler(IRequestHandler requestHandler) {
        Url url = this.wrappedMapper.mapHandler(requestHandler);
        if (requestHandler instanceof ListenerInterfaceRequestHandler) {
            ListenerInterfaceRequestHandler listenerInterfaceRequestHandler = (ListenerInterfaceRequestHandler) requestHandler;

            RequestListenerInterface requestListenerInterface = listenerInterfaceRequestHandler.getListenerInterface();
            if (requestListenerInterface != null) {
                Class<? extends IRequestListener> listenerInterfaceClass = requestListenerInterface.getListenerInterfaceClass();
                if (IBehaviorListener.class.isAssignableFrom(listenerInterfaceClass)) {
                    IRequestableComponent requestableComponent = listenerInterfaceRequestHandler.getComponent();
                    if (requestableComponent != null) {
                        Integer behaviorIndex = listenerInterfaceRequestHandler.getBehaviorIndex();
                        Behavior behavior = requestableComponent.getBehaviorById(behaviorIndex);
                        if (behavior != null) {
                            if (AbstractAjaxTimerBehavior.class.isAssignableFrom(behavior.getClass())
                                || CustomAbstractAjaxTimerBehavior.class.isAssignableFrom(behavior.getClass())) {
                                url.prependLeadingSegments(newArrayList(this.prefix));
                            }
                        }
                    }
                }
            }
        }
        return url;
    }
}

这样,wicket 将在 url 中使用给定的固定前缀。

于 2013-02-07T12:40:13.160 回答