How to set a variable in JSF?

My code here iterates over the columns for each row, and the rendered attribute rendered computed for each iteration, testRule .

 <p:dataTable ...> <p:column ...> ... </p:column> <p:column rendered="#{managedBean.testRule('rules.canDoActions')}"> <!-- Action buttons --> <h:commandButton ...> <h:commandButton ...> </p:column> </p:dataTable> 

To get better performance, I was interested in setting the result to a variable, but I don’t know how ... It will be something like this:

  <?:??? var="canDoActions" value="#{managedBean.testRule('rules.canDoActions')}"> <p:dataTable ...> <p:column ...> ... </p:column> <p:column rendered="#{canDoActions}"> <!-- Action buttons --> <h:commandButton ...> <h:commandButton ...> </p:column> </p:dataTable> 

Also, I'm not allowed to use the Core Tag Library, which means that <c:set ../> out of the question.

In this area, how can I set a variable? Or, if this is not possible, what do you propose to solve?

+4
source share
1 answer

I'm not allowed to use the Core tag library, which means that <c:set ../> out of the question

Then you can save it to a Bean and check if it is null calculateRules and set the value or just return.

Example:

 HashMap<String, Boolean> map; public boolean testRule(String stringInput) { Boolean result = map.get(stringInput); if (result == null) { //calculate and set in map } return result; } 
+5
source

Source: https://habr.com/ru/post/1387248/


All Articles