Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF: rendered attribute

Tags:

jsf

I have a panelGroup with a rendered attribute. Why is it that the component values in the panelGroup are even called if the rendered attribute is set to false? Do I missunderstand the rendered attribute here?

What I want to do is: I have a selectManyCheckbox before the panelGroup and everything in the panelGroup should only be executed if the user has chosen values in the selectManyCheckbox and hit a button. This won't work like this because the components in the panelGroup depend on the values the user has to choose in the selectManyCheckbox.

<h:selectManyCheckbox /> // for the user to choose
<h:commandButton /> // to render the panelGroup

<h:panelGroup rendered="#{someBean.render}">
  <h:dataTable value="#{someOtherBean.loadSomething(someObject)}" var="item">
    // ...
  </h:dataTable>         
</h:panelGroup>
like image 915
geeehhdaa Avatar asked Jun 07 '11 10:06

geeehhdaa


People also ask

What is rendered attribute in JSF?

You use the rendered attribute to include or exclude a component from a page, depending on a condition. Here, loggedIn is a boolean property in the user bean. JSF HTML tags have appropriate HTML 4.0 "pass-through" attributes.

What is the use of binding attribute in JSF?

A JSF "binding" is a binding of the actual JSF UI component to a property. In over 99 cases out of 100, you would use the "value=" attribute, since it's only the control's backing property value you care about dealing with in the backing bean.


1 Answers

The rendered attribute simply states if the following component should be rendered on the client side DOM. These components will still follow the JSF lifecycle events and will maintain the value of a managed bean.

EDIT: In response to a request for a workaround:

The simplest way I can see to workaround this, if you do not want the value attribute to invoke the bean method then simply wrap the logic in your bean method with an if check on the render condition.

public void loadSomething(Object someObject) {
  if (render()) {
    //Do loadSomething logic
  }
}
like image 58
maple_shaft Avatar answered Nov 15 '22 11:11

maple_shaft