Yeah... that's what I think too.

-----Original Message-----
From: Jeff Bischoff [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 12, 2006 17:05
To: MyFaces Discussion
Subject: Re: Problem with <jsp:include/>

CD,

Okay, this is an alternative way to do this. However, in your solution 
there must be a separate include for each possible content page. In your 
code snippet, there are 2, but in reality there would be 50. And each 
subview would need to point to a separate booleanShown1() method, 
resulting in 50 additional methods.

If that works for you, great. I feel a value-binding expression is more 
flexible for my needs, since I don't have to modify the outer template 
pages to add new content pages.

<jsp:include page="${navigation.contentPage}" />

One include, instead of 50. :)

Both approaches work, it's really a matter of taste.

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

CD wrote:
> To clarify on my post a bit...
>  
> I did not include full code as maybe I should have.  The way we 
> accomplish this task is
>  
> <f:subview id="subView1" rendered="#{bean.booleanShown1}">
>     <jsp:include page="viewPage1"/>
> </f:subview>
> <f:subview id="subView2" rendered="#{bean.booleanShown2}">
>     <jsp:include page="viewPage2"/>
> </f:subview>
>  
>  
>  
> This approach does work for our needs....  however, maybe I don't 
> understand what is attempting to be done in this case.  I apologize for 
> the lack of good code snippet previously.  I will admit that it did look 
> bad and was not explained clearly.
>  
> Regards,
> CD
>  
> 
> 
>  
> On 9/12/06, *Jeff Bischoff* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
>      > 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 ??
>      >
> 
>     Gladly, no... this is not the only solution. It's not what we are doing
>     either! :)
> 
>     Let me explain a little further...
> 
>     When you don't specify an id for a component, it gets auto-generated an
>     id like "_idJsp134". But the container ids are concatenated, so inside
>     form MyForm, you get an id like MyForm:_idJsp134. The problem comes in
>     when you include a new page, and e.g. something that maybe was a
>     inputText before is now a selectOneMenu.
> 
>     Subviews are the answer to this problem, but only if you use them in a
>     certain way. If you following CD's pattern, the subview ID gets appended
>     but it doesn't help. This is because both pages are being included
>     from the same line. Using his pattern, you might get the following ids
>     for the components on the two different pages:
> 
>     MyForm:subviewID:_idJsp134
>     MyForm:subviewID:_idJsp134
> 
>     They are still not unique. If you instead follow the pattern I laid out
>     in my last post, you will get the following ids:
> 
>     MyForm:Payments:_idJsp134
>     MyForm:Balances:_idJsp134
> 
>     Now these IDs will not conflict. Even though they are not hard-coded,
>     and get auto-assigned the same _idJsp134 id, the appending of a
>     distinct
>     subview ID differentiates them. Therefore, you are free to use
>     components without a hard-coded id.
> 
>     Hope this clarifies a bit?
> 
>     Regards,
> 
>     Jeff Bischoff
>     Kenneth L Kurz & Associates, Inc.
> 
>     Bieringer, Dominik wrote:
>      > 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]
>     <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]
>     <mailto:[EMAIL PROTECTED]>]
>      >> *Sent:* Monday, September 11, 2006 15:47
>      >> *To:* MyFaces Discussion; [EMAIL PROTECTED]
>     <mailto:[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]> <mailto: [EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>>*
>      >> <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>     <mailto:[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]>
>     <mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>>
>      >> Datum: 11.09.2006 12:16
>      >> An: "MyFaces Discussion"<[email protected]
>     <mailto:[email protected]>
>      >> <mailto:[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]> <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]>
>      >> <mailto:[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]
>     <mailto:[EMAIL PROTECTED]>>
>      >>
>      >>     *To:* [email protected]
>     <mailto:[email protected]> <mailto:[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
>     <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