JSF selectOneRadio, rendering only certain items - jsf-2

Is there any possibility rendering just certain items (based on their value) of radio buttons in jsf
e.g this below: (but this approach doesn't work)
<h:selectOneRadio value="#{user.favColor3}">
<f:selectItems rendered="c.colorValue eq 'red'" .... var="c"
</h:selectOneRadio>
So, I want to iterate over the items, and showing only the red item.
Thanks in advance.
Cs

Related

Primefaces TabView throwing a null-pointer on third load of tab

I have a tab view with three tabs. The tab view seems to work correctly in the first two tab changes, but on the third I get a null-pointer as in
java.lang.NullPointerException
at org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:59)
Also, TabChangeEvents have null data at this point.
Making the contents of the tabs minimal (just a line of text), I can see that the contents of the tabs are being appended onto each other. Once this happens, the issues begin.
Looking at the PrimeFaces source code, it seems that it's when trying to work with the tabToLoad variable that is retrieved with the generated tabClientId. I'm not certain that it should be in the branch of logic that deals with new tabs either.
My tab view looks as follows:
<p:tabView styleClass="entities-tabview" id="tabs" dynamic="true">
<p:ajax event="tabChange" listener="#{action.onTabChange}"
update="first-tab,second-tab"/>
<p:tab title="First Tab" id="first-tab">
tab one content
</p:tab>
<p:tab title="Second Tab" id="second-tab">
tab two content
</p:tab>
<p:tab title="Other Tab" id="other-tab">
// tab content
</p:tab>
</p:tabView>
It seems that the code checks if the var parameter is set on the TabView. As we do not use one, it is null, so it goes into the new tab branch. The tab index is set on the tabview though. Any ideas about what could be wrong?
After some more investigation, I see that on a tab change the tab that should be changed to is specified via the request parameter with the client ID with _newTab appended to it. The first two times this is set correctly, but on changing back to the tab it is not set, hence not being able to find the tab and the subsequent NPEs.
Updated Cause
With the tabs being dynamic, and the ajax event firing, the tabs are changed and subsequently the ajax updates the tabs. This seems to cause the issue where both tabs are loaded into the same tab, which most likely is messing up the parameters later on.
But how to be able to do the tab change functions and have its details display in the tab?
The issue here is that you have the ajax updating both of the tabs.
It seems that when it does this, the state of the tabs gets confused and you end up with the content of both tabs in one.
You can get around it by inserting the content into an h:panelGroup and updating the panelgroup instead of the tab
example below
<p:tabView styleClass="entities-tabview" id="tabs" dynamic="true">
<p:ajax event="tabChange" listener="#{action.onTabChange}"
update="one-content,two-content,other-content"/>
<p:tab title="First Tab" id="first-tab">
<h:panelGroup display="block" id="one-content">
tab one content
</h:panelGroup>
</p:tab>
<p:tab title="Second Tab" id="second-tab">
<h:panelGroup display="block" id="two-content">
tab two content
</h:panelGroup>
</p:tab>
<p:tab title="Other Tab" id="other-tab">
<h:panelGroup display="block" id="other-content">
// tab content
</h:panelGroup>
</p:tab>
</p:tabView>

False representation with o:tree and p:panelGrid

I want to build a tree which has p:oanelGrid as nodes. Like this:
<o:tree value="#{plannedElementsBean.tree}" var="item">
<o:treeNode level="0">
<o:treeNodeItem>
<p:panelGrid columns="6">
<f:facet name="header">
<h:outputText value="Header" />
</f:facet>
<o:treeInsertChildren />
<p:panel><h:outputText value="Inner" /></p:panel>
<f:facet name="footer">
<h:outputText value="Footer" />
</f:facet>
</p:panelGrid>
</o:treeNodeItem>
</o:treeNode>
</o:tree>
The problem is, that the vertical lines between the children are missing. p:panelGrid renders vertical lines between its children. And I tested it, with static markup. But all the children inserted by the o:tree are treated as if they where the first child, and thus rendered into the first part, while the inner panel is rendered into a second part, divided by a vertical line. I would like to have all inserted children and the inner panel be divided by a vertical line. What is going wrong here?
This is indeed expected behavior. The <o:tree> and friends are UI components like <ui:repeat> and not tag handlers like <c:forEach>. The <p:panelGrid> renders a <td> per UI component child.
You seem to think that <o:tree> (and equivalently <ui:repeat>) recursively generates multiple JSF components which end up in place of <o:treeInsertChildren>. This is not true. There's really physically only one JSF component in the component tree which repeatedly generates its HTML output depending on the current iteration state. There's physically only one <o:treeInsertChildren> component whose all the HTML output ends up in a single <td> of <p:panelGrid>.
Your best bet is just using left-floating divs with a fixed width of 16% so that they break to next line after each 6 items. Note that you can easily reuse PrimeFaces standard CSS classes on plain HTML elements, if necessary.
See also:
c:forEach inside primefaces(e.g. p:panelgrid) inside ui:repeat
ui:repeat JSF 2.0 cannot render iterate p:row primefaces
create table columns dynamically in JSF

How to restrict editing of certain cells in a DataTable editable in PrimeFaces

I want to restrict certain cells in a DataTable from editing. I mean those fields are not allowed to be edited. How can I achieve this?
Just don't use <p:cellEditor> then.
<p:column>#{videoList.referenceFileName}</p:column>
Note that the <f:facet name="output"> is specific to <p:cellEditor>. You should remove it as well. Alo note that <h:outputText> is not necessary if you don't need to use any specific attributes on it.

Datatable rows come selected as default

I have a datatable:
<p:dataTable style="width: 100%;" id="dTable" var="tt" value="#{backingBean.memberList}" paginator="true" rows="20" selection="#{backingBean.selectedMember}" selectionMode="single" onRowSelectUpdate="mf:tabcontent" onRowSelectComplete="tvl();">
whose rows come selected when the page loads. Does anyone have any opinion about this issue?
primefaces version is 2.2.1.
Thanks in advance.
That will happen if the array or collection behind selection="#{backingBean.selectedMember}" is been prefilled with the selected rows. If you set it to null or an empty array/collection, then nothing will be preselected.

Render h:panelGrid on dataTable row select?

I have a dataTable that when a user selects a row a number of fields are populated so they can see more detail. of that particular item. However, at the moment the page loads with the unpopulated panelgrid and populates on selecting of a row. How can I hide this panelgrid and get it to show once the row has been selected??
Thanks
Use the rendered attribute and let it evaluate true if anything has been selected.
E.g.
<h:panelGrid rendered="#{not empty bean.selectedRow}">
<h:outputText value="#{bean.selectedRow.foo}" />
<h:outputText value="#{bean.selectedRow.bar}" />
...
</h:panelGrid>

Resources