Command Link with in a datatable not working - jsf-2

I am having a problem with primefaces command link.
I have two <h:form> which are not nested the link from the second <h:form> is not triggered.
<h:form>
<p:dataTable>
<p:column>
</p:column>
<p:column>
<p:commandLink onclick="dialog.show()"/>
</p:column>
</dataTable>
</h:form>
<p:dialogBox widgetWar="dialog">
<h:form>
<p:dataList value="#{bean.List}" var="var">
<p:commandLink value="#{var.name}" actionListener="#{bean.viewName(var.id)}"/>
</dataList>
</h:form>
</p:dialogBox>
The command Link from the dialog box is not working and there are no exceptions thrown.
Can any one help?

Your command Link shoud be inside <p:column>.
<p:dataList value="#{bean.List}" var="var">
<p:column>
<p:commandLink value="#{var.name}" actionListener="#{bean.viewName(var.id)}"/>
</p:column>
</p:dataList>
This is necessary in order tou have data Selection inside dataList. Related problem is here

Related

Datatable cellEditor functionality in forEach generated Datatable

I am trying to generate a editable datatable dynamically dependend on the resultset of an previously executed SQL-Query.
Depending on which columns would have a constant value I am trying to not render them. That part of the code works just fine, everything is displayed as i would like it to be.
My issues are with the cellEditor. I generate my datable as follows:
<p:dataTable ajax="true" var="mBT" value="#{stammdaten.bbvList}" id="meldeBearbeitungsTable" editable="true" editMode="cell" scrollable="true" scrollHeight="400" style="width:600px">
<p:ajax event="cellEdit" listener="#{stammdaten.onCellEdit}" update=":Mb:message"/>
<c:forEach var="column" items="#{stammdaten.columns}">
<p:column headerText="#{column.header}">
<f:attribute name="myCol" value="#{column}" />
<span>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mBT[column.property]}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mBT[column.property]}">
<p:keyFilter regEx="/[0-9]/i"/>
</p:inputText>
</f:facet>
</p:cellEditor>
</span>
</p:column>
</c:forEach>
</p:dataTable>
bbvList is a List of beans with different values.
columns is a List of beans to identify the header-Texts coresponding to the respective variables.
So now the issue itself:
This is how the cellEditor looks like when i click on it:
Issue-Picture
So in that example i tried to edit the field with the value "8" in it. onCellEdit gets triggered (a System.out.println is getting printed on the console) but i cant actually change the value in the respective field.
Does have cellEdit issues with the forEach initialisition of the dataTable? If yes is there a way to fix it? Else what am i doing wrong?
Since only a specific component of the html-side of code isnt working as it should be i won't post unnecessary java-Code for now. If needed i will add that as well.
Hope someone can help :)
Turns out the attribute and/or span where the cause of the problem. Simply removing them solved the issue with the cellEdit.
following works fine :
<p:dataTable ajax="true" var="mBT" value="#{stammdaten.bbvList}" id="meldeBearbeitungsTable" editable="true" editMode="cell" scrollable="true" scrollHeight="400" style="width:600px">
<p:ajax event="cellEdit" listener="#{stammdaten.onCellEdit}" update=":Mb:message"/>
<c:forEach var="column" items="#{stammdaten.columns}">
<p:column headerText="#{column.header}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mBT[column.property]}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mBT[column.property]}">
<p:keyFilter regEx="/[0-9]/i"/>
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
</c:forEach>
</p:dataTable>

primefaces dialog box and datatable checkbox selection

I want to display the selected rows of a table in a dialog box but I have an empty dialog box even if I check one or more line nothing is displayed .. I realy don't know what is the cause of my problem .. I hope there will be someone who can help me (I m a beginner in jsf2 and I just discovered primefaces I really want help thanks soo much in advance ) this is my jsf :
<p:outputLabel for="product" value="" />
<p:dataTable id="product" var="ligne" value="#{productBean.myProducts}" selection="#{productBean.selectedProducts}" style="margin-bottom:0" rowKey="#{productBean.id}">
<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column headerText="Code">
<h:outputText value="#{ligne.code}" />
</p:column>
<p:column headerText="designation" >
<h:outputText value="#{ligne.title}" />
</p:column>
<f:facet name="footer">
<p:commandButton process="product" update=":form:multiProductDetail" icon="ui-icon-search" value="View" oncomplete="PF('multiProductDialog').show()" />
</f:facet>
</p:dataTable>
<p:dialog header="Products" widgetVar="multiProductDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" width="200">
<p:outputPanel id="multiProductDetail" style="text-align:center;">
<ui:repeat value="#{prodBean.selectedProducts}" var="ligne">
<h:outputText value="#{ligne.code} -- #{ligne.title}" style="display:block"/>
</ui:repeat>
</p:outputPanel>
Did you put a
h:form
inside this page
Is there data inside selection="#{productBean.selectedProducts}" .Can you a debug point there and see or put some sysouts in the getters and setters of selectedProducts.
Can you share your product code and check if selectedProducts is null or not
system.out.println("products"+selectedProducts.get(0))
best
vj

