0

I have a datatable that iterates over a list of rows.

For each row that the datatable renders, sometimes one of these rows also contains a sub-datatable.

I need to pre-initialize the rows in the sub-datatable with a value from the parent datatable's current row variable.

How can one call a function to initialize the nested datatable with a value from the parent datatable temporary variable? Thanks!!

Pseudocode:

<Datatable var="currentRow" value="#{**parentBean**.listOfRows}>
    <p:row> <p:column colspan="6">

        <Datatable var="details" value="#{**detailsBean**.listOfDetails}">

        <!-- stuff in listOfDetails needs to be created with a function
             call, passing in the value of "currentRow.rowId" -->

        </Datatable>

    </p:column></p:row>
</Datatable>
Mike
  • 609
  • 12
  • 36

1 Answers1

0

I realized i could just call a method on my bean and still return the list of items, so rather than referencing the list to enumerate over as a get, I call a method to create the list right there by querying the database in the method and returning the list.

[EDIT] - this is not working properly for me. Although it looked like it was working - the function is getting called 27 times instead of once..

Mike
  • 609
  • 12
  • 36
  • 1
    Better to preemptive populate the list in a good recursive query https://stackoverflow.com/questions/4740748/when-to-use-common-table-expression-cte. Way more preformant. And please post some code with this text. It is unclear to me how you solved it. – Kukeltje Jan 05 '19 at 07:54
  • don't have access to it at the moment - to explain better, I call a function in my datatable 'value' attribute, passing it currentRow.rowId. That function gets the list of items using rowId in the database and returns the List - then Datatable has its list in value to iterate over... – Mike Jan 06 '19 at 00:17
  • Actually, no- paging is not working correctly this way. Somehow my method is getting called 27 times (and querying 27 times when it should only be happening once).. – Mike Jan 08 '19 at 15:28
  • Remarkable is that I expected it to be called multiple times since the way you described you solved it (code is always better) implied that. – Kukeltje Jan 08 '19 at 15:35
  • Is there a way to get at the DataTable "var" (current loop variable) entity? When the lazy loader I have gets called, I need to construct my query using a field of the current loop variable entity. – Mike Jan 08 '19 at 15:50
  • Sorry, this is an answer, not a question... It is not good practice in Stackoverflow to ask questions in answers... AND it is totally unclear what you are asking the var of the datatable is in the variable that is declared in the var. But as I suggested. It is better to preemtive do the. == create a good model with parent child relations – Kukeltje Jan 08 '19 at 16:23
  • @Kukeljte, could you please post what you said first about preemptive populate? It was exactly what I needed, it just had to sink in how to do that with lazy loading. I just want to accept your answer. Thanks again! – Mike Jan 22 '19 at 05:45