Hi,

Wow.... thanks for your answer!!! It's really great! You are totally right 
about the things you have said, ... 

I've tried assigning all my components in the subviews id="" attributes before 
(sorry for forgetting to mention that), and yes, it worked that way... But 
that's much work and it doesn't look good having an id attribute assigned on 
every component... but if there's no other way ?!?

Thanks for the great approach to solve the problem with the initialization of 
the JSF managed bean... I've solved it with having code like that at the top of 
the main.jsp page:

<%
        SessionTracker tracker = BeanResolver.getSessionTracker();
        String tmp = tracker.getContentPage();
%>

BeanResolver is using FacesContext to resolve the bean. And then using:

<jsp:include page='<%= tmp %>'/>

But your approach is much more straight forward... I think I will replace that 
part of my code.

I'm having the <f:subview/> tags inside the pages which I am including... and 
yes, I was very very carefully with writing the pages (hehe)... I am not even 
using any html tags in my code... 

You are right... I am not including the same jsf page more than once, so there 
is no problem with having <f:subview/> tags with the same id...

So, using hard coded id's for every component on my included pages (And that 
are a lot.. I have about 50 pages or more) is the only solution? You are using 
hard coded ids for every component ??

Dominik


-----Original Message-----
From: Jeff Bischoff [mailto:[EMAIL PROTECTED] 
Sent: Monday, September 11, 2006 19:08
To: MyFaces Discussion
Subject: Re: Problem with <jsp:include/>

Dominik,

Our web application has the same behaviour that you are trying to 
create. We have many different tabs, each of which dynamically includes 
various pages depending on the menu buttons they click. (we even use the 
same method name, setContentPage() heh)

We've been running such a way for over 6 months now, with no problems 
since the first few days. You have to be very careful about how you 
manage your subviews. These problems you are seeing occur when 
components are using generated ids, and on a subsequent display a new 
component is getting the same id that was assigned to a different 
component before. Hard-coding IDs can help, but this would be a severely 
painful solution in this case.

CD told you to:

 > subview tags go around the <jsp:include> in your page i.e.
 >
 > <f:subview id="subviewID">
 >     <jsp:include page=" f.jsp"/>
 > </f:subview>
 >

I'm sorry CD, but for what Dominik is trying to do this is WRONG!! It 
will result in his included page getting the same subview ID every time, 
which is causing his problems. Normally yes, that is the best practice 
way to include a page, but not when the included content will change 
drastically in structure.

Dominik, you need to follow this pattern for inclusion:

Including page
--------------
<f:attribute name="Content" value="#{navigation.contentPage}" />
<jsp:include page="${navigation.contentPage}" />

--------------


Included (content) pages
--------------
<f:subview id="Payments">
...content...
</f:subview>

Included page #2
--------------
<f:subview id="Balances">
...other content...
</f:subview>


The subview tags need to be in the *included* pages. Each subview needs 
a distinct id, ensuring that the components on the dynamically-included 
pages also get unique ids. My f:attribute tag serves only to ensure that 
navigation managed-bean has been instantiated before the JSTL-el call - 
avoiding a NPE. But you've probably already crossed that bridge.

In your case, I doubt that you will include the same content-page more 
than once at a time. If you do, you will need to wrap the include with 
an *additional* subview tag, with a different id for each one. The key 
here is preventing duplicate component ids on the content pages.

Hope this helps.

Best regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.


Bieringer, Dominik wrote:
> Okay... what I have posted here is a simple example...
> 
> In my application I am currently developing, there is a String property: 
> (getContentPage()) on a session bean.
> 
>  
> 
> I have several pages, for example:
> 
>  -> Downloads
> 
>  -> Customers
> 
>  -> Home
> 
>  -> ... etc.
> 
>  
> 
> If a user clicks on Downloads, setContentPage("downloads.jsp") is called 
> and the next time the page is rendered,
> 
> <jsp:include ...../> includes downloads.jsp...
> 
>  
> 
> I've not tried using the rendered attribute, because it's not possible 
> in my case...
> 
> But thanks for your idea.
> 
>  
> 
> ------------------------------------------------------------------------
> 
> *From:* CD [mailto:[EMAIL PROTECTED]
> *Sent:* Monday, September 11, 2006 15:47
> *To:* MyFaces Discussion; [EMAIL PROTECTED]
> *Subject:* Re: RE: Problem with <jsp:include/>
> 
>  
> 
> Have you tried making use of the "rendered" attribute on the subview tag 
> to determine which page to include?  I would also recommend 
> encapsulating the logic used to determine the boolean value in the bean.
> 
>  
> 
> On 9/11/06, [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>* 
> <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:
> 
> 
> 
> I can confirm
> 
> - multiple jsp:include's
> - session scope bean
> - subview does not fix it.
> 
> ----Ursprüngliche Nachricht----
> Von: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> Datum: 11.09.2006 12:16
> An: "MyFaces Discussion"<[email protected] 
> <mailto:[email protected]>>
> Betreff: RE: Problem with <jsp:include/>
> 
> I?ve tried that too, but that does not solve the problem? same results
> 
>  
> 
> ------------------------------------------------------------------------
> 
> *From:* CD [mailto: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>]
> 
> 
> *Sent:* Monday, September 11, 2006 09:42
> *To:* MyFaces Discussion
> 
> *Subject:* Re: Problem with <jsp:include/>
> 
>  
> 
> subview tags go around the <jsp:include> in your page i.e.
> 
> <f:subview id="subviewID">
>     <jsp:include page=" f.jsp"/>
> </f:subview>
> 
> Then f.jsp just needs to contains the content you would like to render.
> 
> HTH
> 
> On 9/11/06, *Jordan Laughlin* < [EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
> I can confirm I have experienced this problem as well. Page experienced 
> VERY weird behavior when using multiple <jsp:include> statements.
> 
>  
> 
> You might want to consider using <%@ include %> if you can't find a 
> solution.
> 
>  
> 
> -JL
> 
>  
> 
> ----- Original Message -----
> 
>     *From:* Bieringer, Dominik <mailto:[EMAIL PROTECTED]>
> 
>     *To:* [email protected] <mailto:[email protected]>
> 
>     *Sent:* Sunday, September 10, 2006 11:37 PM
> 
>     *Subject:* Problem with <jsp:include/>
> 
>      
> 
>     Hi!
> 
>      
> 
>     I have a problem with using <jsp:include> on my JSF pages. I am
>     sorry for having created an JIRA issue () before asking here on the
>     user mailing list (I've not known about this mailing list). Okay, so
>     here is my problem:
> 
>      
> 
>     I am having many pages, with one master page (in this example
>     test.jsp). In my real world application, the master page is
>     including other JSF pages. The page to include is determined by a
>     String property of a session bean. So, when a user clicks on a link
>     in the navigation menu, a property in a session bean is set and the
>     next time the page is loaded, this page get's included, rendered,
>     and sent to the client. (In my example I am including 2 different
>     pages 0.jsp and 1.jsp depending on Math.random() to simulate what I
>     want to do in my real world application).
> 
>      
> 
>     This worked fine for some time, but in the last weeks I've watched
>     some strange behavior. Some elements (like <h:outputText/>, ?) have
>     been rendered twice, or in the wrong order, ? and sometimes there
>     was a duplicate_id exception? So I tried to figure out what is going
>     wrong and realized, that there is something about the <jsp:include>.
>     If I use JSP include for one page? (for example 1.jsp) ? and in the
>     next request I am including the same page, and in the next request
>     the same page, and so on? everything works as expected, but when I
>     include another page, this strange behaviour occurs?
> 
>      
> 
>     I am not sure about what the problem is and I've read the JSF
>     Reference implementation and I think I've done everything like
>     described there. I've attached a very very simple example of what I
>     am trying to do. You have to click on the button some times, until
>     another page gets rendered, and you can see, that the BEFORE and
>     AFTER label are positioned wrong ! (The MMMMMM label has to be
>     between them). I've removed the libraries in my example to keep it
>     small. I've used Sun RI because it's the same problem that I have
>     when using MyFaces (In my real world application I am using MyFaces
>     (And I really like it!!!)).
> 
>      
> 
>     Okay, I hope you can help me, because I am already very frustrated?.
> 
>     Thanks for your help in advance, (If you need anything, please let
>     me know)
> 
>      
> 
>     Dominik
> 
>      
> 
>      
> 
>      
> 
>      
> 
>     Because I was not able to attach my file, here are the files and
>     there contents:
> 
>      
> 
>     ---
> 
>      
> 
>     Test.jsp (This is the first page)
> 
>      
> 
>     <%@ page contentType="text/html; charset=Cp1252" %>
> 
>     <%@ taglib uri="http://java.sun.com/jsf/html
>     <http://java.sun.com/jsf/html>" prefix="h"%>
> 
>     <%@ taglib uri="http://java.sun.com/jsf/core
>     <http://java.sun.com/jsf/core>" prefix="f"%>
> 
>      
> 
>     <%       long i = Math.round(Math.random());  %>
> 
>      
> 
>     <html>
> 
>                 <head><title>test_ri</title></head>
> 
>                
> 
>                 <body>
> 
>                             <f:view>
> 
>                                         <h:panelGrid width="100%"
>     columns="1">
> 
>      
> 
>                                                                
>     <jsp:include page='<%= "" + (i++) + ".jsp" %>'/>
> 
>      
> 
>                                                                
>     <h:outputText value="before"/>
> 
>                                                                
>     <jsp:include page='f.jsp'/>
> 
>                                                                
>     <h:outputText value="after"/>
> 
>                                                                
> 
>                                         </h:panelGrid>
> 
>                             </f:view>
> 
>                 </body>
> 
>     </html>
> 
>      
> 
>     ---
> 
>      
> 
>     f.jsp
> 
>      
> 
>     <%@ taglib uri="http://java.sun.com/jsf/html
>     <http://java.sun.com/jsf/html>" prefix="h"%>
> 
>     <%@ taglib uri="http://java.sun.com/jsf/core
>     <http://java.sun.com/jsf/core>" prefix="f"%>
> 
>      
> 
>     <f:subview id="pagef">
> 
>                 <h:panelGrid columns="1" width="100%">
> 
>                             <h:outputText value="MMMMMMMMMMMMMMMM"/>
> 
>                 </h:panelGrid>
> 
>     </f:subview>
> 
>      
> 
>     ---
> 
>      
> 
>     1.jsp
> 
>      
> 
>     <%@ taglib uri="http://java.sun.com/jsf/html
>     <http://java.sun.com/jsf/html>" prefix="h"%>
> 
>     <%@ taglib uri="http://java.sun.com/jsf/core
>     <http://java.sun.com/jsf/core>" prefix="f"%>
> 
>      
> 
>     <f:subview id="page1">
> 
>                 <h:panelGrid>
> 
>                             <h:outputText value="hi 1"/>
> 
>                             <h:form>
> 
>                                         <h:commandButton value="hi"/>
> 
>                             </h:form>
> 
>                             <h:outputText value="hi 2"/>
> 
>                             <h:outputText value="hi 3"/>
> 
>                             <h:outputText value="hi 4"/>
> 
>                             <h:outputText value="hi 5"/>
> 
>                 </h:panelGrid>
> 
>     </f:subview>
> 
>      
> 
>     ---
> 
>      
> 
>     0.jsp
> 
>      
> 
>     <%@ taglib uri="http://java.sun.com/jsf/html
>     <http://java.sun.com/jsf/html>" prefix="h"%>
> 
>     <%@ taglib uri="http://java.sun.com/jsf/core
>     <http://java.sun.com/jsf/core>" prefix="f"%>
> 
>      
> 
>     <f:subview id="page0">
> 
>                 <h:panelGrid>
> 
>                             <h:outputText value="ZERS asdfasdf"/>
> 
>                             <h:form>
> 
>                                         <h:commandButton value="hi"/>
> 
>                             </h:form>
> 
>                 </h:panelGrid>
> 
>     </f:subview>
> 
>  
> 
> 
> 
>  
> 
>  
> 





Reply via email to