p:dataTable not updated by PrimeFaces.current().ajax().update - jsf

I am starting developpment with JSF and PrimeFace datatable. I have prepared the following xhtml page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
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>Find Capital of Countries</title>
</h:head>
<h:body>
<h:form id="FrmTest">
<p:dataTable id="ListSites" value="#{testing.SiteSearch()}" var="lst" editable="true">
<f:facet name="header">
List of Sites
</f:facet>
<p:column>
<f:facet name="header">
Site Code
</f:facet>
#{lst.stCode}
</p:column>
<p:column headerText="Site Description">
<h:outputText value="#{lst.stDescription}" />
</p:column>
<p:column headerText="is Active">
<div style="text-align: center;">
<p:selectBooleanCheckbox value="#{lst.stActive}" />
</div>
</p:column>
<p:column>
<f:facet name="header">
Site Active
</f:facet>
<div style="text-align: center;">
<h:outputText value= "#{lst.stActive}" />
</div>
</p:column>
<p:column>
<f:facet name="header">
Modified By
</f:facet>
#{lst.modifiedBy}
</p:column>
<p:column>
<f:facet name="header">
Modification Date
</f:facet>
#{lst.modifiedDate}
</p:column>
<p:column>
<f:facet name="header">
Has Error
</f:facet>
#{lst.hasError}
</p:column>
<p:column>
<f:facet name="header">
Error Description
</f:facet>
#{lst.errorDescription}
</p:column>
<p:column>
<f:facet name="header">
Row State
</f:facet>
#{lst.rowState}
</p:column>
</p:dataTable>
<h:outputLabel value="Enter Country Name:"/>
<h:inputText id="country" binding="#{testing.country}"
valueChangeListener="#{testing.findCapitalListener}"
immediate="true"
onchange="document.getElementById('findcapital').click();" />
<br/>
<br/>
<h:outputLabel value="Capital is: " />
<h:inputText id="capital" binding="#{testing.capital}" immediate="true"/>
<br/>
<br/>
<h:commandButton value="Submit" partialSubmit="true" />
<div style="visibility: hidden" >
<h:commandButton id="findcapital" value="findcapital" partialSubmit="true" immediate="true" />
</div>
</h:form>
</h:body>
</html>
I want entry made in text box named country to update datatable named ListSites. The associated listener is called (system.out.println made) but the primeface update is not made. Here is the listener:
```
public void findCapitalListener(ValueChangeEvent cdl) {
String country = cdl.getNewValue().toString();
System.out.println("Country is : " + country);
StringBuilder capitalCountry = new StringBuilder();
findCapital(country, capitalCountry);
capital.setValue(capitalCountry.toString());
siteDto = listSiteDto.get(0);
siteDto.setStDescription(capitalCountry.toString());
listSiteDto.set(0, siteDto);
PrimeFaces.current().ajax().update("FrmTest:ListSites");
//System.out.println("Capital is : " + capital.getValue());
//System.out.println("New DTO Description : " + siteDto.getStDescription());
System.out.println("New list Description : " + listSiteDto.get(0).getStDescription());
}
```

The problem was due to the fact that the function populating the datatable (SiteSearch()) was retrieving data from the database. At that stage I wanted to refresh the page display before updating the database. I replaced the function by the list getter, things are working properly now.

Related

