Hi again,

Another thing I had to do to ease JSP development.

3) I wrote a replacement of the JSF link tag that works in both servlet
and portlet environments seamlessly (actually I develop most of the code
as plain standalone application and then portalize it). In a portlet
context, JSP are passed as "VIEW_ID" to the MyFaces portlet, so when if
you have a JSP and you want to link to another JSP in your application,
you need to construct the special portal URL. 

You might put something like this in tomahawk (if it's not already
there, but I didn't find anything).

Here is my code....(ignore the ELSupport stuff, I just add JSTL EL
support to all my tags, I find it idiotic that almost none of the JSF
tag attributes accept runtime expressions ):

public class UILinkTag extends HtmlOutputLinkTag
{
        private String target;
        
        private String relativeToAbsolute(FacesContext ctx, String
value)
        {
                String relativePath = ctx.getViewRoot().getViewId();
                relativePath = relativePath.substring(0,
relativePath.lastIndexOf('/'));
                return relativePath + "/" + value;              
        }
        
        public void setValue(String value)
        {
        FacesContext context = FacesContext.getCurrentInstance();

                if (UIComponentTag.isValueReference(value)) {
            ValueBinding vb =
                context.getApplication().createValueBinding(value);
            value = (String)vb.getValue(context);
        }
        else if (ELSupport.isEL(value))
                value = (String)ELSupport.eval(value, String.class,
pageContext);
                
                if (value != null && value.length() > 0 &&
value.indexOf("://") == -1)
                {
                        if (!value.startsWith("/")) 
                                value = relativeToAbsolute(context,
value);
                        if (context.getExternalContext() != null && 
                context.getExternalContext().getResponse() instanceof
RenderResponse)
                        {
                                if (target == null)
                                {
                                        PortletURL url =
((RenderResponse)context.getExternalContext().getResponse()).createRende
rURL();
        
url.setParameter(MDCPortlet.VIEW_ID, value);
                                        value = url.toString();
                                }
                                else
                                        value =
context.getExternalContext().encodeResourceURL(value);
                        }
            else if (value != null && value.length() > 0)
                value = "/faces" + value;
                }
                super.setValue(value);
        }
        
        public void setTarget(String target)
        {
                this.target = target;
                if (target.length() == 0)
                        target = null;
                super.setTarget(target);
        }
}

-----Original Message-----
From: Mike Kienenberger [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 13, 2006 12:22 PM
To: MyFaces User mailing list
Subject: Portlet examples needed by portlet/MyFaces users

We've had a number of bugs posted by users of MyFaces who are also
using Portlets.

Would one of those users like to contribute some MyFaces portlet
examples to aid us in fixing and debugging your issues?   I don't
think any of the currently-active MyFaces committers are using
portlets, so it's hard for us to see your problems or test patches.

Thanks!

Reply via email to