JSF2.0部分渲染UI:定义 [英] JSF2.0 Partial Render with ui:define
问题描述
我使用的facelet模板,我想我运行到一个问题,用户界面:定义和JSF生命周期。我template.xhtml包括在头一个固定的菜单,简化它具有像这样的链接:
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>
本的template.xhtml还包含一个用户界面:插入语句:
The template.xhtml also contains a ui:insert statement:
<ui:insert name="content">
<h:outputLabel value="content placeholder"/>
</ui:insert>
现在我有一个content.xhtml它看起来像:
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>
这么多的介绍。当我点击commandlink点击我我打电话给我的听众。此侦听器设置在backingbean参考依据我点击了链接,动态加载内容。
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.
这呈现不这样做,我第一次preSS的commandlink。那么它基本上看起来像它首先做了重新渲染,然后调用的另一种方法监听,而不是围绕。所以,当我第一次点击,似乎什么都没有发生。当我点击了我第二次看到,是为第一次点击设置内容。当我点击第三次我看到的第二次点击的内容。
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.
我想这是因为用户界面:定义视图已经重新建在JSF生命周期的恢复视图阶段。任何想法如何克服呢?
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?
更新
好像我的假设是错误的。这样做的原因似乎是不同的东西。该#{myBean.listener}
有一个 @SessionScoped @ManagedProperty
的CommandLink点击之后被更新。该的ContentPanel实际上是通过加载数据#{myBean.data}
是 @RequestScoped
。这#{myBean.data}
没有正确地重新加载数据。我通过直接传递的getData()
方法将 @SessionScoped
豆解决了这个问题。
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.
可能会有点混乱。但我的结论:不工作,部分渲染它通过的facelet模板加载的组件( UI:定义/ UI:插入
)
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
)
推荐答案
好像我的假设是错误的。这样做的原因似乎是不同的东西。在#{} myBean.listener有@SessionScoped @ManagedProperty的CommandLink被点击后更新。该的ContentPanel实际上是通过#{myBean.data}这是@RequestScoped加载数据。这个#{myBean.data}没有正确地重新加载数据。我通过直接传递getData()方法的@SessionScoped bean的解决了这个问题。
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.
可能会有点混乱。但我的结论是:它不工作,部分呈现其通过的facelet模板加载的组件(UI:定义/ UI:插入)
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)
这篇关于JSF2.0部分渲染UI:定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!