a4j:commandLink not work at first time

I hava a rich:tabPanel where i can add and remove tab dynamically
<rich:tabPanel id="tabsPanel" switchType="client" activeItem="#{tabsBean.activeTab}" itemChangeListener="#{tabsBean.tabChange()}" >
<c:forEach var="tab" items="#{tabsBean.tabs}" >
<rich:tab name="#{tab.name}" onheaderclick="switchTab('#{tab.name}');" >
<f:facet name="header">
<h:panelGrid columns="2">
<h:outputText value="#{tab.name}" />
<h:graphicImage value="#{pathImmagini.pathImmagineElimina}"
style="width:12px; height:12px;"
onclick="myFunc('#{tab.name}'); Event.stop(event);"/>
</h:panelGrid>
</f:facet>
<h:form id="#{tab.name}" >
<ui:include src="#{tab.pathComponent}" />
</h:form>
</rich:tab>
</c:forEach>
</rich:tabPanel>
where each tab has a its component *.xhtml (tab.pathComponent) , within of this components i have many a4j:commandlink that not works at first time.
this is one of my components (tab.pathComponent)
<rich:toolbar height="30" >
<a4j:commandLink action="#{tab.setNewObject('Nuovo Cliente')}" render="pannelloDatiCliente" execute="#this" >
<h:graphicImage value="#{pathImmagini.pathImmagineAggiungiSoggetto}"/>
</a4j:commandLink>
</rich:toolbar>
How i can do?
can you give bit more information regarding your xhtml. normally second click problem happens because of partial rendereing of page or UI. Can't tell the problem only with this part of code.

p:dataTable not updating after deleting row

