Problems hide / show a4j commandobutton

0

I have an "a4j commandButton" that I try to update from a combo that has the following event change so it can be seen on the screen:

<a4j:ajax render="modelNameNew, prueba " event="change" execute="@this" />

<a4j:commandButton id="prueba" action="..." oncomplete="..." rendered="#{!managedBean.Boolean}" />

It turns out that it does not update and does not update the rest of the elements that are behind that point on the screen, however previous elements such as the inputext below if they are updated.

<h:inputText id="modelNameNew" disabled="#{managedBean.Boolean}" />

On other screens I have the same casuistry and zero problems, everything is perfectly updated, the inputs are enabled and the buttons appear.

What can make the button is not pulling well in this case ?. Say that if instead of rendered, I use the disabled tag, there is no problem, the button is enabled and disabled accordingly.

    
asked by AuRiCaN 11.03.2016 в 12:57
source

1 answer

0

The problem is that you are confusing the concept of the attributes rendered and disabled of JSF.

rendered is an attribute of JSF. It means that the component will not be rendered, therefore the component will not be part of the TreeView that arms JSF behind the scenes, which means that the component can not be used to obtain its data or edit it. This can be checked simply by seeing the generated HTML, you will see that your component does not exist, as it does not exist, you can not apply any functionality via javascript or similar. That is why <a4j:ajax render="modelNameNew, prueba " event="change" execute="@this" /> fails.

disabled is an HTML attribute. It means that the component is disabled or not. When sending the data of the form to the server, by default the data of the components that are disabled will not be sent to the server. However, these components are rendered and can be accessed via JavaScript. That's why <a4j:ajax render="modelNameNew, prueba " event="change" execute="@this" /> works correctly for this component.

The problem with using rendered is very common when working with JSF. The solution is to use a UIContainer on the component that has the attribute rendered and re-render the UIContainer instead of re-rendering the component in question. In code it is better understood:

<!-- Se indica que se renderizará pruebaContainer, no prueba -->
<a4j:ajax render="modelNameNew, pruebaContainer" event="change" execute="@this" />
<!--
    Se crea un componente UIContainer que sirva como wrapper al componente a re-renderizar con el atributo rendered.
    En este caso, utilizaré un h:panelGroup y le pondré el id pruebaContainer
-->
<h:panelGroup id="pruebaContainer">
    <!-- Dentro del UIContainer colocamos el componente que necesita ser re-renderizado -->
    <a4j:commandButton id="prueba" action="..." oncomplete="..." rendered="#{!managedBean.Boolean}" />
</h:panelGroup>
    
answered by 11.03.2016 в 17:43