• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Add jsf or primefaces components in a template and add them to header

 
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to add a image carousel in all my pages. So I tried templating it with <ui:repeat /> in a common header file. I also included them in html tag with xmlns:h, xmlns:p etc.. and tried adding the contents to <body>. But the template wasn't added to the main page. Any Ideas why?
 
Ranch Hand
Posts: 82
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose you have a file "carousel.xhtml",

Do you want to include it in a template file "template.xhtml" that it's used by the other pages?

In this case, just use <ui:include> :

this example include a file in the head with a collection of css and js inclusions and a file in the body containing the header , in you case that file can be "carousel.xhtml"
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
daniele licitra,

I know that I should use <ui:include>, that is how I am inserting. Can you please show me the code of resources.xhtml and header.xhtml? That is where I have the doubt. I think you are inserting the script and css files in resources.xhtml and carousel in header.xhtml. Am I right? I don't want the contents but I want to see how you have included the tags.
 
daniele licitra
Ranch Hand
Posts: 82
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course!

This is _resources.xhtml




The pages start with <ui:composition> and after i wrote the code directly.
There are problem if you write <h:head> or <h:body> in the included page: if you use h:heador h:body in the resultant page will be 2 body or 2 head, so primefaces have problem to manage components
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
daniele licitra,

Thanks this is what I needed. So we can include stylesheets and js in templates. I will try it and let you know. And one more doubt is have you added <h:form> inside the template and does it work. I will try that too but just asking your experience.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
daniele,

I tried the including stylesheets and scripts in a template it worked. Thanks a lot but the form doesn't work when I add in a template. What I did was added the logout <h:commandLink> in a template and called the backing bean method to invalidate the session. But error thrown is that the backing bean method is not found. Here is my code

template.xhtml


LoginBean.java
 
daniele licitra
Ranch Hand
Posts: 82
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had too a logout button in the template, inside a h:form but i don't remember if i get problem.

You can check:

  • 1) If the web page was shown, open the source code (from browser) and investigate if the form and the link was correctly rendered;
    2) Are there nested forms?
    3) Check if the LoginBean was created: are there problem with the constructor or the postConstructor? For experience, most of times I had that problem because i made error in the constructor of beans. To test it, create a property String test and a getter method and put it in the template and in the included page.


  • Another way, you can simply put the form and the button in a page like _logout.xhtml and use inclusion in template

    This solution provided smaller xhtml pages and focused on a concern... if you want to change logout in a button, you need only to modify _logout.xhtml


    NB: pay attention with primefaces and multiple forms, with prepended id on component ;)
     
    Partheban Udayakumar
    Ranch Hand
    Posts: 499
    Spring AngularJS Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    daniele licitra,

    I don't know how but it works now thank you so much.
     
    Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic