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.
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" />
I have a primefaces datatable and I'm trying to set the background-color of cells as following :
<p:column sortBy="#{salle.couleur}">
<f:facet name="header">
<h:outputText value="#{messages.Couleur}" />
</f:facet>
<h:outputText style="background-color:##{salle.couleur}" />
</p:column>
the value of #{salle.couleur} is something like this : 0909e8, thats why use a # before the value.
But it doesn't work, and when I inspected the html page I can see that the cell has indeed a background-color :
How can I solve this ?
In your case the inspected <span /> is empty, so there is nothing to color with a custom background. That is beacause you do not set the background color of the cell but of the cells content. I would recommend to set the background color on the cell itself via:
<p:column
sortBy="#{salle.couleur}"
style="#{empty salle ? '' : 'background-color: #'.concat(salle.couleur).concat(';')}"
>
...
</p:column>
So even if the cells content is empty the cell itself will have a custom background color. The empty salles condition in the ternary operator prevents the column header from getting colored also.
I am working with PrimeFaces 5. The row selection is enabled and I want to embed a commandLink in one of the columns. When I click on the commandLink, I show a dialog, but I do not want the row to be selected. Is this possible (currently both events happen, the dialog is shown and the row is selected)?
<p:dataTable id="tableData" widgetVar="tableData" var="p"
value="#{bean.list}" ...
selection="#{bean.selectedItem}" selectionMode="single">
<p:ajax event="rowSelect" listener="#{actionBean.onSelect}"
update="#form" onstart="PF('statusDialog').show();"
oncomplete="PF('statusDialog').hide();" />
<p:column headerText="Title" ...>
<p:commandLink id="clickableTitle" onstart="PF('statusDialog').show();"
oncomplete="PF('statusDialog').hide();PF('detailsDialog').show()">
<h:outputText value="#{p.title}" styleClass="link"/>
</p:commandLink>
</p:column>
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 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>