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 7548171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:37:53+00:00 2026-05-30T09:37:53+00:00

Referring to this post on primefaces forum. Has someone got any idea how can

  • 0

Referring to this post on primefaces forum.
Has someone got any idea how can we use multiple datatable on the same page but only display the correct one?

My problem is that i have a view-Scoped bean whose properties contain data from different tables from a database. I have multiple datatables for data of each database table. Now i want to display the datatable on the basis value selected from <p:selectOneMenu> (encircled in red color).
this screenshot would explain a bit further.

image

  • 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-30T09:37:54+00:00Added an answer on May 30, 2026 at 9:37 am

    The basic approach would be to let the rendered attribute of the tables depend on the selected item of the menu.

    <p:selectOneMenu value="#{bean.table}">
        <f:selectItem itemValue="players" itemLabel="Players" />
        <f:selectItem itemValue="jobs" itemLabel="Jobs" />
        <f:selectItem itemValue="business" itemLabel="Business" />
        ...
        <p:ajax update="tables" />
    </p:selectOneMenu>
    
    <h:panelGroup id="tables">
        <p:dataTable value="#{bean.players}" rendered="#{bean.table == 'players'}">
            ...
        </p:dataTable>
        <p:dataTable value="#{bean.jobs}" rendered="#{bean.table == 'jobs'}">
            ...
        </p:dataTable>
        <p:dataTable value="#{bean.business}" rendered="#{bean.table == 'business'}">
            ...
        </p:dataTable>
        ...
    </h:panelGroup>
    

    This is easy to implement, but you end up with a lot of code in the view (which can of course be split over <ui:include> files). The more advanced and reuseable approach would be to let the value of the single table depend on the selected item of the menu and use <p:columns> to generate columns dynamically.

    <p:selectOneMenu value="#{bean.table}">
        <f:selectItems value="#{bean.tables}" />
        <p:ajax listener="#{bean.changeModel}" update="table" />
    </p:selectOneMenu>
    
    <p:dataTable id="table" value="#{bean.model}" var="item">
        <p:columns value="#{bean.columns}" var="column">
            <h:outputText value="#{item[column]}" />
        </p:columns>
    </p:dataTable>
    

    with something like:

    public void changeModel() {
        model = populateModelBasedOn(table);
        columns = populateColumnsBasedOn(table);
    }
    

    This only allows less fine-grained control whenever you want to add more specialized columns. You’d probably want to work with tag files instead.

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

Sidebar

Related Questions

Referring back to this SO post If there is a Grouping category Category which,
referring to yesterday's post, this woke me up this morning. Why does this actually
Referring to this question , how can i get the current page size in
Referring to this web site http://www.cplusplus.com/reference/std/utility/make_pair/ The std::make_pair has this signature (and possible implementation):
I'm referring to a problem similar to the one in this post , because
Currently i am referring to this post and am able to create a 2*2
Referring to this issue: How can I set a minimum length for a field
Referring to this post and this one . I'm trying to implement tag search
The post I am referring to is this. Not only does the first one
When referring to this post here: http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/ it tells you to run php -q

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.