Quantcast

Tiles2 2.0.5 - JSF RI 1.2 - inlineContent

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Tiles2 2.0.5 - JSF RI 1.2 - inlineContent

Holger Igel

I have a (simple) question:

I want to use a definition with an inline content. This content contains jsf
tags. This doesn't work. If I use the value attribute of tiles:putAttribute
and insert the content of another file, everything works fine.
I've pasted the file with inline content (welcome.jsp) and with included
content (welcome2.jsp and body.jsp)
I'm getting the following stacktrace:



02.11.2007 18:31:57 org.apache.tiles.jsp.taglib.RenderTagSupport doCatch
SCHWERWIEGEND: Error during rendering
javax.servlet.jsp.JspException: java.lang.IllegalStateException: Component
javax.faces.component.UIViewRoot@1500efd not expected type.  Expected:
javax.faces.component.UIOutput.  Perhaps you're missing a tag?
        at
com.sun.faces.taglib.html_basic.OutputTextTag.doStartTag(OutputTextTag.java:
170)
        at
org.apache.jsp.welcome_jsp._jspx_meth_h_005foutputText_005f0(welcome_jsp.jav
a:195)
        at
org.apache.jsp.welcome_jsp._jspx_meth_tiles_005fputAttribute_005f0(welcome_j
sp.java:157)
        at
org.apache.jsp.welcome_jsp._jspx_meth_tiles_005finsertDefinition_005f0(welco
me_jsp.java:108)
        at org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java:68)
        at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:3
93)
        at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:206)
        at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.
java:654)
        at
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDis
patcher.java:445)
        at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatch
er.java:379)
        at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher
.java:292)
        at
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:
415)
        at
com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandler
Impl.java:458)
        at
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:12
6)
        at
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java
:110)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
        at
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:175)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128
)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102
)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http
11Protocol.java:584)
        at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalStateException: Component
javax.faces.component.UIViewRoot@1500efd not expected type.  Expected:
javax.faces.component.UIOutput.  Perhaps you're missing a tag?
        at
com.sun.faces.taglib.html_basic.OutputTextTag.setProperties(OutputTextTag.ja
va:126)
        at
javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassi
cTagBase.java:614)
        at
javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTa
gBase.java:1136)
        at
com.sun.faces.taglib.html_basic.OutputTextTag.doStartTag(OutputTextTag.java:
164)
        ... 35 more





