Primefaces datatable with commandLink conflicts with row selection - jsf-2

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>

Related

Primefaces dataTable with select and dragable rows, select fails when rows are reordered

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" />

Change default color of a popupPanel?

I have a popupPanel:
<rich:popupPanel id="popup" modal="false" autosized="true" resizeable="false">
<f:facet name="header">
<h:outputText value="Simple popup panel" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popup')}.hide(); return false;">
X
</h:outputLink>
</f:facet>
<p>Any content might be inside this panel.</p>
<p>
The popup panel is open and closed from the javascript function of component client side object. The following code
hide this panel:
<f:verbatim>#</f:verbatim>{rich:component('popup')}.hide()
</p>
</rich:popupPanel>
I´m using this example:
Simple popup example
I want to change the color, the default color is blue, I want to change this color to Red or Green, is it possible ?
If it is relevant, i´m using richfaces 4.
Thanks in advance !
Add This css :
.rf-pp-hdr{
background: red;
}

rich:tabPanel loads data of all tabs on tab switch

I have a in my ui file which has switchType set to ajax. It has 4 tabs. The problem is when I click on tab1 , it loads data of tab1. But, when I click on tab2, it loads data of tab1 and tab2. When tab3 is clicked, it loads data of tab1, tab2 and tab3. And so on. How can I avoid this behaviour? It should load the data of only the tab which is selected(or clicked on) and not all the tabs before it.
I use richfaces 4 and JSF 2.0
Below is the code :
<rich:tabPanel status="loadingMask" id="tabPanelTest" switchType="ajax" style="height:80%;width:100%;padding-top:5px">
<a4j:ajax event="itemchange" render="tabPanelTest" />
<rich:tab header="Tab 1" id="TAB 1">
<h:panelGroup layout="block" style="height:100%;width:100%;" id="tab1view">
<ui:include src="tab-1-file.xhtml"/>
</h:panelGroup>
</rich:tab>
<rich:tab header="Tab 2" id="TAB 2">
<h:panelGroup layout="block" style="height:100%;width:100%;" id="tab2view">
<ui:include src="components/tab-2-file.xhtml"/>
</h:panelGroup>
</rich:tab>
<rich:tab header="Tab 3" id="TAB 3">
<h:panelGroup layout="block" style="height:100%;width:100%;" id="tab3view">
<ui:include src="tab-3-file.xhtml"/>
</h:panelGroup>
</rich:tab>
<rich:tab header="Tab 4" id="TAB 4">
<h:panelGroup layout="block" style="height:100%;width:100%;" id="tab4view">
<ui:include src="tab-4-file.xhtml"/>
</h:panelGroup>
</rich:tab>
</rich:tabPanel>

Dynamic Value for MenuItem in MenuGroup of rich:contextMenu

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>

Primefaces: Select same row in p:dataTable multiple times

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.

Resources