如何在基于Struts桥梁的portlet链接中设置WindowState?
问题描述:
我正在开发基于struts 1.2.9的JSR-286标准portlet(由于历史原因,我们希望重复使用很多现有的代码)使用struts portlet桥梁。我想要一些链接来更改WindowState,但门户网桥提供的FormTag和LinkTag没有简单的方法来设置WindowState。我很高兴扩展这两个标记,但我不确定如何继续,我怎样才能确定哪些请求参数需要添加在门户不可知的方式?如何在基于Struts桥梁的portlet链接中设置WindowState?
答
哦,还不如回答我的问题:-)
我不得不创建基于(不扩展)的支柱桥码我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项目的补丁。