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>
Related
I have a primefaces dataTable which is both select-able (single selection) and has draggable rows. I also need to select a row via a button (apart from being able to select the row itself). My view code is:
<p:dataTable id="itemTable" widgetVar="itemTable"
var="item" draggableRows="true"
value="#{routesModelBean.itemList}" selectionMode="single"
selection="#{routesModelBean.selectedItem}"
rowKey="#{item.id}" rowIndexVar="rowId">
<p:column style="width:32px;text-align: center">
<p:commandButton icon="ui-icon-search"
onclick="PF('itemTable').unselectAllRows();PF('itemTable').selectRow(#{rowId},false);" type="button">
</p:commandButton>
</p:column>
The problem seems to be the "rowIndexVar". For example, if i have two items in my list and i swap them by dragging, then clicking the button of one item will result in selecting the other.
Edit: Primefaces version is 6.0
When reordering the rows you should update the table too. Use the following
<p:ajax event="rowReorder" listener="YOUR_LISTENER" update=":itemTable" />
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
Issue: I am unable to rerender MenuItems in a MenuGroup of rich:contextMenu on selection of a row in a table.
Scenario: I have table of 5 colums and multiple rows. Mouse right click on a row should open contextMenu which has MenuGoup Items, this Group should display MenuItem of values of selected row of specific column values.
I am generating a ArrayList in backing bean and have coded like below. But this menuItemPanel is not rendering. And not showing any values.
<rich:contextMenu>
<rich:menuItem
value="View"
action="#{bakingBean.view}">
</rich:menuItem>
<rich:menuGroup value="Show All Column Values">
<a4j:outputPanel id="menuItemPanel">
<c:forEach items="#{bakingBean.items}" var="item">
<rich:menuItem value="#{item}"
action="#{backingBean.filter}">
<f:param name="filterVal" value="#{item}"/>
</rich:menuItem>
</c:forEach>
</a4j:outputPanel>
</rich:menuGroup>
I have a simple p:dataTable which fires an AJAX event when selecting a row:
<p:dataTable var="c" value="#{myBean.dmCars}"
selection="#{myBean.car}" selectionMode="single">
<p:ajax event="rowSelect" listener="#{myBean.select}"/>
<p:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{c.name}"/>
</p:column>
</p:dataTable>
This works fine, but I can only select a row once. I want to select the same row multiple times and the event listener of p:ajax invoked for each click.
Update I think it's because the row has somewhere the state selected. You see the selected row with a grey background in this example: http://www.primefaces.org/showcase/ui/datatableRowSelectionInstant.jsf
#Daniel and #MattHandy, thank you both for your support. I found a solution to this issue:
public void select()
{
// Do some stuff
car=null;
}
In the backing bean i set the value holder to null after I've processed the event.
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.