commandButton inside p:datatable is not working [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 5 years ago.
I know there are similiar questions here but none of the solutions worked for me. Before I used primeface datatable every thing was working perfectly but I needed paginator of primefaces so I switched to primeface's datatable instead of default jsf datatable. The problem is I have a column named action where somebuttons will be placed. For instance one of the button is "Buy". When I click this button the program will take from product database and add it to cart database. This is working perfectly with jsf datatable. But in primefaces datatable it's either not doing anything or gives null point exception. This is my xhtml file. It gives null point exception if I click buy button for the first item in the datatable if I click for anything else it's not doing anything.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Shopping</title>
<h:outputStylesheet library="css" name="Product-table.css" />
</h:head>
<body>
<h:outputLabel value="Welcome #{loginBean.name}"></h:outputLabel>
<br></br>
<br></br>
<div style="width: 100%;">
<div style="width: 75%; float: left;">
<h2>Products</h2>
<h:form>
<p:dataTable var="product" value="#{databaseBean.products}"
filteredValue="#{databaseBean.filteredProducts}"
widgetVar="productWidget" paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink}
{PreviousPageLink} {PageLinks} {NextPageLink}
{LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,20,25">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search:" />
<p:inputText id="globalFilter"
onkeyup="PF('productWidget').filter()" style="width:150px"
placeholder="Search text" />
</p:outputPanel>
</f:facet>
<p:column headerText="Id" filterBy="#{product.id}" filterMatchMode="contains">
<h:outputText value="#{product.id}" />
</p:column>
<p:column headerText="Name" filterBy="#{product.name}" filterMatchMode="contains" >
<h:outputText value="#{product.name}" />
</p:column>
<p:column headerText="Price" filterBy="#{product.price}" filterMatchMode="contains">
<h:outputText value="#{product.price}" />
</p:column>
<p:column headerText="Quantity" filterBy="#{product.quantity}" filterMatchMode="contains">
<h:outputText value="#{product.quantity}" />
</p:column>
<p:column headerText="Category" filterBy="#{product.category}" filterMatchMode="contains" >
<h:outputText value="#{product.category}" />
</p:column>
<p:column>
<f:facet name="header">Action</f:facet>
<h:form>
<h:commandButton type="submit" value="#{product.id}"
name="buyLink" action="#{databaseBean.addtoCart}">
<f:param name="productId" value="#{product.id}" />
<f:param name="userId" value="#{loginBean.name}" />
</h:commandButton>
</h:form>
</p:column>
</p:dataTable>
</h:form>
</div>
<div style="width: 25%; float: right;">
<h2>Cart</h2>
<p:dataTable value="#{databaseBean.cart}" var="product"
styleClass="product-table" headerClass="product-table-header"
rowClasses="product-table-odd-row,product-table-even-row">
<p:column>
<f:facet name="header">Product ID</f:facet>
#{product.productId}
</p:column>
<p:column>
<f:facet name="header">Quantity</f:facet>
#{product.quantity}
</p:column>
</p:dataTable>
</div>
</div>
<h:form>
<h:commandButton action="#{loginBean.logout}" value="logout"></h:commandButton>
</h:form>
This is the method that the button should call. As I said it's working perfectly in default jsf datatable so I do not think anything is wrong with the java code but the problem is in xhtml file.
public void addtoCart(){
//userId = getUserID();
ManageCart MC = new ManageCart();
FacesContext fc = FacesContext.getCurrentInstance();
Map<String,String> params =
fc.getExternalContext().getRequestParameterMap();
String productIdString = params.get("productId");
int productId = Integer.parseInt(productIdString);
MC.addToChart(userId, productId, 1);
cart = mc.listCart(userId);
products = mp.listProducts();
}
I would really appreciate any help.
Thank you.
I found the solution. I needed to delete tag <h:form></h:form> from the code block of action column and it works.

Delete Rows Using Checkbox in JSF

I am trying to delete multiple rows of employee data using checkboxes. However i am having a hard time finding a way to do this. The following is some code:
DeleteEmployees.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:loadBundle basename="resources.application" var="msg"/>
<head>
<title><h:outputText value="#{msg.welcomeTitle}" /></title>
</head>
<h:body>
<h:dataTable value="#{empController.list}" var="emp" border="2">
<h:column>
<f:facet name="header">
<h:outputText value="First Name"/>
</f:facet>
<h:outputText value="#{emp.firstName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Last Name"/>
</f:facet>
<h:outputText value="#{emp.lastName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{emp.email}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Phone"/>
</f:facet>
<h:outputText value="#{emp.phone}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Hire Date"/>
</f:facet>
<h:outputText value="#{emp.hireDate}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Manager ID"/>
</f:facet>
<h:outputText value="#{emp.managerId}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Department ID"/>
</f:facet>
<h:outputText value="#{emp.departmentId}"/>
</h:column>
<h:column>
<f:facet name="header">Delete</f:facet>
<h:form>
<h:selectBooleanCheckbox value="#{empController.checked[emp.id]}"/>
</h:form>
</f:facet>
</h:column>
</h:dataTable>
<h:commandButton value="Delete Employees" action="#{empController.delEmp}"/>
</h:body>
</html>
In my Managed bean i have this method in order to delete the ID. However the objects are not being deleted. I need some guidance here thank you!
public void delEmp(){
list = em.getAllEmployees();
for(Employee e : list){
if(checked.get(e.getId())){
em.deleteEmployee(e.getId());
}
}
checked.clear();
}
Your h:commandButton is not nested within the h:form. It needs to be nested for the form data to submit. Note that this is not a JSF limitation, but an HTML limitation.
See also
Call another form from the command button

after editing a cell in datatableEditor the output text still display the old Value primefaces

I am using JSF 2.2 with PrimeFaces 5.0. I have a dataTable with cell-editing.
I am having the dataTable inside dialog when I set editMode="cell", the outputtext after editing it's doesn't appear, but when i put the datatable edit outside dialog, it's work.When I inspect the element of datatable it's empty but if i put the datatable edtor outside dialog the outPut element isn't empty
===>when i click to edit the cell the input have the new value but the outputext still have the old value
===>so here my page
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<h:form id="lotRecepForm">
<p:dataTable value="#{lotRecpBean.liste}"
var="lotRecp"
id="tbl">
<p:column>
<f:facet name="header">
<span class="nomColonneTab">Lot Réception</span>
</f:facet>
<h:outputText value="#{lotRecp.codeLotReception}"/>
</p:column>
<p:column>
<f:facet name="header">
<span class="nomColonneTab">Entrant</span>
</f:facet>
<h:outputText value="#{lotRecp.entrant.designation}"/>
</p:column>
<p:column>
<f:facet name="header">
<span class="nomColonneTab">Date Réception</span>
</f:facet>
<h:outputText value="#{lotRecp.dateReception}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<span class="nomColonneTab">Quantite Livrée</span>
</f:facet>
<h:outputText value="#{lotRecp.quantiteLivree}"/>
</p:column>
<p:column headerText="Action" exportable="false" styleClass="nomColonneTab">
<p:commandButton icon="ui-icon-arrowrefresh-1-w"
update=":content:modif"
oncomplete="PF('w_edit').show();" styleClass="buttonAction">
<f:setPropertyActionListener value="#{lotRecp}" target="#{lotRecpBean.currentLotReception}" />
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
<p:dialog id="modif" width="80%" widgetVar="w_edit" modal="true" >
<p:tabView >
<p:tab title="Controle de Réception ">
<h:form>
<h:panelGrid>
<p:dataTable id="data1" value="#{normeMicroEBean.listOfNorme(lotRecpBean.currentLotReception.entrant)}"
var="item" editable="true" editMode="cell" >
<p:column headerText="Valeur Controle" styleClass="ui-editable-column">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{item.valeurControle}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{item.valeurControle}" style="width: 50%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column width="15%" headerText="Testeur">
<p:cellEditor >
<f:facet name="output"><h:outputText value="#{item.testeurCR.nom}" /></f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{item.testeurCR.nom}" style="width:50%">
<f:selectItems value="#{personnelBean.liste}" var="perso" itemLabel="#{perso.nom}" itemValue="#{perso}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:panelGrid>
<h:form>
</p:tab>
<p:tab title="Info lot de Réception">
<h:form>
<p:panelGrid id="idPanel">
<p:row>
<p:column><p:outputLabel value="QuantiteLivree:" for="quantiteLivree" /></p:column>
<p:column><p:inputText id="quantiteLivree" value="#{lotRecpBean.currentLotReception.quantiteLivree}" title="QuantiteLivree" /></p:column>
<p:column><p:outputLabel value="QuantiteRecue:" for="quantiteRecue" /></p:column>
<p:column><p:inputText id="quantiteRecue" value="#{lotRecpBean.currentLotReception.quantiteRecue}" title="QuantiteRecue" /></p:column>
<p:column><p:outputLabel value="NumBonLivraison:" for="numBonLivraison" /></p:column>
<p:column><p:inputText id="numBonLivraison" value="#{lotRecpBean.currentLotReception.numBonLivraison}" title="NumBonLivraison" /></p:column>
</p:row>
</p:panelGrid>
<div>
<p:commandButton action="#{lotRecpBean.update()}" value="Enregistrer" styleClass="button"
style="float: right" oncomplete="PF('lotRecepTable').filter();PF('w_edit').hide();" />
</div>
</h:form>
</p:tab>
</p:tabView>
</p:dialog>
I fixed the problem , it's come from the value of datatable ===> the value of datatable editor must be a list and not a method which return a list datatable editor work just with a list 1-
<p:dataTable id="data1" value="#{normeMicroEBean.listOfNorme}"
var="item" editable="true" editMode="cell" >
I create a list in the managed bean t and in the button i execute the method to full the list created in the managed bean . thank you for your response

Primefaces, right way to use form tag

I have an xhtml in which I wrap two model dialogs in one form ( I wrap the whole body ). As a result when I try to submit the content on one dialog, I get validation errors from the other dialog.
When I seperate the forms for each dialog, I get warnings regarding I should wrap the whole content under one form ( or so I have interpreted ).
What is the correct way to use form tag both under this example and in general ?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view>
<h:head>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta http-equiv="Content-Type" content="text/html;charset=utf8"/>
</h:head>
<h:body id="templateBody">
<h:form id="userForm" prependId="false">
<p:messages id="mymessages" autoUpdate="true" showDetail="true"/>
<h:panelGrid columns="4" id="operationBtnsGrid">
<p:commandButton value="New" icon="ui-icon-plusthick" onclick="newDialog.show();"/>
<p:commandButton value="Update" update="dataTable" icon="ui-icon-pencil"
disabled="#{userController.userModels.selectedUser.id==null}"
onclick="updateDialog.show();"/>
<p:commandButton id="Delete" value="Delete" update="dataTable" onclick="confirmation.show()"
icon="ui-icon-trash" disabled="#{userController.userModels.selectedUser.id==null}"/>
</h:panelGrid>
<p:dataTable id="dataTable"
var="user"
value="#{userController.findAll()}"
rowKey="#{user.id}"
selectionMode="single"
selection="#{userController.userModels.selectedUser}">
<f:facet name="header">
<h:outputText value="User List"/>
</f:facet>
<p:ajax event="rowSelect" update="#(form)"/>
<p:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{user.name}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Lastname"/>
</f:facet>
<h:outputText value="#{user.lastname}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Phone Number"/>
</f:facet>
<h:outputText value="#{user.phoneNumber}"/>
</p:column>
</p:dataTable>
<p:dialog header="Add New User" widgetVar="newDialog" modal="true">
<p:panelGrid columns="2">
<h:outputLabel for="new_name" value="Name: "/>
<p:inputText id="new_name" required="true" value="#{userController.userModels.newUser.name}"/>
<h:outputLabel for="new_lastname" value="Lastname: "/>
<p:inputText id="new_lastname" required="true" value="#{userController.userModels.newUser.lastname}"/>
<h:outputLabel for="new_phoneNumber" value="Phone number: "/>
<p:inputMask id="new_phoneNumber" value="#{userController.userModels.newUser.phoneNumber}" mask="(999) 999-9999"/>
</p:panelGrid>
<p:panelGrid columns="1">
<p:captcha label="Captcha" language="en" theme="white"/>
</p:panelGrid>
<p:commandButton id="saveNewButton" actionListener="#{userController.addNewUser}"
oncomplete="confirmation.hide()" update="#(form), #(#mymessages)" value="Save"
ajax = "false" icon="ui-icon-check"/>
</p:dialog>
<p:dialog header="Update User" widgetVar="updateDialog" modal="true">
<p:panelGrid columns="2">
<h:outputLabel for="update_name" value="Name: "/>
<p:inputText id="update_name" required="true" value="#{userController.userModels.selectedUser.name}"/>
<h:outputLabel for="update_lastname" value="Lastname: "/>
<p:inputText id="update_lastname" required="true" value="#{userController.userModels.selectedUser.lastname}"/>
<h:outputLabel for="update_phoneNumber" value="Phone number: "/>
<p:inputMask id="update_phoneNumber" value="#{userController.userModels.selectedUser.phoneNumber}" mask="(999) 999-9999"/>
</p:panelGrid>
<p:commandButton id="updateSelectedButton" actionListener="#{userController.updateUser}"
oncomplete="confirmation.hide()" update="#(form), #(#mymessages)" value="Save"
ajax = "false" icon="ui-icon-check"/>
</p:dialog>
<p:confirmDialog id="confirmDialog" message="Silmek istediğinizden emin misiniz ?"
header="Silmek için onayınız gerekiyor" severity="alert" widgetVar="confirmation">
<p:commandButton id="confirm" value="Evet" oncomplete="confirmation.hide()"
actionListener="#{userController.deleteUser}"
ajax = "false" update="#(form), #(#mymessages)"/>
<p:commandButton id="decline" value="Hayır" onclick="confirmation.hide()" type="button"/>
</p:confirmDialog>
</h:form>
<p:ajaxStatus style="width:64px;height:64px;position:fixed;right:5px;bottom:5px">
<f:facet name="start">
<p:graphicImage value="/images/ajax-loader.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</h:body>
</f:view>
</html>
When you do a form submit it submits the whole form and all ids, you have them all on the page so they fail validations.
You can either:
A) Use 'rendered' on your div blocks to hide them from the dom based on conditions, but not likely due to you wanting to have an update/new - its kind of difficult.
B) use PPR (Partial Tree Processing)
http://www.primefaces.org/showcase/ui/pprPartialTree.jsf
On your commandbutton - add 'process="update_name, update_lastname, update_phoneNumber"'
This will only submit those fields to be updated, or if you wrap them in a block with an id you can just do process="blockToUpdate"

