I have a dataTable with no width specified. Instead of automatically adjust its width it wraps the text in one of the columns. I don't know why this is happening. I'm hoping to avoid using white-space: nowrap;
xhtml:
<ez:listTable
listBean="#{artistBean}"
actionBean="#{albumBean}"
editable="#{artistBean.moderatedByUser}"
title="albums"
info="You need to be moderator to edit albums">
<h:column>
<f:facet name="header">name</f:facet>
<h:link
outcome="album"
styleClass="tableLink"
value="#{item.name}">
<f:param name="albumId" value="#{item.id}" />
<f:param name="albumName" value="#{item.name}" />
</h:link>
</h:column>
<h:column>
<f:facet name="header">year</f:facet>
<h:outputText value="#{item.year}" styleClass="tableItem" />
</h:column>
</ez:listTable>
Composite component (implementation):
<cc:implementation>
<div id="#{cc.clientId}">
<h:outputStylesheet name="tableBase.css" library="css/table" />
<h:outputStylesheet name="tableContent.css" library="css/table" />
<h:panelGrid columns="2" cellpadding="0" cellspacing="0">
<h:outputText value="#{cc.attrs.title}" styleClass="#{cc.attrs.titleClass}" />
<h:panelGroup rendered="#{cc.attrs.showInfo}">
<h:graphicImage id="info" styleClass="tableInfoIcon" library="images" name="q1_9x9.png" />
<p:overlayPanel
for="info"
styleClass="tableInfo"
showEffect="fade"
hideEffect="fade">
#{cc.attrs.info}
</p:overlayPanel>
</h:panelGroup>
</h:panelGrid>
<h:panelGrid columns="2" cellpadding="0" cellspacing="0">
<h:dataTable
id="table"
binding="#{cc.table}"
value="#{cc.attrs.listBean.list}"
var="item"
styleClass="#{cc.attrs.styleClass}"
rowClasses="#{cc.attrs.rowClasses}"
headerClass="#{cc.attrs.headerClass}"
rendered="#{not empty cc.attrs.listBean.list}">
<cc:insertChildren />
<h:column rendered="#{cc.attrs.editable}">
<p:commandLink
action="#{cc.attrs.actionBean.checkChangeAction()}"
value="edit"
styleClass="tableLink"
update="#form"
oncomplete="#{cc.attrs.editDialogId}Wid.show();"
rendered="#{cc.attrs.actionBean != null}">
<f:actionListener binding="#{cc.attrs.actionBean.setItem(item)}" />
</p:commandLink>
<p:commandLink
action="#{cc.attrs.listBean.checkChangeAction()}"
value="edit"
styleClass="tableLink"
update="#form"
oncomplete="#{cc.attrs.editDialogId}Wid.show();"
rendered="#{cc.attrs.actionBean == null}">
<f:actionListener binding="#{cc.attrs.listBean.setItem(item)}" />
</p:commandLink>
</h:column>
<h:column rendered="#{cc.attrs.editable}">
<p:commandLink
action="#{cc.attrs.actionBean.delete(item)}"
value="delete"
styleClass="tableLink"
update="#form"
rendered="#{cc.attrs.actionBean != null}"/>
<p:commandLink
action="#{cc.attrs.listBean.delete(item)}"
value="delete"
styleClass="tableLink"
update="#form"
rendered="#{cc.attrs.actionBean == null}" />
</h:column>
</h:dataTable>
<h:panelGroup rendered="#{empty cc.attrs.listBean.list}" styleClass="default_paragraph">
#{cc.attrs.emptyListMsg}
</h:panelGroup>
</h:panelGrid>
</div>
</cc:implementation>
Generated html:
<table id="albumForm:j_idt180:table" class="table">
<thead>
<tr>
<th class="tableHeader" scope="col">name</th>
<th class="tableHeader" scope="col">year</th>
<th class="tableHeader" scope="col"></th>
<th class="tableHeader" scope="col"></th>
</tr>
</thead>
<tbody>
<tr class="tableRowOdd">
<td>Through The Eyes</td>
<td><span class="tableItem">2002</span></td>
<td><a id="albumForm:j_idt180:table:0:j_idt170" href="#" class="ui-commandlink tableLink" onclick="PrimeFaces.ab({source:'albumForm:j_idt180:table:0:j_idt170',update:'albumForm',oncomplete:function(xhr,status,args){dialogWid.show();;}});return false;">edit</a></td>
<td><a id="albumForm:j_idt180:table:0:j_idt173" href="#" class="ui-commandlink tableLink" onclick="PrimeFaces.ab({source:'albumForm:j_idt180:table:0:j_idt173',update:'albumForm'});return false;">delete</a></td>
</tr>
<tr class=" tableRowEven">
<td>Endangered Species</td>
<td><span class="tableItem">2001</span></td>
<td><a id="albumForm:j_idt180:table:1:j_idt170" href="#" class="ui-commandlink tableLink" onclick="PrimeFaces.ab({source:'albumForm:j_idt180:table:1:j_idt170',update:'albumForm',oncomplete:function(xhr,status,args){dialogWid.show();;}});return false;">edit</a></td>
<td><a id="albumForm:j_idt180:table:1:j_idt173" href="#" class="ui-commandlink tableLink" onclick="PrimeFaces.ab({source:'albumForm:j_idt180:table:1:j_idt173',update:'albumForm'});return false;">delete</a></td>
</tr>
</tbody>
</table>
CSS:
.tableLink {
display: inline-block;
text-decoration: none;
padding: 3px 5px 3px 5px;
color: #3a5776;
}
.table {
*border-collapse: collapse; /* IE7 and lower */
border-spacing: 0;
border: solid #ccc 1px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
padding: 2px;
}
The name column is the one that gets wrapped. It seems there's like one px missing for the column to be rendered correctly.
After some testing I found out what the problem was. In the style for the tableelement, I use padding to get the border distanced from the actual table content. Padding for the table (not td) is - as far as I understand - not supported. It worked in firefox but not in chrome.
Related
Any idea why f:setPropertyActionListener is not working when I'm setting p:dataTable id="inv#{ck001.sequence}", which is a value obtained from the pageBean.
It works ok if I set it to p:dataTable id="inv1", a fixed value
<table class="layout-matrix">
<tr>
<td class="layout-cell" rowspan="3" style="width: 33.33%;">
<p:poll interval="60" listener="#{ck001.refreshData}" update="#form"/>
<div id="availableInventory" style="overflow: scroll; height:1030px" >
<table class="outer-wrap"><tr><td class="outer-cell"><table class="inner-wrap"><tr><td class="inner-cell">
<p:fieldset legend="#{i18n.static.availableInventory}">
<c:forEach var="invBBD" items="#{ck001.distinctBBD}">
<p:panel styleClass="has-footer" >
<p:dataTable id="inv#{ck001.sequence}" var="inv" value="#{ck001.getAvailableInventoryViewModelList(invBBD)}" style="width:300px;">
<f:facet name="header">
<h:outputText value="#{i18n.static.bestBeforeDate}: #{invBBD}" styleClass="strong"/>
</f:facet>
<p:column headerText="#{i18n.static.productDescription}" width="200">
<h:outputText value= "#{inv.productName}" style="display: block; background-color: #{inv.color}"/>
</p:column>
<p:column headerText="#{i18n.static.birdGrade}">
<h:outputText value= "#{inv.birdGrade}" style="display: block; background-color: #{inv.color}"/>
</p:column>
<p:column headerText="#{i18n.static.supplierName}" width="200">
<h:outputText value="#{inv.supplierName}" style="display: block; background-color: #{inv.color}"/>
</p:column>
<p:column headerText="#{i18n.static.quantity}">
<h:outputText value="#{inv.sumOfQuantityOnHand}" style="display: block; background-color: #{inv.color}"/>
</p:column>
<p:column>
<p:commandButton id="chickenReplenishment"
update=":chickenReplenishmentPopupForm:chickenReplenishmentPnl"
process="#this"
oncomplete="chickenReplenishmentPopup.show()"
icon="ui-icon-c34"
title="#{i18n.static.chickenReplenishment}">
<f:setPropertyActionListener value="#{inv}" target="#{ck001.selectedAvailableInventory}" />
<f:setPropertyActionListener value="#{invBBD}" target="#{ck001.selectedBestBeforeDate}" />
<f:setPropertyActionListener value="#{inv.sumOfQuantityOnHand}" target="#{ck001.quantityRequested}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:panel>
</c:forEach>
</p:fieldset>
</td></tr></table></td></tr></table>
</div>
</td>
....
In my JEE application, I have an emails list extraction process. I need to display a counter which be incremented after adding a mail to the list. The idea is to display the size of this list and update it every 1 seconde using primeface poll. I procced like this:
EmailsExtraction.xhtml:
<h:body>
<h:form>
<h:panelGroup id="formblock" style="margin-top: 40px" layout="block" >
<p:panelGrid columns="2">
<p:outputLabel for="Keyword" value="Keywords: " />
<p:inputText id="Keyword" type="search" requiredMessage="Keyword is required" style="width: 600px"
value="#{mailMB.keyword}" required="true" label="Keyword">
</p:inputText>
<p:outputLabel for="Emailsnbr" value="Emails amount:" />
<p:inputText id="Emailsnbr" requiredMessage="Emails number is required" style="width: 590px"
value="#{mailMB.number}" required="true" label="Emailsnbr">
</p:inputText>
</p:panelGrid>
</h:panelGroup>
<p:spacer height="5px" />
<p:commandButton value="Start" style="width: 12%;height: 100%" id="extractbutton" ajax="true" widgetVar="ButtonExtract"
actionListener="#{mailMB.searchEmailsRym()}"
styleClass="ui-priority-primary"
onstart="blockUIWidget1.show();" oncomplete="play(); blockUIWidget1.hide(); if (args && !args.validationFailed) freeMails();">
</p:commandButton>
</h:form>
<p:dialog widgetVar="blockUIWidget1" header="Hitonclick" modal="true" resizable="false" closable="false" >
<table border="0" style="width: 500px">
<tbody >
<tr>
<td>
<p:graphicImage url="pictures/loading81.gif" width="200" height="200" alt="animated-loading-bar"/>
</td>
<td>
<h:form >
<p:outputLabel value="#{mailMB.count}" id="countOutPut"/>
<p:poll interval="1" update="countOutPut" listener="#{mailMB.increment}"/>
<div id="countdown_text">0</div>
<br></br>
<p:commandButton ajax="false" style="width: 100px;height: 40px" actionListener="#{mailMB.abortSearch()}" value="Cancel" styleClass="ui-priority-primary" title="Cancel" oncomplete="clearForm('formcounter'), clearForm('searchForm')"/>
</h:form>
</td>
</tr>
<div align="right">
</div>
</tbody>
</table>
</p:dialog>
</h:body>
ManagedBean.java:
private int count=0;
public void increment(){
count=mails.size();
}
// count getter & setter
But the count value is not updated.
I am working on j2ee web application (jsf2 and primefaces) and i wonder how to display form depending on the item selected from select one menu.
I tried this but it didn't work.
<h:form id="global">
<p:panel header="Association">
...
<p:outputLabel value="Travel Class" />
<p:selectOneMenu id="associationType" style="width: 230px" value="#{associationMBean.travelClass}">
<f:selectItem itemLabel="Select one" itemValue="" />
<f:selectItem itemLabel="Seminar" itemValue="Seminar" />
<f:selectItem itemLabel="Honeymoon" itemValue="Honeymoon" />
<f:selectItem itemLabel="Organized Trip" itemValue="Organized Trip" />
<p:ajax update=":hidePanel"/>
</p:selectOneMenu>
</p:panel>
</h:form>
<p:panel id="hidePanel" style="margin-top: 20px; font-size: 14px; border: 0;display: none " header="Remarks (Optional)" rendered="#{associationMBean.travelClass eq Seminar}">
<h:form>
<p:inputTextarea style="width: 100% ; height: 100px" value="#{associationMBean.description}" ></p:inputTextarea>
</h:form>
</p:panel>
Update
<html
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Visa Application-Thailand</title>
</h:head>
<h:body>
<div align="center">
<div>
<img class="logo" src="images/banner.jpg"/>
</div>
<p:panel style="width: 61%; border-color: indianred; border-width: 2px; margin-top: 10px">
<h:form id="global">
<p:panel style="margin-top: 20px; font-size: 14px ; border: 0" header="Association">
<table border="0" >
<tbody >
<tr>
<td align="right">
<p:outputLabel value="Association Type" />
</td >
<td align="left">
<p:selectOneMenu id="selectmenu" style="width: 230px" value="#{associationMBean.type}">
<f:selectItem itemLabel="Select a Class" itemValue="" />
<f:selectItem itemLabel="Seminar" itemValue="Seminar" />
<f:selectItem itemLabel="Organized Trip" itemValue="Organized Trip" />
<f:selectItem itemLabel="Honeymoon" itemValue="Honeymoon" />
<p:ajax update=":hidePanel"/>
</p:selectOneMenu>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Date of Departure" for="departure" />
</td>
<td align="left">
<p:calendar value="#{associationMBean.departure}" showOn="button" pattern="dd/MM/yy" style="width: 250px" id="departure"></p:calendar>
<p:watermark value="01/01/2014" for="departure"/>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Date of Arrival" for="arrival" />
</td>
<td align="left">
<p:calendar value="#{associationMBean.arrival}" showOn="button" pattern="dd/MM/yy" style="width: 250px" id="arrival"></p:calendar>
<p:watermark value="01/01/2014" for="arrival"/>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Travel Agency " for="travelAgency"/>
</td>
<td align="left">
<p:inputText id="travelAgency" value="#{associationMBean.travelAgency}" style="width: 220px"></p:inputText>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Airline " for="airline"/>
</td>
<td align="left">
<p:inputText id="airline" value="#{associationMBean.airline}" style="width: 220px"></p:inputText>
</td>
</tr>
<tr>
<td align="right">
<p:outputLabel value="Travel Class" />
</td >
<td align="left">
<p:selectOneMenu id="selectclass" style="width: 230px" value="#{associationMBean.travelClass}">
<f:selectItem itemLabel="Select a Class" itemValue="" />
<f:selectItems value="#{associationMBean.allClasses}" />
<!-- <p:ajax update=":hidePanel"/> !-->
</p:selectOneMenu>
</td>
</tr>
<tr >
<td align="right">
<p:outputLabel value="Hotels " for="hotels" />
</td>
<td align="left">
<p:inputTextarea id="hotels" value="#{associationMBean.hotels}" style="width: 220px"/>
</td>
</tr>
</tbody>
</table>
</p:panel>
<div align="right" style="margin-top: 20px ">
<p:commandButton type="reset" value="Reset" style="font-size: 14px;"/>
<p:commandButton value="Save" ajax="false" styleClass="ui-priority-primary" style="font-size: 14px;" action="#{associationMBean.addAssociation()}" />
</div>
</h:form>
<p:panel id="hidePanel" style="margin-top: 20px; font-size: 14px; border: 0;display: none " header="Remarks (Optional)" >
<h:form rendered="#{associationMBean.type == 'Seminar'}" >
<p:inputTextarea style="width: 100% ; height: 100px" value="#{visaMBean.description}" ></p:inputTextarea>
</h:form>
</p:panel>
</p:panel>
</div>
</h:body>
</html>
the code above is the whole html code after adding some updates <h:form rendered="#{associationMBean.type == 'Seminar'}" > But still can't display the hidePane when i select Seminar from the selectOneMenu.
Have you any idea what am i missing??
The following should work:
<p:panel id="hidePanel" style="margin-top: 20px; font-size: 14px; border: 0;display: none " header="Remarks (Optional)">
<h:form rendered="#{associationMBean.travelClass eq 'Seminar'}">
<p:inputTextarea style="width: 100% ; height: 100px" value="#{associationMBean.description}" ></p:inputTextarea>
</h:form>
</p:panel>
You can not update components which are not in the DOM and when a component is not rendered it is not in there. So you need to update the parent of the conditionally rendered component.
And as #{associationMBean.travelClass} is a String you need to wrap 'Seminar' with single quotes '.
i have three tab that invoke separate composite Component. my problem is, when i click on button, there is no action happend. but when i open my composite component page separately my buttons work clearly.my Buttons Are in Tab3. when in invoke ""bizbiz:inviteRequest"" in Tab3, my buttons dosnot work.
could you please see my code ?
<h:body>
<h:form>
<p:tabView >
<p:tab id="tab1" title="#{businessPartner_msg.supplier}">
<h:panelGrid columns="2" cellpadding="10">
<bizbiz:supplier/>
</h:panelGrid>
</p:tab>
<p:tab id="tab2" title="#{businessPartner_msg.customer}">
<h:panelGrid columns="2" cellpadding="10">
<bizbiz:customer/>
</h:panelGrid>
</p:tab>
<p:tab id="tab3" title="#{businessPartner_msg.inviteRequest}">
<h:panelGrid columns="2" cellpadding="10">
<bizbiz:inviteRequest/>
</h:panelGrid>
</p:tab>
</p:tabView>
</h:form>
</h:body>
my buttons in tab3 . here is Tab3
<composite:implementation>
<table style="width: 100%" id="tabell">
<p:selectOneButton value="#{inviteRequestManagedBean.filterType}">
<f:selectItem itemLabel="#{inviteRequest_msg.request}" itemValue="request" />
<f:selectItem itemLabel="#{inviteRequest_msg.archive}" itemValue="archive" />
<f:ajax event="change" execute="#form" render="#form" />
<tr>
<td>
<p:panel></p:panel>
<p:dataGrid id="requestDataGrid" var="tBusinessPartnerRequestInfo"
value="#{inviteRequestManagedBean.filterBusinessRequest()}" columns="1" >
<p:column>
<div>
<table border="0" width="100%">
<tr>
<td>
<p:graphicImage value="#{tBusinessPartnerRequestInfo.partySender_imageUrl}"/>
</td>
<td>
<div>
<table border="0" width="100%">
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.requestDate}"/>
</td>
</tr>
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.partySender_fullName}"/>
</td>
</tr>
</table>
</div>
</td>
<td>
<p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}"
update="#form"/>
</td>
<td>
<p:commandButton id="noNowCommonButton" value="#{inviteRequest_msg.notnow}"
actionListener="#{inviteRequestManagedBean.notNowRequest(tBusinessPartnerRequestInfo.id)}"
update="#form"/>
</td>
<p:blockUI block="acceptCommonButton" trigger="acceptCommonButton"/>
<p:blockUI block="noNowCommonButton" trigger="acceptCommonButton"/>
<p:blockUI block="acceptCommonButton" trigger="noNowCommonButton"/>
<p:blockUI block="noNowCommonButton" trigger="noNowCommonButton"/>
<td>
<p:panel>
<p:ajaxStatus>
<f:facet name="start">
<p:graphicImage value="../resources/img/loading.gif"/>
</f:facet>
<f:facet name="complete">
<h:outputLabel value=""/>
</f:facet>
</p:ajaxStatus>
</p:panel>
</td>
</tr>
</table>
</div>
<hr/>
</p:column>
</p:dataGrid>
</td>
</tr>
</p:selectOneButton>
</table>
</composite:implementation>
I have button that when I click on it, the dialog appear and in that dialog , I have p:selectBooleanCheckBox and h:outputlable.
The first problem is when p:dialog appear I can not choose p:selectBooleanCheckBox separately. It means that when I click on one of them, all of p:selectBooleanCheckBox choose.
The second problem is when I click on p:commandButton in dialog , the actionListener work but it dos not disappaer and it shows permanently. I think the problem cause by Ajax. could you please tell me how can I fix this problem?
<h:panelGrid>
<p:dialog appendToBody="true" header="Selected Values" modal="false" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<p:dataGrid id="AcceptDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.filterBusinessRequest()}"
columns="1" >
<tr>
<td>
<p:selectBooleanCheckbox/>
</td>
<td>
<h:outputLabel value="test"/>
</td>
</tr>
</p:dataGrid>
<p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}"
update="display" />
</h:panelGrid>
</p:dialog>
</h:panelGrid>
<table style="width: 100%" id="tabell">
<p:selectOneButton value="#{inviteRequestManagedBean.filterType}">
<f:selectItem itemLabel="#{inviteRequest_msg.request}" itemValue="request" />
<f:selectItem itemLabel="#{inviteRequest_msg.archive}" itemValue="archive" />
<f:ajax event="change" execute="#form" render="#form" />
<tr>
<td>
<p:panel></p:panel>
<p:dataGrid id="requestDataGrid" var="tBusinessPartnerRequestInfo"
value="#{inviteRequestManagedBean.filterBusinessRequest()}" columns="1" >
<p:column>
<div>
<table border="0" width="100%">
<tr>
<td>
<p:graphicImage value="#{tBusinessPartnerRequestInfo.partySender_imageUrl}"/>
</td>
<td>
<div>
<table border="0" width="100%">
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.requestDate}"/>
</td>
</tr>
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.partySender_fullName}"/>
</td>
</tr>
</table>
</div>
</td>
here is where p:dialog call
<td>
<p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
onclick="dlg.show()" />
</td>
<td>
<p:commandButton id="noNowCommonButton" value="#{inviteRequest_msg.notnow}"
actionListener="#{inviteRequestManagedBean.notNowRequest(tBusinessPartnerRequestInfo.id)}"
update="#form" />
</td>
<p:blockUI block="acceptCommonButton" trigger="acceptCommonButton"/>
<p:blockUI block="noNowCommonButton" trigger="acceptCommonButton"/>
<p:blockUI block="acceptCommonButton" trigger="noNowCommonButton"/>
<p:blockUI block="noNowCommonButton" trigger="noNowCommonButton"/>
<td>
<p:panel>
<p:ajaxStatus>
<f:facet name="start">
<p:graphicImage value="../resources/img/loading.gif"/>
</f:facet>
<f:facet name="complete">
<h:outputLabel value=""/>
</f:facet>
</p:ajaxStatus>
</p:panel>
</td>
</tr>
</table>
</div>
<hr/>
</p:column>
</p:dataGrid>
</td>
</tr>
</p:selectOneButton>
</table>
</h:panelGrid>
<h:panelGrid>
<p:dialog appendToBody="true" header="Selected Values" modal="false" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<p:dataGrid id="AcceptDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.loadPartyRelationShipType()}"
columns="1" >
<tr>
<td>
<p:selectBooleanCheckbox/>
</td>
<td>
<h:outputLabel value="test"/>
</td>
</tr>
</p:dataGrid>
<p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}"
update="display" oncomplete="dlg.hide()" />
</h:panelGrid>
</p:dialog>
</h:panelGrid>
</ui:composition>
Your markup is a bit scary, I don't get why you've got so much thing in your <p:selectOneButton (all the <tr>'s) so instead of trying to correct everything as I start to understand what you try to achieve I'll give you a working example.
Sample.java
public class Sample implements Serializable {
private String name;
private boolean checked;
public Sample() {
}
public Sample(String name, boolean checked) {
this.name = name;
this.checked = checked;
}
// Getter and Setter for name and checked omitted
}
SampleBean.java
#ManagedBean
#ViewScoped
public class SampleBean implements Serializable {
private List<Sample> samples;
private Sample currentSample;
public void prepareEdit(Sample sample) {
this.currentSample = sample;
}
public void edit() {
// Do what you need to do with sample
// You can get it with : this.currentSample
RequestContext.getCurrentInstance().execute("dlg.hide()");
}
public List<Sample> getSamples() {
if (this.samples == null) {
this.samples = new ArrayList<Sample>();
for (int i = 1; i <= 10; ++i) {
this.samples.add(new Sample("Sample n°" + i, (i % 3 == 0)));
}
}
return samples;
}
public void setSamples(List<Sample> samples) {
this.samples = samples;
}
public Sample getCurrentSample() {
return currentSample;
}
public void setCurrentSample(Sample currentSample) {
this.currentSample = currentSample;
}
}
view.xhtml :
<h:form id="myForm">
<p:dataTable value="#{sampleBean.samples}" var="sample">
<p:column headerText="Name">
<h:outputText value="#{sample.name}" />
</p:column>
<p:column headerText="Checked?">
<h:outputText value="#{sample.checked}" />
</p:column>
<p:column style="width: 1px; text-align: center;">
<p:commandButton value="edit"
actionListener="#{sampleBean.prepareEdit(sample)}"
update=":dialog"
oncomplete="dlg.show()" />
</p:column>
</p:dataTable>
</h:form>
<p:dialog id="dialog" widgetVar="dlg" header="Editing">
<h:form rendered="#{!empty sampleBean.currentSample}">
<h:outputText value="Current sample is #{sampleBean.currentSample.name}" />
<br />
<p:selectBooleanCheckbox value="#{sampleBean.currentSample.checked}" />
<br />
<p style="width: 100%; text-align: center;">
<p:commandButton actionListener="#{sampleBean.edit()}"
value="Edit"
update="#form :myForm" />
</p>
</h:form>
</p:dialog>
As you can see I'm storing a currentSample (sampleBean must be #ViewScoped) which helps me to render a custom dialog with the correct current information.
My last comment from your question about the binding of the <p:selectBooleanCheckbox is important because you can get a custom checkbox value only if it's bound to a different endpoint based on the context (here currentSample).
Don't hesitate to comment if something is unclear for you!