JSF + Primefaces: problem with "rendered" components with ajax

EDIT
Cant doesn't seem to allow rendered to work correctly with update attributes. Here are my codes

  <ui:define name="left"> <h:form> <p:commandLink value="Hey" actionListener="#{bean.setRenderComment}" update="comment"/> </h:form> </ui:define> <ui:define name="right"> <h:panelGroup id="comment" rendered="#{bean.renderComment}"> hello </h:panelGroup> </ui:define> 

renderComment are the boolean attributes inside the bean . setRenderComment basically toggles renderComment state like this

 this.renderComment = !this.renderComment; 

To the right, every time I click on the Hey link, I need to update or make the hello render on or off. How can I fix this so that I do not need to update

+4
source share
2 answers

I do not use Primefaces, but Richfaces in my projects. Therefore, I do not know how the update process is performed using Primefaces. However, I have an idea that can be easily tested.

Your problem may be due to the fact that the component for reprocessing (for example, updating) was not found on the HTML page. If your rendered attribute is false , then <SPAN> with comment id is not integrated into the generated HTML page. Thus, when an Ajax request is received on the client side, the Ajax mechanism cannot update this <SPAN> because it was not found.

So, you can always display panelGroup and move your rendered attribute to a nested <h:outputText> containing the Hello message.

Here is what I suggest:

 <h:panelGroup id="comment"> <h:outputText value="Hello" rendered="#{bean.renderComment}"/> </h:panelGroup> 

This way panelGroup will always be updated after an Ajax call and will contain a Hello message or not regarding the value of the renderComment attribute of your bean.

+13
source

Since the component with the comment identifier is not one of the child elements of the form (a UINamingContainer ), you need to attach the identifier with : to instruct JSF to scan from the "top level".

This should do:

 <p:commandLink value="Hey" actionListener="#{bean.setRenderComment}" update=":comment" /> 
+1
source

All Articles