I have searched this topic and tried all the suggestions, however I just cannot seem to get what seems to be a very simple thing to work.
I have a PrimeFaces 3.4 <p:dataTable> with data populated from a List in my backing bean and with a <p:commandLink> in one of the columns for every row. I am just trying to implement a simple delete and refresh of the data table. However although the element is removed from the List object, the data table does not refresh.
Bean (view scoped):
public void deleteRow(rowType row){
this.tableDataList.remove(row);
}
View:
<h:form id="form">
<p:dataTable id="dt" var="dt" value=#{managedBean.tableDataList}
rowKey="#{dt.id}" selection="#{managedBean.selectedRow}"
selectionMode="single">
<p:column><h:outputText value="#{dt.field1}"/></p:column>
<p:column><h:outputText value="#{dt.field2}"/></p:column>
<p:column><h:outputText value="#{dt.field3}"/></p:column>
<p:column width="60">
<p:commandLink id="deleteCl"
value="Delete"
actionListener="#{managedBean.deleteRow(dt)}"
update=":form:dt"
/>
</p:column>
</h:form>
From what I can see, a data table in PrimeFaces 3.4 should be able to be updated via a child component such as a command link, but I just can't get it to work. I have a phase listener implemented so I can see that there are no validation or other errors before the render response phase, but the data table continues to display the deleted row unless I refresh the browser window, then it will disappear.
It works if I set ajax="false" in the command link, but then the entire page is updated unnecessarily.
I have tried:
Changing between action and actionListener
Making the following changes in various combinations to the command link attributes:
process="#this"
update="#this"
update="#form"
The annoying thing is that I have a similar table with a command link where each link opens up a dialog window containing another data table that is populated with data retrieved based upon the row that was initially clicked. Works perfectly on the same page. Agh!
Try modeling some points from this to see if it helps you.
<h:outputText escape="false" value="#{message.noCompaniesFound}" rendered="#{companyController.companyModel.rowCount == 0}"/>
<h:panelGroup rendered="#{companyController.companyModel.rowCount > 0}">
<p:commandButton id="addButton" value="#{message.newCompany}" oncomplete="companyDialog.show()" icon="ui-icon-plus" title="#{message.addCompany}" rendered="#{loginController.privileges.contains(bundle.SuperUser)}"/>
<p:dataTable id="companyList" var="company" widgetVar="companyTable" value="#{companyController.companyModel}" rowKey="#{company.name}" selection="#{companyController.selectedCompany}" selectionMode="single"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,20,50,100">
<p:ajax event="rowEdit" update="#this" listener="#{companyController.saveCompany(company)}">
<f:param name="company" value="#{company}"/>
</p:ajax>
<f:facet name="header">
<p:outputPanel>
<h:outputText value="#{message.search}: "/>
<p:inputText id="globalFilter" onkeyup="companyTable.filter()"/>
</p:outputPanel>
</f:facet>
<p:column id="name" headerText="#{message.name}" filterBy="#{company.name}" filterMatchMode="contains" filterStyle="display: none;">
<h:outputText value="#{company.name}"/>
</p:column>
<p:column headerText="#{message.editOptions}" style="width:10px;">
<p:commandButton id="editButton" update=":companyForm" oncomplete="editDialog.show()" icon="ui-icon-pencil" title="#{message.edit}">
<f:setPropertyActionListener value="#{company}" target="#{companyController.selectedCompany}"/>
</p:commandButton>
<p:commandButton id="deleteButton" update=":companyForm" oncomplete="confirmation.show()" icon="ui-icon-trash" title="#{message.delete}">
<f:setPropertyActionListener value="#{company}" target="#{companyController.selectedCompany}"/>
</p:commandButton>
</p:column>
<f:facet name="footer">
</f:facet>
</p:dataTable>
</h:panelGroup>
<p:confirmDialog id="confirmDialog" message="#{message.sureYouWantToDelete} #{companyController.selectedCompany.name} ?" severity="alert" widgetVar="confirmation">
<p:commandButton id="confirm" value="#{message.yes}" onclick="confirmation.hide()" actionListener="#{companyController.deleteCompany}" update="companyForm" />
<p:commandButton id="decline" value="#{message.no}" onclick="confirmation.hide()"/>
</p:confirmDialog>

ui:repeat JSF 2.0 cannot render iterate p:row primefaces

