gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:37:40 25 4
gpt4 key购买 nike

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

最佳答案

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

我必须基于(而不是扩展)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()));

显然需要一个顶级域名来引用我修改过的标签。

这已作为补丁提供 PB-91 (还包含了更改 portlet 模式的修复程序)到 struts 桥接项目。

关于java - 如何在基于 Struts 桥的 portlet 链接中设置 WindowState?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1031622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com