2009-06-23 80 views
0

我正在開發基於struts 1.2.9的JSR-286標準portlet(由於歷史原因,我們希望重複使用很多現有的代碼)使用struts portlet橋樑。我想要一些鏈接來更改WindowState,但門戶網橋提供的FormTag和LinkTag沒有簡單的方法來設置WindowState。我很高興擴展這兩個標記,但我不確定如何繼續,我怎樣才能確定哪些請求參數需要添加在門戶不可知的方式?如何在基於Struts橋樑的portlet鏈接中設置WindowState?

回答

2

哦,還不如回答我的問題:-)

我不得不創建基於(不擴展)的支柱橋碼我TagsSupport,FormTag和鏈接標記的自己的版本。

我修改了TagsSupport.getUrl()和TagsSupport.getFormTagRenderFormStartElement()方法來接受一個WindowState參數,並在創建渲染和動作URL時使用它。

public static String getURL(PageContext pageContext, String url, PortletURLTypes.URLType type, WindowState ws) 
... 
    if (type.equals(PortletURLTypes.URLType.ACTION)) 
    { 
     final PortletURL portletURL = StrutsPortletURL.createActionURL(pageContext.getRequest(), url); 
     if (ws!=null) { 
     try { 
      portletURL.setWindowState(ws); 
     } 
     catch (WindowStateException e) { 
      e.printStackTrace(); 
     } 
     } 
     return portletURL.toString(); 
    } 
    else if (type.equals(PortletURLTypes.URLType.RENDER)) 
    { 
     final PortletURL portletURL = StrutsPortletURL.createRenderURL(pageContext.getRequest(), url); 
     if (ws!=null) { 
     try { 
      portletURL.setWindowState(ws); 
     } 
     catch (WindowStateException e) { 
      e.printStackTrace(); 
     } 
     } 
     return portletURL.toString(); 
    } 
... 

public static String getFormTagRenderFormStartElement(PageContext pageContext, String formStartElement, WindowState ws) 
{ 
    if (PortletServlet.isPortletRequest(pageContext.getRequest())) 
    { 
     int actionURLStart = formStartElement.indexOf("action=") + 8; 
     int actionURLEnd = formStartElement.indexOf('"', actionURLStart); 
     String actionURL = formStartElement.substring(actionURLStart, 
       actionURLEnd); 
     final PortletURL portletURL = StrutsPortletURL.createActionURL(pageContext.getRequest(), 
                    actionURL); 
     if (ws!=null) { 
     try { 
      portletURL.setWindowState(ws); 
     } 
     catch (WindowStateException e) { 
      e.printStackTrace(); 
     } 
     } 
     formStartElement = formStartElement.substring(0, actionURLStart) 
       + portletURL.toString() 
       + formStartElement.substring(actionURLEnd); 
    } 
    return formStartElement; 
} 

我再變FormTag和鏈接標記以接受的WindowState屬性並將其傳遞給在TagsSupport方法。

private String windowState; 

public String getWindowState() { 
    return windowState; 
} 

public void setWindowState(String windowState) { 
    this.windowState = windowState; 
} 

url = TagsSupport.getURL(pageContext, url, urlType, new WindowState(getWindowState())); 

顯然則需要一個TLD引用我的修改標籤。

這是作爲補丁PB-91(也包含修改portlet模式的修補程序)提供給struts bridge項目的補丁。