I need your help in enabling and disabling inputText based on rowSelectCheckbox and rowUnselectCheckbox if the checkbox is ticked or unticked. If it is ticked, then I need to enable the inputText otherwise it should be disabled on page load and on untick. By default the inputText is disabled on the page load. Here is the code for the jsf:
<h:form id="request">
<p:dataTable value="#{dataTableView.employeeList}" id="Employee" var="emp"
selection="#{dataTableView.selectedEmployees}" rowKey="#{emp.id}">
<p:ajax event="rowSelectCheckbox" listener="#{dataTableView.EnableInputText}" />
<p:ajax event="rowUnselectCheckbox" listener="#{dataTableView.EnableInputText}" />
<p:columnGroup type="header">
<p:row>
<p:column/>
<p:column headerText="ID"/>
<p:column headerText="Name"/>
<p:column headerText="Location"/>
<p:column headerText="Remarks"/>
</p:row>
</p:columnGroup>
<p:column selectionMode="multiple" style="width:2%;text-align:center"/>
<p:column headerText="ID">
<h:outputText value="#{emp.id}"/>
</p:column>
<p:column headerText="Name">
<h:outputText value="#{emp.name}"/>
</p:column>
<p:column headerText="Location">
<h:outputText value="#{emp.location}"/>
</p:column>
<p:column headerText="Remarks">
<h:inputText id="inputT1" value="#{emp.remarks}" disabled="#{emp.disable}"/>
</p:column>
</p:dataTable>
</h:form>
And here is the code in the bean:
private List<Student> employeeList = new ArrayList<Student>();
private List<Student> selectedEmployees;
private boolean disable;
#PostConstruct
public void init() {
//add Employees
disable=true;
Student w1 = new Student(111, "AAAA", "ZZZZ", "", disable);
Student w2 = new Student(222, "CCCCC", "ZZZZZ", "OUT", disable);
Student w3 = new Student(222, "BBBBBB", "YYYYYYY", "IN", disable);
employeeList.add(w1);
employeeList.add(w2);
employeeList.add(w3);
}
public void EnableInputText(SelectEvent event) {
for(int i=0;i<=selectedEmployees.size();i++){ //Assuming you have declared as List
for(int j=0;j<=employeeList.size();j++){
if(selectedEmployees.get(i).getId().equals(employeeList.get(j).getId()))
{
employeeList.get(j).setDisable(false);
break;
}
}
}
}
The Student Bean:
public class Student {
private Integer id;
private String name;
private String location;
private String remarks;
private boolean disable;
public Student(Integer id, String name, String location, String remarks, boolean disable){
this.id = id;
this.name = name;
this.location = location;
this.remarks=remarks;
this.disable=disable;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setLocation(String location) {
this.location = location;
}
public String getLocation() {
return location;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public String getRemarks() {
return remarks;
}
public void setDisable(boolean disable) {
this.disable = disable;
}
public boolean isDisable() {
return disable;
}
And in the Bean, I am facing difficulties in enabling the inputText for entry if the row is ticked. So could you please help.
Now I got the error :
java.lang.IndexOutOfBoundsException: Index: 3, Size: 3 if I tick and checkbox
First thing you are using selectionMode="multiple" it means there will be multiple rows with textField enabled next
instead of this :
<h:inputText value="#{emp.remarks}" disabled="#{empBean.enable}" />
write
<h:inputText value="#{emp.remarks}" disabled="#{emp.enable}" />
means declare one variable enable in the bean itself after that:
for(int i=0;i<=selectedEmployees.size();i++){ //Assuming you have declared as List
for(int j=0;j<=empList.size();j++){
if(selectedEmployees.get(i).getId().equals(empList.get(j).getId()){
empList.get(j).setEnable(false);
}
}
}
before to this you can write one for loop and disable all the textField for list for that will work for rowUnselect
Related
When i am not using filter in primefaces datatable and try to select row then for example press edit it working well and takes the selected row.but when i use primefaces filter and then select the filtered row then edit
i got org.primefaces.model.SelectableDataModel when selection is enabled exception.
i know that mean i have a null row key but i don't know why.i am using a valid row key(id) the primary key of the datatable and when i use the debug i found that it get the id two times in the failure case,first time it got the right filtered id and the second time it get null id.
my question why it gets the rowkey id two times which get the null in the second time and cause the exception
<h:body>
<h:form prependId="false" id="growlForm">
<p:growl id="growl" showDetail="false" />
</h:form>
<h:form id="dataForm">
<p:panel id="ingerdientsTable">
<f:facet name="header">
<h:outputText value="Standard Food List" />
</f:facet>
<p:dataTable id="ingedientsTable" widgetVar="ingedientsTable" var="ingerdients" resizableColumns="true"
selectionMode="single" selection="#{mealBean.selectedStandardIngerdients}"
rowKey="#{ingerdients.getId()}" value="#{mealBean.allIngerdients}" rowsPerPageTemplate="5,10,25,50" rows="20"
paginator="true" style="padding-top:10px;padding-bottom:10px" tableStyle="table-layout: auto"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} ">
<p:column headerText="Food Type" filterBy="#{ingerdients.name}"><h:outputText value="#{ingerdients.name}" /></p:column>
<p:column headerText="Protein(gm)" filterBy="#{ingerdients.containedProtiens}"><h:outputText value="#{ingerdients.containedProtiens}" /></p:column>
<p:column headerText="Carbs(gm)" filterBy="#{ingerdients.containedCarbs}"><h:outputText value="#{ingerdients.containedCarbs}" /></p:column>
<p:column headerText="Fats(gm)" filterBy="#{ingerdients.containedFats}"><h:outputText value="#{ingerdients.containedFats}" /></p:column>
<p:column headerText="Total Calories" filterBy="#{ingerdients.totalCalories}"><h:outputText value="#{ingerdients.totalCalories}" /></p:column>
<p:column styleClass="action-column">
<f:facet name="header">
<h:outputText value="Actions" />
</f:facet>
<p:commandButton id="addToMeal" value="Add To Meal" icon="ui-icon-create" update="addToMealDialog"
action="#{mealBean.showIngerdientsToMealDialog(ingerdients)}" immediate="true"
title="Add To meal" ajax="true">
</p:commandButton>
<p:tooltip for="addToMeal" value="Add To Meal"
showEffect="fade" hideEffect="fade" />
</p:column>
</p:dataTable>
</p:panel>
public class StandardIngerdients{
#Id
#Column(name="Id")
#GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
#ManyToOne
#JoinColumn(name="FolderPathId",referencedColumnName="Id",nullable=true)
private FolderPath folderPath;
#Column(name="Name")
private String name;
#Column(name="ContainedProteins")
#NotNull
private Double containedProtiens;
#Column(name="ContainedCarbs")
#NotNull
private Double containedCarbs;
#Column(name="ContainedFats")
#NotNull
private Double containedFats;
#Column(name="TotalCalories")
#NotNull
private Double totalCalories;
#Column(name="ImageName")
private String imageName;
public Integer getId() {
return id;
}
public void setId(Integer Id) {
this.id = Id;
}
public FolderPath getFolderPath() {
return folderPath;
}
public void setFolderPath(FolderPath folderPath) {
this.folderPath = folderPath;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getContainedProtiens() {
return containedProtiens;
}
public void setContainedProtiens(Double containedProtiens) {
this.containedProtiens = containedProtiens;
}
public Double getContainedCarbs() {
return containedCarbs;
}
public void setContainedCarbs(Double containedCarbs) {
this.containedCarbs = containedCarbs;
}
public Double getContainedFats() {
return containedFats;
}
public void setContainedFats(Double containedFats) {
this.containedFats = containedFats;
}
public Double getTotalCalories() {
return totalCalories;
}
public void setTotalCalories(Double totalCalories) {
this.totalCalories = totalCalories;
}
public String getImageName() {
return imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
}
I was having the same problem. The thing is I make my class to implement Serializable which guarantee the "integrity" (so to speak) of data in order not to disappear hehe... so your class would be like this:
public class StandardIngerdients implements Serializable {
you can try below code i think solve it
rowKey="#{ingerdients.id}"
i have a datatable :
<p:dataTable id="marksTable"
var="item"
value="#{markingBean.markToEdit}"
rowKey="#{markingBean.markToEdit}"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15"
scrollable="true"
liveScroll="true"
scrollRows="20"
emptyMessage="No details was found with given criteria">
<p:column headerText="#{bundle.labelMarkSectionOne} ">
<h:outputText value="#{item.markSectionOne}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionTwo}">
<h:outputText value="#{item.markSectionTwo}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionThree}">
<h:outputText value="#{item.markSectionThree}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionFour}">
<h:outputText value="#{item.markSectionFour}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionFive}">
<h:outputText value="#{item.markSectionFive}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionSix}">
<h:outputText value="#{item.markSectionSix}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionSeven}">
<h:outputText value="#{item.markSectionSeven}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionEight}">
<h:outputText value="#{item.markSectionEight}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionNine}">
<h:outputText value="#{item.markSectionNine}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionTen}">
<h:outputText value="#{item.markSectionTen}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionEleven}">
<h:outputText value="#{item.markSectionEleven}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionTwelve}">
<h:outputText value="#{item.markSectionTwelve}" />
</p:column>
<p:column headerText="#{bundle.labelMarkSectionThirteen}">
<h:outputText value="#{item.markSectionThirteen}" />
</p:column>
</p:dataTable>
this will only show one row, what i want to do is simply add up all these values and then take the average
how best can i do this ?
EDIT
as request
The data is retrived from a database where all values are stored, in the data table it only displays one row from the db one pre selected before hand
This is the marking bean
#Named(value = "markingBean")
#ViewScoped
//#RequestScoped
public class MarkingController {
private String searchString;
private String ordering;
private String criteria;
private String match;
private Date today;
private String caseMatch;
private Boolean changed;
//private Marking markSectionOne;
// private Marking studentNumber;
// private Marking markSectionTwo;
// private Marking markToEdit;
private int spinnerField;
private Marking markToCreate, markToEdit;
private String searchMark;
private List<Marking> userSearchResults;
private List<Marking> marksList;
private Person user;
private Progress progress;
private Marking marking;
private Boolean isCompleted;
private String disabled;
private boolean value1;
private boolean value2;
private List<String> selectedOptions;
private Integer option;
private Integer number;
private List<Marking> totalMark;
#Inject
PersonFacade personFacade;
#Inject
CohortFacade cohortFacade;
#Inject
MilestoneFacade milestoneFacade;
#Inject
ProjectFacade projectFacade;
#Inject
ProgressFacade progressFacade;
#Inject
MilestoneService milestoneService;
#Inject
MarkingFacade markingFacade;
#Inject
MarkingService markingService;
#PostConstruct
public void init() {
this.markToCreate = new Marking();
this.marking = new Marking();
this.marksList = markingFacade.findAll();
// totalMark = mark.list();
changed = false; //required otherwise will work opposite of how we want
String username = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
// Get the logged in user
List<Person> usernameSearchResults = this.personFacade.usernameSearch(FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName());
if (usernameSearchResults.size() > 0) {
this.user = usernameSearchResults.get(0);
}
String marking_id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("edit_id");
System.out.println(marking_id);
if (marking_id != null) {
this.markToEdit = this.markingFacade.find(Long.parseLong(marking_id));
}
}
public void createMarkingOne() {
System.out.println("in Create mark one");
this.markingService.createMarking(this.markToCreate);
// this.markingFacade.create(this.markToCreate);
this.setMessage(" saved");
}
public void createMarking() {
System.out.println("in Create mark");
this.markingService.createMarking(this.markToCreate);
// this.markingFacade.create(this.markToCreate);
this.setMessage(" saved");
}
private void setMessage(String message) {
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage(null, new FacesMessage(message, ""));
}
/* Delete mark*/
public void deleteMark(Marking markToDelete) {
/* this.markingService.deleteMark(markToDelete);
listMarks(); //need to add the list marks function
this.setMessage("Mark has been deleted.");*/
//this.markingFacade.remove(this.marking_id);
}
// Edit existing marks
public void editMark() throws IOException {
System.out.println("in edit mark");
this.markingFacade.edit(this.markToEdit);
this.setMessage("Mark(s) for the project has been successfully been recorded.");
MarkingLog loadProp = new MarkingLog(); // re anable for testing when finished
loadProp.loadProp();
}
public void addMessage(boolean markingCompleted) {
String summary = markingCompleted ? "Checked" : "Unchecked";
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(summary));
}
public void editChange() {
changed = true;
}
/**
* SEARCHES *
*/
//for the advanced search query
public void basicMarkingSearch() {
userSearchResults = markingFacade.basicMarkingSearch(searchString, criteria, ordering, match);
}
public void testMarkingSearch() {
userSearchResults = markingFacade.testMarkingSearch(searchString, ordering, match);
}
Marking entity
#Entity(name = "MARKING")
public class Marking implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
#ManyToOne
private Person marker;
#ManyToOne
private Project project;
// #ManyToOne
// private Project project;
//#ManyToMany(mappedBy = "title")
//private Project projectBeMarked;
private String markingCompleted, markSectionOne, markSectionTwo, markSectionThree, markSectionFour,
markSectionFive, markSectionSix, markSectionSeven, markSectionEight,
markSectionNine, markSectionTen, markSectionEleven, markSectionTwelve, markSectionThirteen, markAdjust, overalMark, thirdMarker, plagorism;
What i am trying to do, is add up a row markSectionOne to Thirteen and then take the average and display this to the user
I have the CommandLink/CommandButton which is an element of the column in the dataTable. The dataTable is integrated with the lazy model. My code (not exactly my, because this is the primefaces showcase example) works perfect when the number of records in the table is divisible by the page size. For example the page size is 5 and the number of records is 60. But, when the number of records is 61, then when I reach the last record in the table, the action listener for every button is not called. I've tried to change p:commandlink to h:commandbutton/p:commandbuton. I've tried all the stackoverflow tips related to use update="#form" or immediate="true" or disable ajax requests by ajax="false", but the result is the same. For me it looks like a problem with dataTable rendering. Please look at the source code. This example is based on the primefaces showcase, I've added only a new column (this one with the commandlink).
xhtml page:
<h:form id="form">
<p:dataTable styleClass="test-class" id="data" var="car" value="#{tableBean.lazyModel}" scrollable="true" liveScroll="true" scrollRows="5" scrollHeight="200" lazy="true" >
<p:column headerText="Model">
<h:outputText value="#{car.model}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Manufacturer">
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
<p:column headerText="Color">
<p:commandLink value="Test"
actionListener="#{tableBean.buttonListener()}" />
</p:column>
</p:dataTable>
</h:form>
datatable lazy model:
public class MyLazyModel extends LazyDataModel<Car> {
private List<Car> datasource;
public MyLazyModel(List<Car> datasource) {
this.datasource = datasource;
}
#Override
public Car getRowData(String rowKey) {
for(Car car : datasource) {
if(car.getModel().equals(rowKey))
return car;
}
return null;
}
#Override
public Object getRowKey(Car car) {
return car.getModel();
}
#Override
public List<Car> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
//rowCount
int dataSize = datasource.size();
this.setRowCount(dataSize);
//paginate
if(dataSize > pageSize) {
try {
return datasource.subList(first, first + pageSize);
}
catch(IndexOutOfBoundsException e) {
return datasource.subList(first, first + (dataSize % pageSize));
}
}
else {
return datasource;
}
}
}
DataTable bean:
#ManagedBean
#ViewScoped
public class TableBean {
private LazyDataModel<Car> lazyModel;
private Car selectedCar;
private List<Car> cars;
public TableBean() {
populateRandomCars(cars, 60);
lazyModel = new MyLazyModel(cars);
}
public void setSelectedCar(Car selectedCar) {
this.selectedCar = selectedCar;
}
public LazyDataModel<Car> getLazyModel() {
return lazyModel;
}
How would it be possible to retrieve an inputText value foreach row in JSF dataTable, since this data is not an attribute in the object on which we iterate in the loop.
(here 0 as default value). I can't change the Class properties (here Product)
<h:form>
<p:dataTable var="product" value="#{bean.products}">
<p:column headerText="Id">
<h:outputText value="#{product.id}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{product.name}" />
</p:column>
<p:column headerText="Quantity">
<h:inputText size="3" value="0" />
</p:column>
</p:dataTable>
<h:commandButton value="Submit" action="#{bean.submit}"/>
</h:form>
Bean.class
#ManagedBean
...
public void submit() {
List<Product> products = this.getProducts();
for(Product product : list) {
System.out.println("Product.name : "+ Product.name );
System.out.println("Quantity : "+ ?? );
}
}
Bind it to a Map with Product (or its ID) as key.
E.g.
private List<Product> products;
private Map<Product, Long> quantities;
#EJB
private ProductService productService;
#PostConstruct
public void init() {
products = productService.list();
quantities = new HashMap<>();
}
public void submit() {
for (Product product : products) {
Long quantity = quantities.get(product);
System.out.println("Quantity: " + quantity);
}
}
// Getters (no setters necessary for those two properties)
with
<h:inputText size="3" value="#{bean.quantities[product]}" />
You can use the visitor pattern to get the values. Something like this:
table.visitTree(VisitContext.createVisitContext(faces),
new VisitCallback() {
#Override public VisitResult visit(VisitContext vc, UIComponent component) {
if (component.equals(quantity) && quantity.getValue() != null) {
cart.addItem(
(Product) table.getRowData(),
(Integer) quantity.getValue());
}
return VisitResult.ACCEPT;
}
});
I m trying to display data in jsf datable data from the database,ans in a same row i m displaying link for Edit. Now when user will clicked on edit button then it should be inputText from outputText. Here i have done coding for that but i can't change the textbox can u please help me? Thanks in advance.
ShowData.xhtml
<h:dataTable value="#{customerdata.customerList}" var="c"
styleClass="order-table" binding="#{customerdata.dataTable}"
headerClass="order-table-header" border="1" width="100%"
rowClasses="order-table-odd-row,order-table-even-row" rows="3">
<h:column>
<h:selectBooleanCheckbox></h:selectBooleanCheckbox>
</h:column>
<h:column>
<f:facet name="heder">User ID</f:facet>
<h:inputText value="#{c.cust_id}" size="10" rendered="#{c.editable}"/>
<h:outputLabel value="#{c.cust_id}" rendered="#{not c.editable}" />
</h:column>
<h:column>
<f:facet name="heder">User Name</f:facet>
<h:inputText value="#{c.cust_name}" size="10" rendered="#{c.editable}"/>
<h:outputLabel value="#{c.cust_name}" rendered="#{not c.editable}" />
</h:column>
<h:column>
<h:commandLink value="Update" rendered="#{c.editable}" action="#{customerdata.editAction(c)}" />
<h:commandLink value="Edit" action="#{customerdata.editAction(c)}" rendered="#{not c.editable}"/>
</h:column>
<h:column>
<h:commandLink value="Delete" action="#{customerdata.deleteAction(c)}" />
</h:column>
<!-- Footer Setting -->
<f:facet name="footer">
<h:panelGroup>
<h:commandButton value="prev" action="#{customerdata.pagePrevious}"
disabled="#{customerdata.dataTable.first == 0}" />
<h:commandButton value="next" action="#{customerdata.pageNext}"
disabled="#{customerdata.dataTable.first + customerdata.dataTable.rows
>= customerdata.dataTable.rowCount}" />
</h:panelGroup>
</f:facet>
</h:dataTable>
CustomerData.java
package model;
#ManagedBean(name="customerdata")
public class CustomerData implements Serializable {
private static final long serialVersionUID = 1L;
Connection con;
Statement smt;
HtmlDataTable dataTable;
//Customer cust=new Customer();
public List<Customer> getcustomerList() throws SQLException{
//System.out.println("in getcustomerlist");
List<Customer> list= new ArrayList<Customer>();
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/openid","root","root");
smt = con.createStatement();
String query="select * from jsftable";
ResultSet rs= smt.executeQuery(query);
while(rs.next()){
Customer cust = new Customer();
cust.setCust_id(rs.getInt("cust_id"));
cust.setCust_name(rs.getString("cust_name"));
cust.setHas_attachment(rs.getBoolean("has_attachment"));
System.out.println("in cusotomer data"+cust.isEditable());
//store all data into a List
list.add(cust);
}
}
catch(Exception e){
e.printStackTrace();
}
return list;
}
public void pageFirst() {
dataTable.setFirst(0);
}
public void pagePrevious() {
dataTable.setFirst(dataTable.getFirst() - dataTable.getRows());
System.out.println("Prevoius"+dataTable.getFirst());
}
public void pageNext() {
dataTable.setFirst(dataTable.getFirst() + dataTable.getRows());
System.out.println("Next"+dataTable.getFirst());
}
public void pageLast() {
int count = dataTable.getRowCount();
int rows = dataTable.getRows();
dataTable.setFirst(count - ((count % rows != 0) ? count % rows : rows));
}
public HtmlDataTable getdataTable() {
return dataTable;
}
public void setdataTable(HtmlDataTable dataTable) {
this.dataTable = dataTable;
}
public void showRow(){
System.out.println(dataTable.getRows());
}
public String deleteAction(Customer customer) throws SQLException{
//list.remove(customer);
//System.out.println(customer.cust_id);
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/openid","root","root");
smt = con.createStatement();
String query="delete from jsftable where cust_id="+customer.cust_id+"";
//ResultSet rs= smt.executeQuery(query);
smt.executeUpdate(query);
}
catch(Exception e){
e.printStackTrace();
}
return null;
}
public String editAction(Customer customer) {
//list.remove(customer);
System.out.println(customer.cust_id);
customer.setEditable(true);
return null;
}
}
Customer.java
public class Customer {
int cust_id;
String cust_name;
boolean has_attachment;
boolean editable;
String edit_value;
public String getEdit_value() {
System.out.println("in getter");
return edit_value;
}
public void setEdit_value(String editvalue) {
this.edit_value = editvalue;
}
public boolean isHas_attachment() {
System.out.println("in getter of has_attach");
return has_attachment;
}
public void setHas_attachment(boolean hasAttachment) {
has_attachment = hasAttachment;
}
public int getCust_id() {
System.out.println("in getter of cust_id");
return cust_id;
}
public void setCust_id(int custId) {
cust_id = custId;
}
public String getCust_name() {
return cust_name;
}
public void setCust_name(String custName) {
cust_name = custName;
}
public boolean isEditable() {
//System.out.println("in isEditable"+editable);
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
//System.out.println("in set editable"+editable);
}
}
To be honest, I wonder how your code works at all. It has several major flaws.
You should start with
giving your managed bean a scope, the #ViewScoped seems the most appropriate (see here)
removing the database access from the getter method. Put it inside an #PostConstruct annotated method in your bean. Getter methods can be called several times during JSF lifecycle. The #PostConstruct method only after bean construction.
closing sql statement and connection when you are done (stmt.close() and con.close())
following bean field and method naming conventions: A private field xxx has a getter getXxx and a setter setXxx (the capitalization is important)
removing datatable binding. It is not necessary here.
I recommend to go through this simple CRUD example by BalusC and adapting it for your functional requirements.
Add id tag for datatable:
<h:dataTable value="#{customerdata.customerList}" var="c" id="customerDT"
styleClass="order-table" binding="#{customerdata.dataTable}"
headerClass="order-table-header" border="1" width="100%"
rowClasses="order-table-odd-row,order-table-even-row" rows="3">
Add in your edit CommandButton update tag:
But why you don't use the inplace component using primefaces? http://www.primefaces.org/showcase-labs/ui/inplace.jsf (need a save button)