如何在基于Struts桥的portlet链接中设置WindowState?

时间:2009-06-23 09:52:31

标签: java struts portlet portals-bridge

我正在使用struts portlet桥开发基于struts 1.2.9的JSR-286兼容portlet(由于历史原因,我们希望重用大量现有代码)。我想要一些链接来更改WindowState,但门户网桥提供的FormTag和LinkTag没有一种简单的方法来设置WindowState。我很高兴扩展这两个标签,但我不确定如何继续,如何确定需要以门户无关的方式添加哪些请求参数?

1 个答案:

答案 0 :(得分:2)

哦,不妨回答我自己的问题:-)

我必须基于(不扩展)struts桥代码创建我自己的TagsSupport,FormTag和LinkTag版本。

我修改了方法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和LinkTag更改为接受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桥项目。