Datatable rows come selected as default - jsf-2

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.

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

JSF selectOneRadio, rendering only certain items

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

<p:autoComplete> renders dropdownlist to top when the list is too large

I am using <p:autoComplete> in my webproject. When lots of data coming to the search box the position of list is from bottom to top instead of top to bottom and not all data is visible.
How can I fix it so that it shows the data from top to bottom?
You can use the scrollHeight attribute to define height of the items those are seen in list as follows
<p:autoComplete value="#{bean.text}" completeMethod="#{bean.complete}" scrollHeight = "150" />
Primefaces documentation will definitely help you regarding this
<p:autoComplete id="acOrden" value="#{serviciosMB.ordenSelect}"
completeMethod="#{serviciosMB.complete}"
var="mauto"
itemValue="#{mauto}"
itemLabel="#{mauto.consecutivoOrden}"
converter="ordenProduccionServiciolConverter" required="true">
<p:ajax event="itemSelect" listener="#{serviciosMB.renderPanelOrden}" update="panelOrden :form2:growl" />
<p:column>
#{mauto.codigoOrden}
</p:column>
</p:autoComplete>
see ajax listener

Primefaces dataTable column width , color scheme , checkboxes functionality

I am new to primefaces and jsf and facing a few problems using it.
Following is the code i am using in jsf
<p:dataTable id="plazaId" var="plaza" value="#{coverageBean.plazaDataModel}" selection="#{coverageBean.selectedPlaza}" rowIndexVar="rowIndex" width="100%" border="0" cellspacing="0" cellpadding="0" >
<p:column id="name" headerText="Select" selectionMode="multiple"
style="width:18px" />
<p:column id="plazaName" headerText="Plaza's" style="width: 50%" bgcolor="#dcdcdc">
<h:outputText value="#{plaza.name}" bgcolor="#dcdcdc"></h:outputText>
</p:column>
<p:column id="plazaDirect" headerText="Directo" style="width: 10%" bgcolor="#dcdcdc">
<h:outputText value="#{plaza.direct}" bgcolor="#dcdcdc"></h:outputText>
</p:column>
</p:dataTable>
I have checked the Beans and backend. They are all correct.
The issues are :
I like to change the width using percentage in this table . But its not working.
I like all the rows to be of the same color. But its showing alternate colors (white and blue)
And is there a way to make the checkbox of simple html style . But its a little fancy.
Could anyone help with any of there problems. Thanks in advance
I like to change the width using percentage in this table . But its not working.
You have syntax issues with your JSF view. Their is no bgcolor attribute of h:outputText, this is a style attribute.
<h:outputText value="#{plaza.name}" headerText="Plazas" style="bgcolor: #dcdcdc;" />
This is also true for the p:column component as well...
<p:column id="plazaName" headerText="Plaza's" style="width: 50%; bgcolor: #dcdcdc;">
This also should fix your background color issue.
And is there a way to make the checkbox of simple html style . But its a little fancy.
This would actually be quite difficult to do. The p:selectBooleanCheckbox is really a styled div with javascript events attached to it. Within this div is a hidden input type="checkbox" that exists as the form element that gets posted back. You can't do this without tinkering with javascript and stylesheets that I know of.
As of today, this is not possible. Refer to http://code.google.com/p/primefaces/issues/detail?id=2801
It is to do with styling. Define style as required.
It is to do with styling. Define style as required.

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