I am new to JSF. I am using row editable data table in JSF primefaces. In row editable datatable input text column it have two ajax calls.one is blur and another one is Commandbuuton. I want to get value from this input text column from backing bean.
Here is my Code:
<h:form id="frm1">
<p:dataTable var="fert" value="#{fertilizerEntryBean.fertList}" id="fertList" editable="true" scrollable="true" scrollWidth="900" scrollHeight="250" >
<p:ajax event="rowEdit" listener="#{fertilizerEntryBean.onEdit}" update=":frm1:messages :frm1:ha_amount" />
<p:ajax event="rowEditCancel" listener="#{fertilizerEntryBean.onCancel}" update=":frm1:messages :frm1:ha_amount" />
<p:column headerText="...." width="15">
<p:rowEditor />
</p:column>
<p:column headerText="Receiver Plot No." width="150">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{fert.receiverPlot}" /></f:facet>
<f:facet name="input">
<p:inputText id="receiverPlot" value="#{fert.receiverPlot}" size="15">
<p:ajax event="blur" listener="#{fertilizerEntryBean.loadReceiverDetails(fert)}" update="receiverCode,receiverName"/>
</p:inputText>
<p:commandButton icon="ui-icon-search" style="height: 25px;position: absolute;" onclick="receiver_dialog.show();"/>
</f:facet>
</p:cellEditor>
</p:column>
</p:datatable>
</h:form>
<h:form id="receiverForm">
<p:dialog widgetVar="receiver_dialog" id="receiver_dialog">
<p:dataTable id="receiver_table" value="#{fertilizerEntryBean.mediumFertModel}" selection="#{fertilizerEntryBean.selectedList}" selectionMode="single" var="fert" rows="10" liveScroll="true" paginator="true" paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,20">
<p:ajax event="rowSelect" listener="#{fertilizerEntryBean.onRowSelect}" update=':frm1:fertList:receiverPlot'/>
<p:column id="state_id_column" headerText="Receiver Code">
<h:outputText value="#{fert.receiverPlot}"/>
</p:column>
</p:dataTable>
<p:commandButton style="alignment-adjust: central;" value='OK' onclick="receiver_dialog.hide();"/>
</p:dialog>
</h:form>
And my Bean Class:
public class FertilizerEntryBean implements Serializable{
private List<FertModel> fertList=null;
private FertDataModel mediumFertModel;
private FertModel selectedList;
public List<FertModel> getFertList() {
return fertList;
}
public void setFertList(List<FertModel> fertList) {
this.fertList = fertList;
}
public FertDataModel getMediumFertModel() {
getReceiverCode();
return mediumFertModel;
}
public void setMediumFertModel(FertDataModel mediumFertModel) {
this.mediumFertModel = mediumFertModel;
}
public FertModel getSelectedList() {
return selectedList;
}
public void setSelectedList(FertModel selectedList) {
this.selectedList = selectedList;
}
public List<FertModel> getReceiverCode(){
Session session=HibernateUtil.getSessionFactory().openSession();
try{
List<DosVendormaster> vendorList=session.createCriteria(DosVendormaster.class).add(Restrictions.eq("vendortype", "CGRV")).add(Restrictions.eq("block", "X")).list();
if(vendorList.size()>0){
for (Iterator<DosVendormaster> it = vendorList.iterator(); it.hasNext();) {
DosVendormaster dosVendormaster = it.next();
fertList.add(new FertModel(dosVendormaster.getSapVendorcode()));
}
mediumFertModel=new FertDataModel(fertList);
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
session.close();
}
return fertList;
}
public void onRowSelect(SelectEvent event) {
FacesMessage msg = new FacesMessage(" Selected", ((FertModel) event.getObject()).getReceiverPlot());
FacesContext.getCurrentInstance().addMessage(null, msg);
FertModel fert=new FertModel();
fert.setReceiverPlot(((FertModel) event.getObject()).getReceiverPlot());
}
}