Primefaces taking random form ID [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
What is the way to refresh page in primefaces?
I have tried
<p:commandLink actionListener="#{legendcontroller.addEditLegendType(true,false)}" update="legendform:pnlform" >Add Legend</p:commandLink>
<p:commandLink immediate="true" actionListener="#{legendcontroller.addEditLegendType(false,false)}" update="legendform:pnlform" >View Legend </p:commandLink>
<p:commandLink id="editLink" value="Edit" actionListener="#{legendcontroller.editLegendType(legendtype)}" update=":legendform:pnlform" process="#this"/>
The third one would generate error in page with datatable. The error I get:
Cannot find component with expression "pnlform" referenced from "j_idt22:legendviewdatatable:0:editLink". I would like to refresh the form when I hit edit and open editpanel. And I would like to refresh only datatable when I hit delete.
The full html:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
<title>Legend</title>
</h:head>
<h:body>
<ui:composition template="/generalTemplate.xhtml">
<ui:define name="title">Legend </ui:define>
<ui:define name="content" >
<f:view>
<h:form id="legendform" prependId="false" >
<p:panel id="pnlform">
<f:facet name="header">
<p:commandLink actionListener="#{legendcontroller.addEditLegendType(true,false)}" update="legendform:pnlform" >Add Legend</p:commandLink>
<p:commandLink immediate="true" actionListener="#{legendcontroller.addEditLegendType(false,false)}" update="legendform:pnlform" >View Legend </p:commandLink>
</f:facet>
<p:panel id="addeditpnl" rendered="#{legendcontroller.addLegendBool or legendcontroller.editLegendBool}" style="width:100%">
<h:panelGrid columns="2" >
<h:outputLabel value="Legend Name" for="legendname" />
<h:inputText id="legendname" value="#{legendcontroller.legendType.legendname}" title="Legendname" required="true" requiredMessage="The Legendname field is required."/>
<h:outputLabel value="Legend Description" for="legendDesc" />
<h:inputText id="legendDesc" value="#{legendcontroller.legendType.legendDesc}" title="LegendDesc" />
<h:outputLabel value="Legend For" for="legendfor" />
<h:inputText id="legendfor" value="#{legendcontroller.legendType.legendfor}" title="Legendfor" required="true" requiredMessage="The Legendfor field is required."/>
</h:panelGrid>
<p:dataTable id="addeditdtable" value="#{legendcontroller.legendType.legendList}" var="legend" style="width:100%">
<p:column>
<f:facet name="header">
<h:outputText value="Legend SN"/>
</f:facet>
<h:inputText value="#{legend.legendSn}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="LegendDesc"/>
</f:facet>
<h:inputText value="#{legend.legendDesc}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Lower Range"/>
</f:facet>
<h:inputText value="#{legend.lowerrange}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Upper Range"/>
</f:facet>
<h:inputText value="#{legend.upperrange}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Color"/>
</f:facet>
<p:colorPicker value="#{legend.color}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="ADD/Delete"/>
</f:facet>
<p:commandLink value="Add" actionListener="#{legendcontroller.addLegendAfter(legend)}" update="addeditdtable" process="#this"/>
<h:outputText value=" / "/>
<p:commandLink value="Delete" actionListener="#{legendcontroller.removeLegendDTO(legend)}" update="addeditdtable" process="#this"/>
</p:column>
<f:facet name="footer">
<p:commandButton value="SAVE" action="#{legendcontroller.saveLegend()}"/>
</f:facet>
</p:dataTable>
</p:panel>
<p:dataTable id="legendviewdatatable" value="#{legendcontroller.allLegendType()}" rendered="#{!legendcontroller.addLegendBool and !legendcontroller.editLegendBool}" var="legendtype" style="width:100%">
<p:column>
<f:facet name="header">
<h:outputText value="Legendname"/>
</f:facet>
<h:outputText value="#{legendtype.legendname}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="LegendDesc"/>
</f:facet>
<h:outputText value="#{legendtype.legendDesc}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Legendfor"/>
</f:facet>
<h:outputText value="#{legendtype.legendfor}"/>
</p:column>
<p:column id="editDelCol">
<f:facet name="header">
<h:outputText value="Edit/Delete"/>
</f:facet>
<p:commandLink id="editLink" value="Edit" actionListener="#{legendcontroller.editLegendType(legendtype)}" update=":legendform:pnlform" process="#this"/>
<h:outputText value=" / "/>
<p:commandLink id="deleteLink" value="Delete" actionListener="#{legendcontroller.deleteLegendType(legendtype)}" update="legendviewdatatable" process="#this" />
</p:column>
</p:dataTable>
</p:panel>
</h:form>
</f:view>
</ui:define>
</ui:composition >
</h:body>
</html>
Finally I found that primefaces is not taking the id gave but is using random id:
<form id="j_idt12" name="j_idt12" method="post" action="/Configuration/LegendManager/LegendType.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt12" value="j_idt12">
<div id="j_idt12:j_idt13" class="ui-toolbar ui-widget ui-widget-header ui-corner-all ui-helper-clearfix"><div class="ui-toolbar-group-left"><button id="j_idt12:j_idt15" name="j_idt12:j_idt15" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left" title="Welcome" type="submit" role="button" aria-disabled="false"><span class="ui-button-icon-left ui-icon ui-c ui-icon-disk"></span><span class="ui-button-text ui-c">Home</span></button><button id="j_idt12:j_idt16" name="j_idt12:j_idt16" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left" title="Configuration" type="submit" role="button" aria-disabled="false"><span class="ui-button-icon-left ui-icon ui-c ui-icon-disk"></span><span class="ui-button-text ui-c">Configuration</span></button></div><div class="ui-toolbar-group-right"><span id="j_idt12:j_idt18" class="ui-menubutton"><button id="j_idt12:j_idt18_button" name="j_idt12:j_idt18_button" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left" role="button" aria-disabled="false"><span class="ui-button-icon-left ui-icon ui-c ui-icon-triangle-1-s"></span><span class="ui-button-text ui-c">sugandha</span></button></span></div></div><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="2044288989474132123:952602282947229034" autocomplete="off">
</form>
Since you used prependId="false", you should use update="pnlform" only, or remove prependId="false" so you will be able to keep update="yourformname:yourid" or update=":yourid".
More info :
h:form
change your code as follow: <h:form id="legendform" prependId="true" > or without prependId attribute then reference to nested component inside this form with update=":legendform:pnlform" attribute from every where else.
in your case if you want to set prependId=false and then reference from nested components inside <datatable> in same form you should update withupdate=":pnlform".
this is because <datatable> has own NamingContainer

Resources