0

I have currently the following code:

     <h:form id="activitiesListForm" rendered="#{activitiesRequestByObjectController.init('BOOKING_DATE', bookingDateEditController.bookingDate.id)}">

  <p:dataTable id="activitiesListDatatable" value="#{activitiesRequestByObjectController.lazyModel}" var="activities"                            rows="50">
                                        <p:column sortBy="#{activities.activityActionType}"
                                            visible="true">
                                            <f:facet name="header">
                                                <h:outputText value="Aktion" />
                                            </f:facet>

                                        </p:column>
    </p:datatable>
    </h:form>

In my backend bean I have the following code:

 public boolean init(String activityType, Long id) {

        LOGGER.info("START init");
        LOGGER.info("activityType: " + activityType);
        LOGGER.info("id: " + id);

// loadContent from database

This code works and I got the result what I would like to have, but if I have a look in the log, I see that the function in the backend is called many times which is bad. I can generate many backend classes to load the content, e.g. for BOOKING_DATE, CUSTOMER etc. - but I want to avoid this, because otherwise I will have around 100 classes with moreless the same content, only with other parameters.

My question is, is there any possibility to have only one class to load the content from: activitiesRequestByObjectController.lazyModel

but with different parameters or avoid that the backend bean is loaded many times. The best would be if I can have still the function: #{activitiesRequestByObjectController.init('BOOKING_DATE', bookingDateEditController.bookingDate.id)} , loading only one time and get the result.

Any ideas?

vished2000
  • 164
  • 1
  • 11
  • You could implement pattern DTO, which is creating a class that contains ALL the parameters or atleast the most important ones of the objects that you receive, for example their IDS, names, transaction value, etc. Watever you consider important, and so you populate your datatable with objects of that class (DTO) and thats it – BugsForBreakfast Jan 11 '20 at 16:57
  • not sure what you mean exactly... I have in my database two fields: entityType (could be BOOKING_DATE e.g.) and objectId -> this can be the bookingDate.id – vished2000 Jan 11 '20 at 17:20
  • remove the arguments from the methods and get them in the method. add `@PostConstruct` to the method so it is loaded only once each bean creation ([see this](https://stackoverflow.com/questions/16542003/jsf-what-is-the-difference-between-postconstruct-and-direct-method-call-from)) – fuggerjaki61 Jan 11 '20 at 20:09
  • Ok, I can do this - but the main question is: how can I get the arguments than in the @ PostConstruct function. As far as I know @ PostConstruct cannot have a parameter? – vished2000 Jan 11 '20 at 20:41
  • do it 'lazy' then... like referred to in https://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times – Kukeltje Jan 12 '20 at 08:30

0 Answers0