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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:27:18+00:00 2026-05-26T06:27:18+00:00

In two other questions ( here and here ) BalusC makes a straight up

  • 0

In two other questions (here and here) BalusC makes a straight up declaration:

Getters are solely there to access bean properties, not to do some business logic. There you have the bean constructor, initialization blocks or event methods for. All are executed only once during bean’s life and that’s exactly what you want.

Well gee — this just invalidated a gazillion lines of code I have already written. Ok, then, what is the correct way of implementing a backing bean that fills a data table? I understand his point and the concept, but not the practice. My question is twofold:

  1. Why is the way I am doing it wrong?
  2. How do I fix it?

I use PrimeFaces p:dataTable a lot, and it’s value attribute resolves to a collection. For reasons I don’t go into here, I do not use PrimeFaces’ lazy table loading feature. Instead I implement my own filter/sort controls, but they trigger AJAX events, which then results in the table being filled with records fetched from the data base.

The table is marked up like this:

 <p:panel id="mqTable">

   <h:outputText value="Sort/Filter: #{maintCategory.tableQueryParameters}" />

   <p:dataTable
      id="mqDataTable"
      rows="#{maintCategory.pageSize}"
      value="#{maintCategory.dataModel}"
      selection="#{maintCategory.selected}"
      var="cat"
      selectionMode="single"
      emptyMessage="No Categories Found">

Now the INCREDIBLY BAD UN-JSFish (or so I just found out) getter for dataModel goes like this:

public ATMDataModel getDataModel() {
    TableQueryParameters p = getTableQueryParameters();
    if (p.isChangePending()) clearDataModel();
    p.setChangePending(false);
    if (dataModel != null) return dataModel;
    List<ET> list = getDAO().runQuery(p);
    if (p.isNeedResultSize()) p.setResultSize(getDAO().runQueryCount(p));
    dataModel = new ATMDataModel(list);
    return dataModel;
}

A few explanations.

  1. This is from an abstract super-class where ET is the “Entity Type.” All my CRUDs use this same routine.
  2. The class ATMDataModel is a wrapper for the list which implements SelectableListModel. The row selection logic in PrimeFaces requires this. (It is a pain that appeared in PF 3 but it makes row selection work more reliably.)
  3. The class TableQueryParameters is something I wrote to encapsulate the current state of the table on the user’s screen. It includes what sort parameters, what filter parameters, what page we are on, etc. Because this needs to be preserved, the backing bean is ViewAccesScoped (via MyFaces CODI) and the TableQueryParameters is a property within it.
  4. The TableQueryParameters are updated in response via AJAX events, which also update the form causing getDataModel to be called. The method isChangePending goes true when anything changes. So the getDataModel method uses this to generate only one fetch from the DAO between changes no matter how many times it is called.

BUT if the TableQueryParameters do change, I have to call runQuery with those parameters to fetch the new set of records the user wants to see. If I don’t call it in getDataModel where do I call it?

Please advise.

  • 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-26T06:27:18+00:00Added an answer on May 26, 2026 at 6:27 am

    You’re basically lazily loading the data in the getter. You’re not hitting the DB on every getter call within the same request (or view) scope. This is affordable. I don’t use CODI, but I’d imagine that the getTableQueryParameters() call is also particularly cheap and nothing to worry about.

    As to the concrete question, you’d normally do the DB/business job in an action(listener) method which is attached to the UICommand component and/or the ajax event tag.

    For example (works also as <p:commandButton action> though)

    <p:ajax listener="#{bean.deleteSelectedRow}" />
    ...
    <p:ajax listener="#{bean.saveRowDetail}" />
    

    with

    public void deleteSelectedRow() {
        someService.delete(selectedRow);
        dataModel = loadDataModel();
    }
    
    public void saveRowDetail() {
        someService.save(selectedRow);
        dataModel = loadDataModel();
    }
    

    Depending on the meaning of p.isChangePending(), I think you could also get rid of it this way, it look like that you were setting it in the action(listener) methods.

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

Sidebar

Related Questions

I haven't seen any other questions quite like this on here, but I'm hoping
The below code is from my other questions that I have asked here on
I have tried solving this problem by posting other related questions here that focused
Like many other people posting questions here, I recently started programming in Python. I'm
Two (related?) questions here. I was trying to write a program to start an
I know this looks similar to other questions here but I don't think my
I know there are a bunch of other questions on this. The problem I'm
Looking at other questions here they seem to report setInterval is disabled or slowed
I've read several other questions on this topic ( here , here , and
There are some related questions here and here , but they didn't really give

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.