Datatable RowKey and Row Selection

UI Components for JSF
Post Reply
michaelmichael
Posts: 3
Joined: 16 Mar 2018, 15:29

14 Sep 2018, 12:15

Hi,

I have this datatable which polulates correctly and selects the correct record on page load .... (this happens when a user selects a token on the previous screen)

Code: Select all

<p:dataTable styleClass="s-alias-table" var="item"
						value="#{updateTokenView.token.tokenXrefs}" rowIndexVar="index" selection="#{updateTokenView.primary}" rowKey="#{item.id1}">
						<p:column headerText="Primary" id = "col" selectionMode="single" style="width:40px;text-align:center"/>
						<p:ajax event="rowSelectRadio" listener="#{updateTokenView.onRowSelect}" />
						<p:column headerText="Source">
							<h:outputText value="#{item.srcSysCd}" />
						</p:column>
					</p:dataTable>

Once the user has viewed the page they can return to the previous screen with

Code: Select all

<p:commandButton  value="Return to list" class="btnRegister" actionListener="#{mainView.displayLandingPage}" update="@(.s-page-body)" ajax="false" immediate="true" process="@none" />

So this process works the first time
i.e user selects a token -> page loads up and the dataTable is polulated and selects the correct row

the second time a token is selected from the previous screen I get an error on the rowKey it throws a java.lang.IndexOutOfBoundsException because for some reason id1 is null

if I modify the code in the id1 getter to return a dummy key and bypass the null rowkey, the page loads up but the selection fails to occur

The odd thing is this happens every second attempt
i.e
1) select item 1 -> everything works -> leave screen
2) select item 1 -> get null key -> return dummy key -> selection fails -> leave screen
3) select item 1 -> everything works -> leave screen
4) select item 1 -> get null key -> return dummy key -> selection fails -> leave screen

I'm really at a loss , the issue does not seem to have anything to do with the item itself but when everything works the updateTokenView.primary getter
is called and when it fails then updateTokenView.primary is never called.

Anyone have any ideas - cleanup , form closing etc, why does a null ever appear on the rowkey, all my objects always have a rowkey - its like some dummy object is getting created at some point but from where?

Thanks!

Mike.


(PrimeFaces 6.2)
(JSF 2.2)

michaelmichael
Posts: 3
Joined: 16 Mar 2018, 15:29

14 Sep 2018, 16:31

An update ...

its definately the

Code: Select all

selection="#{updateTokenView.primary}"
piece which is leading to the creation of a dummy object. When I remove the selection piece I never get the dummy object created. But then how will I perform the selection?

Thanks,

Mike.

michaelmichael
Posts: 3
Joined: 16 Mar 2018, 15:29

17 Sep 2018, 15:58

Turns out that

Code: Select all

 immediate="true" 
was the source of my problems. If I remove that its all good.

This was difficult to find, just trial and error really - I'm a novice JSF guy ... can anyone suggest an explanation or a way to troubleshoot something like this?

Thanks,

Mike.

kukeltje
Expert Member
Posts: 9181
Joined: 17 Jun 2010, 13:34
Location: Netherlands

18 Sep 2018, 11:52

I alsways do a quick debug. Set some breakpoints, check most logical things (known to you, knowledge increases over time ;-). If that does not yield anything I start creating an 'mcve'. See https://stackoverflow.com/help/mcve and http://sscce.org/ and https://stackoverflow.com/tags/jsf/info.

And if that does not yield anything, I either start debugging again or post a question somewhere with the mcve included and version info...
Ronald van Kuijk
______________________________
PrimeFaces 6.1, PrimeFaces plus 0.0.2 | JbossWildfly 10.1| Mojarra 2.2.13
Fedora 61, Firefox 'most recent'
Read the forum posting rules
Beginners: https://jsf.zeef.com/bauke.scholtz

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: khiter and 14 guests