My code:
<h:form id="form"> <p:dataTable var="article" value="#{articleTable.articles}" lazy="true" selection="#{articleTable.selected}" selectionMode="single" emptyMessage="#{text['emptyMessage']}" rowKey="#{article.id}"> <p:column style="display:none;"> <h:outputText value="#{article.id}" /> </p:column> <p:column headerText="#{text['titleText']}"> <h:outputText value="#{article.title}" /> </p:column> <p:column headerText="#{text['summaryText']}"> <h:outputText value="#{article.summary}" /> </p:column> <p:column headerText="#{text['categoryText']}"> <h:outputText value="#{article.category}" /> </p:column> <p:column headerText="#{text['statusText']}"> <h:outputText value="#{article.status.text}" /> </p:column> <p:ajax event="rowSelect" oncomplete="handleRowSelect('#{article.id}')"/> </p:dataTable> </h:form>
<script type="text/javascript"> function handleRowSelect(id) { if ( id ) window.location.href = 'article.xhtml?id=' + id; } </script>
#{article.id}
has value, but "handleRowSelect('#{article.id}')"
argument value is '' empty.
I use Chrome F12; it has called handleRowSelect()
method, but the id value is '' empty; why?
Why the argument is empty?
And how do I fix it?
Do I have to use commandLink or commandButton? Can't I click on a row to redirect page?
<p:ajax event="rowSelect" listener="#{articleTable.navigateToDetail}"/>
But it turn back to redirect. 2.<p:dataTable id="articleTable" widgetVar="articleTable">
andvar id = PF('articleTable').selection;
. Why not each row call redirect method with id itself?