简体   繁体   中英

JSF2.0 Partial Render with ui:define

I'm using facelet templating and I think I'm running into an issue with ui:define and the JSF lifecycle. My template.xhtml contains a fixed menu in the header, simplified it has links like this:

<h:commandLink value="Click Me">
    <f:ajax update="#{myBean.listener}" render="contentpanel"/>
</h:commandLink>

The template.xhtml also contains a ui:insert statement:

<ui:insert name="content">
    <h:outputLabel value="content placeholder"/>
</ui:insert>

Now I have a content.xhtml which looks like:

<ui:composition template="template.xhtml">
    <ui:define name="content">
        <h:panelGroup id="contentpanel"/>
    </ui:define>
</ui:composition>

So much for the introduction. When I click the commandlink 'Click Me' I'm calling my listener. This listener sets a reference in a backingbean to dynamically load the content based on the link I clicked.

This rendering is not done the first time I press the commandlink. Well it basically looks like it first does the re-render and then call the listener instead of the other way around. So when I first click, nothing seems to happen. When I click for the second time I see the content that was set for the first click. When I click for the third time I see the content of the second click.

I think it's because the ui:define view is already re-built in the 'Restore View' phase of the JSF lifecycle. Any ideas on how to overcome this?

UPDATE

Seems like my assumption was wrong. The cause of this seems to be something different. The #{myBean.listener} has a @SessionScoped @ManagedProperty which is updated after the CommandLink is clicked. The contentpanel actually loads data via the #{myBean.data} which is @RequestScoped . This #{myBean.data} did not reload the data correctly. I solved it by passing the getData() method directly to the @SessionScoped bean.

Might be a bit confusing. But my conclusion: it does work to partial render a component which is loaded via facelet templating ( ui:define / ui:insert )

Seems like my assumption was wrong. The cause of this seems to be something different. The #{myBean.listener} has a @SessionScoped @ManagedProperty which is updated after the CommandLink is clicked. The contentpanel actually loads data via the #{myBean.data} which is @RequestScoped. This #{myBean.data} did not reload the data correctly. I solved it by passing the getData() method directly to the @SessionScoped bean.

Might be a bit confusing. But my conclusion: it does work to partial render a component which is loaded via facelet templating (ui:define / ui:insert)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM