Skip to main content

faceletContext-> getFacesContext() -> getResponseWriter() is null --- WHY?

3 replies [Last post]
tahirraza
Offline
Joined: 2009-11-17

using: facelets, jsf2, tomcat

I am creating a TagHandler and I want to write back something through responseWriter().

When using UIComponent subclass, I can do this:

ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement("table", component); //bla bla bla

But why is faceletContext-> getFacesContext() -> getResponseWriter() NULL in TagHandler. How can i achieve what I am looking for?

Observation:
In TagHandler: com.sun.faces.context.FacesContext
In UIComponent: javax.faces.context.FacesContext.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tahirraza
Offline
Joined: 2009-11-17

Here is more detail:

My TagHandler is..

import com.sun.facelets.tag.TagHandler;
import com.sun.facelets.tag.TagConfig;
import com.sun.facelets.tag.TagAttribute;
import com.sun.facelets.FaceletContext;
import com.sun.facelets.FaceletException;

public class PortletSetDisplayTag extends TagHandler{

private FacesContext context;

public PortletSetDisplayTag(TagConfig tagConfig) {
super(tagConfig);

/* Initialize attributes */
}

public void apply(FaceletContext faceletContext, UIComponent component) throws IOException, FacesException, FaceletException, ELException {

faceletContext.getFacesContext().getResponseWriter().write("Hello"); //this is just bottom line what I trying to achieve
// but faceletContext.getFacesContext().getResponseWriter() is NULL
}

Taglib file:


"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">

http://tag.custom/wlec-tag

portletSetRenderer
com.legaledcenter.jsf.tag.PortletSetDisplayTag

When I use javax* classes, the server gives error:
SEVERE: Error Loading Library: /WEB-INF/taglib/portletSetDisplayTag.taglib.xml
java.io.IOException: Error parsing [jndi:/localhost/WEB-INF/taglib/portletSetDisplayTag.taglib.xml]:
at com.sun.facelets.compiler.TagLibraryConfig.create(TagLibraryConfig.java:410)

Caused by: org.xml.sax.SAXException: Error Handling jndi:/localhost/WEB-INF/taglib/portletSetDisplayTag.taglib.xml@9,90
at com.sun.facelets.compiler.TagLibraryConfig$LibraryHandler.endElement(TagLibraryConfig.java:271)

One more Observation:
I see this while starting tomcat 6:

WARNING: JSF1069: Disabling the JSF 2.0 Facelets ViewHandler as an older FaceletViewHandler, com.sun.facelets.FaceletViewHandler, has been explicitly configured. If this is not desired behavior, remove the older FaceletViewHandler and library from your application.

Please help!
Thanks

Ryan Lubke

The response writer typically isn't created until it's needed (i.e., the
render response phase).
That said, FacesContext.getResponseWriter() isn't responsible for
creating the writer,
so if you want to do some writing during the tag apply() call, you'll
need to get the ResponseWriter
from the desired RenderKit and pass it to the FacesContext.

On 11/19/09 12:28 PM, webtier@javadesktop.org wrote:
> Here is more detail:
>
> My TagHandler is..
>
>
> import com.sun.facelets.tag.TagHandler;
> import com.sun.facelets.tag.TagConfig;
> import com.sun.facelets.tag.TagAttribute;
> import com.sun.facelets.FaceletContext;
> import com.sun.facelets.FaceletException;
>
> public class PortletSetDisplayTag extends TagHandler{
>
> private FacesContext context;
>
> public PortletSetDisplayTag(TagConfig tagConfig) {
> super(tagConfig);
>
> /* Initialize attributes */
> }
>
>
>
>
> public void apply(FaceletContext faceletContext, UIComponent component) throws IOException, FacesException, FaceletException, ELException {
>
> faceletContext.getFacesContext().getResponseWriter().write("Hello"); //this is just bottom line what I trying to achieve
> // but faceletContext.getFacesContext().getResponseWriter() is NULL
> }
>
>
>
>
>
> Taglib file:
>
>
> > "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
> "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
>
> http://tag.custom/wlec-tag
>
> portletSetRenderer
> com.legaledcenter.jsf.tag.PortletSetDisplayTag
>

>

>
>
>
>
> When I use javax* classes, the server gives error:
> SEVERE: Error Loading Library: /WEB-INF/taglib/portletSetDisplayTag.taglib.xml
> java.io.IOException: Error parsing [jndi:/localhost/WEB-INF/taglib/portletSetDisplayTag.taglib.xml]:
> at com.sun.facelets.compiler.TagLibraryConfig.create(TagLibraryConfig.java:410)
>
> Caused by: org.xml.sax.SAXException: Error Handling jndi:/localhost/WEB-INF/taglib/portletSetDisplayTag.taglib.xml@9,90
> at com.sun.facelets.compiler.TagLibraryConfig$LibraryHandler.endElement(TagLibraryConfig.java:271)
>
> One more Observation:
> I see this while starting tomcat 6:
>
> WARNING: JSF1069: Disabling the JSF 2.0 Facelets ViewHandler as an older FaceletViewHandler, com.sun.facelets.FaceletViewHandler, has been explicitly configured. If this is not desired behavior, remove the older FaceletViewHandler and library from your application.
>
> Please help!
> Thanks
> [Message sent by forum member 'tahirraza' ]
>
> http://forums.java.net/jive/thread.jspa?messageID=372586
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

tahirraza
Offline
Joined: 2009-11-17

Thanks Ryan!!

That makes sense!

Tahir