My file welcome.jsp (which doesn'work):



<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>

<tiles:insertDefinition name="default.definition" >
        <tiles:putAttribute name="body">
       
        <h:outputText value="hOutputText !!!!"></h:outputText>
                <h1>test</h1>
                        <h5>H5</h5>
        </tiles:putAttribute>
       
</tiles:insertDefinition>


My file welcome2.jsp (works)


<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>


<tiles:insertDefinition name="default.definition" >
        <tiles:putAttribute name="body" value="/body.jsp" />
</tiles:insertDefinition>


My file body.jsp (works)


<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ page import="java.util.Date;" %>

<h:outputText value="hOutputText !!!!"></h:outputText>
<h1>testH1</h1>
<h5>H5</h5>
<%= new Date() %>
                       


And my file layout.jsp




<%@ page session="false" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>

<f:view>
<html>
<head>
        <f:subview id="htmlheader">
                <tiles:insertAttribute name="htmlheader" flush="false"/>
        </f:subview>

</head>

<body>


        <h:panelGrid columns="1">
                        <f:facet name="header">
                                <f:subview id="header">
                                        <tiles:insertAttribute name="header"
flush="false"/>
                                </f:subview>
       

                                           
                        </f:facet>
               
               
                       
                       
                        <f:subview id="body">
                                <tiles:insertAttribute name="body"
flush="false"/>
                        </f:subview>
                       
                       
                       
                        <f:facet name="footer">
                                <f:subview id="footer">
                                        <tiles:insertAttribute name="footer"
flush="false"/>
                                </f:subview>
                        </f:facet>
                       
                </h:panelGrid>

       
</body>
</html>

</f:view>









My file Tiles-defs.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>

<definition name="default.definition" template="/layout/layout.jsp">
      <put-attribute name="htmlheader"  value="/inc/htmlhead.jsp"/>
      <put-attribute name="header" value="/inc/header.jsp"/>
      <put-attribute name="body" value="/home2.jsp"/>
      <put-attribute name="footer"   value="/inc/footer.jsp"/>
</definition>


</tiles-definitions>




Of course someone knows the cause of this problem. It seems to be that the
inline content is modified by tiles2 ?!


Holger


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Tiles2 2.0.5 - JSF RI 1.2 - inlineContent

Antonio Petrelli-3
2007/11/2, Holger Igel <[hidden email]>:

>
> I have a (simple) question:
>
> I want to use a definition with an inline content. This content contains jsf
> tags.
> ...
>         <tiles:putAttribute name="body">
>
>         <h:outputText value="hOutputText !!!!"></h:outputText>
>                 <h1>test</h1>
>                         <h5>H5</h5>
>         </tiles:putAttribute>

The problem is that inline content is evaluated and, after that, put
as a string in the attribute.
In your case, the <h:outputText> needs the <f:view> tag as a parent
(if I am not wrong). Since it cannot find it, it throws an exception.
The other solution (with the insertion of an URL) it works because it
works just like a <jsp:include>: the JSP code is evaluated in the
whole evaluation cycle.
IOW I think it is not a bug, but a characteristic you have to live with :-(

HTH
Antonio
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

AW: Tiles2 2.0.5 - JSF RI 1.2 - inlineContent

Holger Igel


2007/11/2, Holger Igel <[hidden email]>:
>
> I have a (simple) question:
>
> I want to use a definition with an inline content. This content contains
jsf
> tags.
> ...
>         <tiles:putAttribute name="body">
>
>         <h:outputText value="hOutputText !!!!"></h:outputText>
>                 <h1>test</h1>
>                         <h5>H5</h5>
>         </tiles:putAttribute>

The problem is that inline content is evaluated and, after that, put
as a string in the attribute.
In your case, the <h:outputText> needs the <f:view> tag as a parent
(if I am not wrong). Since it cannot find it, it throws an exception.
The other solution (with the insertion of an URL) it works because it
works just like a <jsp:include>: the JSP code is evaluated in the
whole evaluation cycle.
IOW I think it is not a bug, but a characteristic you have to live with :-(

HTH
Antonio

==========================================================================

Thank you Antonio.
If the inline content is evaluated before it is inserted in the attribute, I
believe I have to embedded the jsf content in <f:view> or <f:subview> tag.
I used the <f:view> tag
     
<tiles:putAttribute name="body">
        <f:view>
         <h:outputText value="hOutputText !!!!"></h:outputText>
                 <h1>test</h1>
                         <h5>H5</h5>
        </f:view>
</tiles:putAttribute>

But the inline content must be passed through. I'm getting following error:

Error during rendering
javax.servlet.jsp.JspException: Can't write content above <f:view> tag
Illegal to flush within a custom tag
        at
com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:186)
...


Is it possible to handle the body content of <tiles:putAttribute> like the
<jsp:include> with an url (your second solution) ? This would be very nice
and avoids using 2 files...

Regards
Holger


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Tiles2 2.0.5 - JSF RI 1.2 - inlineContent

Antonio Petrelli-3
2007/11/5, Holger Igel <[hidden email]>:
>
> javax.servlet.jsp.JspException: Can't write content above <f:view> tag
> Illegal to flush within a custom tag



Mmmm...  the <f:view> tag is trying to flush the stream... that's strange...
I don't know much of JSF, is <f:subview> applicable here?


> Is it possible to handle the body content of <tiles:putAttribute> like the
> <jsp:include> with an url (your second solution) ? This would be very nice
> and avoids using 2 files...



I meant that was *your* second solution, i.e. when you used:
<tiles:insertAttribute name="body" value="/body.jsp" />

Antonio
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

AW: Tiles2 2.0.5 - JSF RI 1.2 - inlineContent

Holger Igel

2007/11/5, Holger Igel <[hidden email]>:
>>
>> javax.servlet.jsp.JspException: Can't write content above <f:view> tag
>> Illegal to flush within a custom tag



> Mmmm...  the <f:view> tag is trying to flush the stream... that's
>strange...
>I don't know much of JSF, is <f:subview> applicable here?

I used <f:subview> as well, but the content wasn't rendered.


>> Is it possible to handle the body content of <tiles:putAttribute> like
the
>> <jsp:include> with an url (your second solution) ? This would be very
nice
>> and avoids using 2 files...



> I meant that was *your* second solution, i.e. when you used:
> <tiles:insertAttribute name="body" value="/body.jsp" />

>Antonio

If I use this solution, I have to create two files: the
"<tiles:insertDefinition>"-file and the "content"-file(body.jsp). I wanted
to merge these two files. Any idea ?

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Tiles2 2.0.5 - JSF RI 1.2 - inlineContent

Nicolas LE BAS
In reply to this post by Antonio Petrelli-3
Antonio Petrelli a écrit :

> 2007/11/5, Holger Igel <[hidden email]>:
>  
>> javax.servlet.jsp.JspException: Can't write content above <f:view> tag
>> Illegal to flush within a custom tag
>>    
>
>
>
> Mmmm...  the <f:view> tag is trying to flush the stream... that's strange...
> I don't know much of JSF, is <f:subview> applicable here?
>
>
>  
>> Is it possible to handle the body content of <tiles:putAttribute> like the
>> <jsp:include> with an url (your second solution) ? This would be very nice
>> and avoids using 2 files...
>>    
>
>
>
> I meant that was *your* second solution, i.e. when you used:
> <tiles:insertAttribute name="body" value="/body.jsp" />
>
> Antonio
>
>  
Only one <f:view> is allowed per request. It must be the outermost of
all JSF-tags.

<f:subview> is allowed anywhere ; it may help you here but won't be a
neat solution to the problem. JSF expects that the tags are executed in
the correct order when building the component tree. You may have to
design an entirely new tag and JSF component ("tiles:putSubView /
tiles:insertSubView"?) in order to make it work correctly in every
situations...

If you really need inline contents with JSF tags in them, you may want
to look at facelets... but facelets is not based on JSP, it's an
entirely different servlet templating engine...

Hope this helps,
Nick
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Tiles2 2.0.5 - JSF RI 1.2 - inlineContent

Antonio Petrelli-3
2007/11/5, Nicolas LE BAS <[hidden email]>:
>
> <f:subview> is allowed anywhere ; it may help you here but won't be a
> neat solution to the problem. JSF expects that the tags are executed in
> the correct order when building the component tree. You may have to
> design an entirely new tag and JSF component ("tiles:putSubView /
> tiles:insertSubView"?) in order to make it work correctly in every
> situations...



Mmm it seems like a job for MyFaces Tomahawk...
Thanks Nicolas :-)

Antonio
Loading...