I am developing a JSR-286 compliant portlet based on struts 1.2.9 (for historical reasons we want to reuse a lot existing code) using the struts portlet bridge. I want some links to change the WindowState, but the FormTag and LinkTag provided by the portal bridge don't have an easy way to set the WindowState. I'm happy to extend these two tags, but am unsure how to proceed, how can I determine what request parameters need adding in a portal agnostic way?
+1
A:
Oh well, might as well answer my own question :-)
I had to create my own versions of TagsSupport, FormTag and LinkTag based on (not extending) the struts bridge code.
I modified the methods TagsSupport.getUrl() and TagsSupport.getFormTagRenderFormStartElement() to accept a WindowState parameter and use it when creating render and action URLs.
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();
}
...
and
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;
}
I then changed FormTag and LinkTag to accept a WindowState attribute and pass it to the methods in TagsSupport.
private String windowState;
public String getWindowState() {
return windowState;
}
public void setWindowState(String windowState) {
this.windowState = windowState;
}
and
url = TagsSupport.getURL(pageContext, url, urlType, new WindowState(getWindowState()));
Obviously then needed a tld to reference my modified tags.
This has been supplied as a patch PB-91 (also incorporating a fix for changing portlet mode) to the struts bridge project.
Steve Bosman
2009-06-24 08:57:54