在ajax更新上更改组件类型

时间:2012-10-26 13:53:10

标签: ajax jsf-2 primefaces

我的表单上有一个组件( id =“theDocument”),我想在某些情况下以不同的方式呈现。

如果' myBean.theDocument '存在,我希望它呈现为 p:commandLink ,但如果它不存在,我希望它呈现为纯文本,例如 H:。的outputText

这种情况会在文件上传后发生变化(上传后, myBean.theDocument 将存在,所以我希望它呈现为 p:commandLink )。< / p>

所以在我的 p:fileUpload 上,我有这样的事情:

<p:fileUpload fileUploadListener="#{myBean.handleFileUpload}" update="theDocument">  

我一直在使用render =“...”,并且更新可以正常刷新现有组件的值。但是如何在ajax更新后更改组件的类型(或者我是否需要刷新整个页面并决定以更一般的方式呈现为文本或链接?

由于

1 个答案:

答案 0 :(得分:1)

在公共父级中只有两个有条件渲染的组件,并更新公共父级。

<h:panelGroup id="theDocument">
    <p:commandLink ... rendered="#{not empty myBean.theDocument}" />
    <h:outputText ... rendered="#{empty myBean.theDocument}" />
</h:panelGroup>