2012-11-22 154 views
2

在我們的其中一個網頁上,我們添加了一個AbstractAjaxTimerBehavior(將潛在的新項目添加到Repeatingview)。執行的AJAX調用如下:自定義AJAX網址

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

但是,由於隨機部分,此URL不是靜態的。我也不確定?0-1是否總是相同。

Wicket 1.5或Wicket 6(我們可能會升級到)爲某個呼叫設置靜態URL嗎?


(這樣做的原因要求是提供這個網址的SiteMinder(SSO),以使SSO會話無視這些URL的保持SSO會話的存活)。

+0

您需要使鏈接無狀態。見http://stackoverflow.com/questions/10582601/how-can-i-make-wickets-ajaxlink-stateless – Jonathan

回答

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; 
    } 
} 

這樣檢票口將使用給定的固定前綴的網址。