Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:48:01+00:00 2026-05-24T16:48:01+00:00

I’m just learning JSF 2 thanks to this site I had learned a lot

  • 0

I’m just learning JSF 2 thanks to this site I had learned a lot in such a short time.

My question is regarding how to implement a common layout to all my JSF 2 pages and have only the content part of the page refresh not the whole page whenever I click a link/menu from a different panel. I am using the Facelets approach it does what I want except that each time I click a link from a panel (e.g. menu items from left panel) the whole page is refreshed. What I am looking for is a way to refresh only the content part of my page. To illustrate this below is my target pagelayout.

enter image description here
Did not post my code because I’m not sure if Facelets can do this . Are there other approach more suited for my requirement other than Facelets?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:48:03+00:00Added an answer on May 24, 2026 at 4:48 pm

    A straightforward approach would be the following view:

    <h:panelGroup id="header" layout="block">
        <h1>Header</h1>
    </h:panelGroup>
    <h:panelGroup id="menu" layout="block">
        <h:form>
            <f:ajax render=":content">
                <ul>
                    <li><h:commandLink value="include1" action="#{bean.setPage('include1')}" /></li>            
                    <li><h:commandLink value="include2" action="#{bean.setPage('include2')}" /></li>            
                    <li><h:commandLink value="include3" action="#{bean.setPage('include3')}" /></li>            
                </ul>
            </f:ajax>
        </h:form>
    </h:panelGroup>
    <h:panelGroup id="content" layout="block">
        <ui:include src="/WEB-INF/includes/#{bean.page}.xhtml" />
    </h:panelGroup>
    

    With this bean:

    @ManagedBean
    @ViewScoped
    public class Bean implements Serializable {
    
         private String page;
    
         @PostConstruct
         public void init() {
             page = "include1"; //  Default include.
         }
    
         // +getter+setter.
     }
    

    In this example, the actual include templates are include1.xhtml, include2.xhtml and include3.xhtml in /WEB-INF/includes folder (folder and location is fully free to your choice; the files are just placed in /WEB-INF in order to prevent direct access by guessing the URL in browser’s address bar).

    This approach works in all MyFaces 2.x versions, but requires in case of Mojarra a minimum of 2.3.x. In case you’re using a Mojarra version older than 2.3.0, then this all fails when the <ui:include> page in turn contains a <h:form>. Any postback will fail because it is totally missing the view state. You can solve this by upgrading to minimally Mojarra 2.3.0 or with a script found in this answer h:commandButton/h:commandLink does not work on first click, works only on second click. Or, if you’re already using PrimeFaces and exclusively use <p:xxx> ajax, then it’s already transparently taken into account.

    Also, make sure that you’re using minimally Mojarra 2.1.18 as older versions will fail in keeping the view scoped bean alive, causing the wrong include being used during postback. If you can’t upgrade, then you’d need to fall back to the below (relatively clumsy) approach of conditionally rendering the view instead of conditionally building the view:

    ...
    <h:panelGroup id="content" layout="block">
        <ui:fragment rendered="#{bean.page eq 'include1'}">
            <ui:include src="include1.xhtml" />
        </ui:fragment>
        <ui:fragment rendered="#{bean.page eq 'include2'}">
            <ui:include src="include2.xhtml" />
        </ui:fragment>
        <ui:fragment rendered="#{bean.page eq 'include3'}">
            <ui:include src="include3.xhtml" />
        </ui:fragment>
    </h:panelGroup>
    

    The disadvantage is that the view would become relatively large and that all associated managed beans may be unnecessarily initialized even though when they would not be used as per the rendered condition. See also JSTL in JSF2 Facelets… makes sense? for an in depth explanation on <ui:include src="#{...}"> vs <x:someComponent rendered="#{...}">.

    As to positioning of the elements, that’s just a matter of applying the right CSS. That’s beyond the scope of JSF 🙂 At least, <h:panelGroup layout="block"> renders a <div>, so that should be good enough.

    Last but not least, this SPA (Single Page Application) approach is not SEO friendly. All the pages are not indexable by searchbots nor bookmarkable by endusers, you may need to fiddle around with HTML5 history in client and provide a server side fallback. Moreover, in case of pages with forms, the very same view scoped bean instance would be reused across all pages, resulting in unintuitive scoping behavior when you navigate back to a previously visited page. I’d suggest to go with templating approach instead as outlined in 2nd part of this answer: How to include another XHTML in XHTML using JSF 2.0 Facelets? See also How to navigate in JSF? How to make URL reflect current page (and not previous one).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.