I am trying to toggle a page that shows a <rich:dataTable>
. Before I just included the <ui:include>
template and it would just show the table the whole time.
<ui:include src="../log/viewDlg.xhtml"/>
Now I want to be able to toggle it on/off on the web-page. Showing on the page with maybe a button or link. How can I achieve it?
Update 1: I am unable to get it to show up for some odd reason, Here is what I wrote so far based on feed back
View:
<a4j:commandLink value="View"
action="#{bean.showview}" render="viewPanel"/>
<h:panelGroup id="viewPanel">
<h:panelGroup id="tableRenderPanel" rendered="#{bean.showPolicyView}">
<ui:include src="../log/viewDlg.xhtml"/>
</h:panelGroup>
</h:panelGroup>
Backing bean:
private boolean showPolicyView = false;
public void showView() {
showPolicyView = !showPolicyView;
}
public boolean isShowPolicyView(){
return showPolicyView;
}
Wrap your
<ui:include>
inside two<h:panelGroup>
elements. There's a catch here, you can't rerender a conditional component. Why's this? because when the element'srendered
attribute resolves tofalse
, it will not be considered while rendering the view so it can't be the target of an operation (in this case, related to renderization).Jumping to the code, you'll have this:
yourBean#renderTable
is aBoolean
property that determines if the component will be rendered. When it evaluates tofalse
, the component is not included in the component tree.Toggling the view
To toggle the view, simply create a bean method that either refreshes the page
or the particular panel through AJAX. To do this in JSF 1.2, rely on extensions like RichFaces to introduce AJAX, if you can. For example, should you choose RichFaces, you can use
<a4j:commandLink/>
and its handyrender
(orreRender
in older versions) attribute to achieve what you could do normally with an<f:ajax/>
in JSF 2Or, another alternative is
Please note that the
reRender
attribute may vary depending on the structure of your page, but it should always reference the id of the wrapping panel in the end. Also,reRender
was renamed to simplyrender
in late RichFaces versions.So, assuming you have a
renderTable
property (getter + setter) inyourBean
, thetoggleTableView
must change it, in order to dinamically define if the component is to be rendered or not (renderTable = false
).Introducing RichFaces
Check this link for help in setting up RichFaces in your project.