2009-06-23 7 views
0

Je développe un portlet compatible JSR-286 basé sur les entretoises 1.2.9 (pour des raisons historiques, nous voulons réutiliser beaucoup de code existant) en utilisant le pont de portlets struts. Je veux que certains liens changent le WindowState, mais le FormTag et le LinkTag fournis par le pont de portail n'ont pas un moyen facile de définir le WindowState. Je suis heureux d'étendre ces deux balises, mais je ne sais pas comment procéder, comment puis-je déterminer quels paramètres de requête doivent ajouter d'une manière agnostique de portail?Comment définir WindowState dans les liens de portlet basés sur un pont Struts?

Répondre

2

Eh bien, pourrait aussi bien répondre à ma propre question :-)

je devais créer mes propres versions de TagsSupport, FormTag et LinkTag sur la base (non extension) du code barres pont.

J'ai modifié les méthodes TagsSupport.getUrl() et TagsSupport.getFormTagRenderFormStartElement() pour accepter un paramètre WindowState et l'utiliser lors de la création d'URL de rendu et d'action.

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(); 
    } 
... 

et

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; 
} 

J'ai alors changé FormTag et LinkTag d'accepter un attribut WindowState et le transmettre aux méthodes TagsSupport.

private String windowState; 

public String getWindowState() { 
    return windowState; 
} 

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

et

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

Il est donc évident besoin d'un tld pour référencer mes tags modifiés.

Ceci a été fourni sous la forme d'un correctif PB-91 (incorporant également un correctif pour le changement de mode de portlet) au projet de pont Struts.

Questions connexes