1
votes

I've got a component on my form (id="theDocument") that I want to render differently under certain circumstances.

If 'myBean.theDocument' exists, I want it to render as a p:commandLink, but if it doesn't exist, I want it to render as plain text e.g. h:outputText.

This condition will change after a file upload (after the upload, myBean.theDocument will exist, so I want it to render as the p:commandLink).

So on my p:fileUpload, I have this kind of thing:

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

I've been using rendered="...", and update works fine for refreshing the value of an existing component. But how do I change the type of the component after an ajax update (or do I need to refresh the whole page and make the decision to render as text or a link in a more general way?

Thanks

1
If my question isn't clear, let me know and I will try to clarify it: was struggling to come up with the correct words to explain my problem...Richard

1 Answers

1
votes

Just have two conditionally rendered components in a common parent and update the common parent.

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