views:

228

answers:

2

EDIT
Cant seem to get rendered to work correctly with update attributes. Here is 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 is a boolean attributes inside bean. setRenderComment basically toggle the state of renderComment like this

this.renderComment = !this.renderComment;

Right, every time I click on the link Hey, I need to refresh to either render hello on or off. How can I fix it, so that I dont need to refresh

+1  A: 

Since the component with the ID comment isn't one of the form's (an UINamingContainer component) children, you need to prefix the ID with : to instruct JSF to scan from the "upper level".

This should do:

<p:commandLink value="Hey"
    actionListener="#{bean.setRenderComment}"
    update=":comment" />
BalusC
Ohh wow. I did not know that `update` only work on the same level. What if I have multiple levels. I try `::comment`, but it does not work. Can u take a look at my updated post, please?
Harry Pham
@Harry: romaintaz has nailed it down.
BalusC
+2  A: 

I am not using Primefaces but Richfaces on my projects. So I am not really aware on how the refresh process is done by Primefaces. However, I have an idea that can be tested easily.

Your problem may be due to the fact that the component to re-render (i.e. update) is not found on the HTML page. If your rendered attribute is equals to false, then the <SPAN> with comment id is not integrated in the HTML page generated. Thus, when the Ajax request is received on the client side, the Ajax engine is not able to refresh this <SPAN> as it is not found.

So what you can do is to always render your panelGroup and move your rendered attribute to a nested <h:outputText> that contains the Hello message.

Here is what I am suggesting:

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

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

romaintaz
Thank you. It works :). I reason why I use `panelGroup` is because, I have many component that I want to `render` on or off using just one `rendered` attributes. If I have to do this, I guess, I might as well just take the `panelGroup` out. Thanks a lot man :D
Harry Pham