I got a problem here, my system config was Mojarra 2.1.7, Primefaces 3.2 and using Glassfish 3.1+.
before this, i got my code well rendered using this codes:
<p:tabView>
<p:tab title="Offices Access" >
<h:outputText value="Access | Offices Name | Offices Code | Parent Offices" style="font-weight: bold;"/>
<ui:repeat value="#{userBean.officeses}" var="office">
<h:panelGrid columns="2">
<p:selectBooleanCheckbox id="access#{office.officesID}" style="width: 50px;"/>
<h:outputLabel for="access#{office.officesID}" value="#{office.officesName} | #{office.officesCode} | #{office.parentOffices}"/>
</h:panelGrid>
</ui:repeat>
</p:tab>
</p:tabView>
and i find this is generate rather ugly interfaces, so i ran over p:panelGrid from primefaces.
after i write some code and from my expectation it would work, but it DONT :(
this code render the header perfectly, but right after the ui:repeat code, it wouldnt render the p:row and the p:column inside it.
here is the code :
<p:tabView>
<p:tab title="Offices Access" >
<p:panelGrid styleClass="centerContent">
<f:facet name="header">
<p:row>
<p:column style="font-weight: bold;">Access</p:column>
<p:column style="font-weight: bold;">Offices Name</p:column>
<p:column style="font-weight: bold;">Offices Code</p:column>
<p:column style="font-weight: bold;">Above Level Offices</p:column>
</p:row>
</f:facet>
<ui:repeat value="#{userBean.officeses}" var="office">
<p:row id="rowforOffice#{office.officesID}">
<p:column><p:selectBooleanCheckbox id="access#{office.officesID}"/></p:column>
<p:column><h:outputText value="#{office.officesName}"/></p:column>
<p:column><h:outputText value="#{office.officesCode}"/></p:column>
<p:column><h:outputText value="#{office.parentOffices}"/></p:column>
</p:row>
</ui:repeat>
</p:panelGrid>
</p:tab>
</p:tabView>
am i miss something..?
or it is was a bug..? because i ran over google looking for this kind of code and i found nothing.
Regards,
bLueZ
As to the concrete problem, the <ui:repeat> is a view render time tag. Thus, it's physically present in the JSF component tree and generates its HTML output as many times as it needs to iterate over the value.
However, the <p:panelGrid> expects physically multiple <p:row> or <p:column> children, not a single <ui:repeat> with therein a single <p:row>. In other words, they needs to be prepared during the view build time instead of the view render time.
The JSTL <c:forEach> is a view build time tag. It will generate physically multiple <p:row> components into the JSF component tree and hence the <p:panelGrid> will find solely <p:row> children.
<p:panelGrid styleClass="centerContent">
<c:forEach items="#{userBean.officeses}" var="office">
<p:row id="rowforOffice#{office.officesID}">
<p:column><p:selectBooleanCheckbox id="access#{office.officesID}"/></p:column>
<p:column><h:outputText value="#{office.officesName}"/></p:column>
<p:column><h:outputText value="#{office.officesCode}"/></p:column>
<p:column><h:outputText value="#{office.parentOffices}"/></p:column>
</p:row>
</c:forEach>
</p:panelGrid>
Note: this breaks view scoped beans in Mojarra versions older than 2.1.18. If you can't upgrade, then consider a <p:dataTable> instead, as you already found out yourself.
See also:
JSTL in JSF2 Facelets... makes sense?
Thanks to #Jedrus07 to suggest me to post an answer.
Actually, what i did, was using <p:dataTable/> to make a good display of data.
example :
<p:tabView id="tabCustomerView">
<p:tab title="Fasilitas Nasabah">
<p:fieldset legend="Detil Fasilitas">
<p:dataTable value="#{custViewBean.customerSavingAccounts}"
var="customerSavingAccount"
rowIndexVar="customerSavingAccountRowIndex"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rows="10"
rowsPerPageTemplate="5,10,15"
paginatorPosition="top">
<f:facet name="header">
<h:outputText value="Daftar Rekening / Fasilitas Nasabah"/>
</f:facet>
<p:column headerText="#">
<h:outputText value="#{customerSavingAccountRowIndex + 1}"/>
</p:column>
<p:column headerText="Fasilitas Nasabah">
<h:outputText value="#{of:capitalize(customerSavingAccount.customerFacility)}"/>
</p:column>
<p:column headerText="Saldo Akhir">
<h:outputText value="#{customerSavingAccount.lastBalance}">
<f:convertNumber type="currency" currencySymbol="#{appBean.appSetting.curDefault.currencySymbol}"/>
</h:outputText>
</p:column>
<p:column headerText="Tanggal Akhir">
<h:outputText value="#{customerSavingAccount.lastTransactiondate}">
<f:convertDateTime pattern="#{appBean.appSetting.siteFormatdate}"/>
</h:outputText>
</p:column>
<p:column headerText="Suku Bunga">
<h:outputText value="#{customerSavingAccount.interest} %"/>
</p:column>
<p:column headerText="Kolektibilitas">
<h:outputText value="#{customerSavingAccount.collectibility}"/>
</p:column>
<p:column headerText="Account Officer">
<h:outputText value="#{of:capitalize(customerSavingAccount.accountOfficer)}"/>
</p:column>
<p:column headerText="Jumlah Tunggakan">
<h:outputText value="#{customerSavingAccount.arrearsAmount}">
<f:convertNumber type="currency" currencySymbol="#{appBean.appSetting.curDefault.currencySymbol}"/>
</h:outputText>
</p:column>
<p:column headerText="Jumlah Pembayaran">
<h:outputText value="#{customerSavingAccount.totalPayment}">
<f:convertNumber type="currency" currencySymbol="#{appBean.appSetting.curDefault.currencySymbol}"/>
</h:outputText>
</p:column>
<p:column headerText="Periode Pembayaran">
<h:outputText value="#{customerSavingAccount.termLimit} #{customerSavingAccount.termLimitDesc}"/>
</p:column>
<p:column headerText="Status">
<h:outputText value="#{customerSavingAccount.status}"/>
</p:column>
</p:dataTable>
</p:fieldset>
</p:tab>
</p:tabView>
So, use datatable for nicer looks to display your datas :)
Have fun.

Resources