Originally posted by Bhaskar GR:
Hi,Can you expain clearly whats is the problem
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<f:view>
<head>
<title>Add Employee</title>
</head>
<body bgcolor="LIGHTBLUE" >
<h:form>
<table border="0" cellpadding="0" cellspacing="1" width="100%" height="15">
<tr ><td align="center">
<h:panelGrid columns="1">
<h:panelGroup style="display:block; text-align:center">
<h:outputText value=" Add Employee "></h:outputText>
</h:panelGroup>
</h:panelGrid>
</td>
</tr></table>
<table border="0" cellpadding="0" cellspacing="1" width="100%" height="100">
<tr></tr>
</table>
<table border="0" cellpadding="0" cellspacing="1" width="100%" height="150">
<tr>
<td></td><td align="right">
<h:outputText value="Employee Id"></h:outputText>
</td><td align="left">
<h:inputText id="empId" value="#{application.id}" required="true" >
<f:validator validatorId = "validateField" /></h:inputText>
</td><td>
<h:message style= "color: red" for="empId" />
</td>
</tr><tr>
<td></td><td align="right">
<h:outputText value="Employee Name"></h:outputText>
</td><td align="left">
<h:inputText id="empName" value="#{application.name}" required="true" >
<f:validator validatorId = "validateField" /></h:inputText>
</td><td>
<h:message style= "color: red" for="empName" />
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="1" width="100%" height="15">
<tr>
<td align="right">
<h:commandButton value="Submit" action="#{application.insertIntoTable}" id="addButton" ></h:commandButton>
</td><td align="left">
<h:commandButton value="Cancel" action="cancel" immediate="true"></h:commandButton>
</td>
</tr>
</table>
</h:form>
</body>
</f:view>
</html>
Bean
package com.test.jsf;
import java.util.ArrayList;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;
import javax.faces.model.SelectItem;
import javax.faces.render.ResponseStateManager;
import org.dbcheck.DatabaseCheck;
public class ApplicationBean implements ValueChangeListener {
private int id;
private ArrayList<SelectItem> nameComboArrayList;
private String name =" ";
private String currentItem;
private HtmlInputText idHtmlInputText;
private HtmlInputText nameHtmlInputText;
private HtmlInputText idForAddHtmlInputText;
public ApplicationBean() {
nameComboArrayList = new ArrayList<SelectItem>();
}
public void setId(int idValue) {
System.out.println("Entered the Setter Method ------------------------");
id = idValue;
}
public void setName(String nameValue) {
name = nameValue;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void getIdMax() {
DatabaseCheck databaseCheck3 = new DatabaseCheck();
String query = "SELECT max(empid) FROM Employee";
ApplicationBean applicationBean = databaseCheck3.getMaxId(query);
}
public void insertIntoTable() {
System.out.println(" Id :" + id);
System.out.println(" Name :" + name);
DatabaseCheck databaseCheck = new DatabaseCheck();
String query = "INSERT INTO Employee Values(" + id + ",'" + name + "')";
databaseCheck.getExecuteUpdate(query);
}
public void updateTableValues() {
System.out.println(" Update ");
System.out.println(" Id :" + id);
System.out.println(" Name :" + name);
DatabaseCheck databaseCheck1 = new DatabaseCheck();
String query = "UPDATE Employee SET emp_Name ='" + name
+ "' WHERE empid =" + id + "";
databaseCheck1.getExecuteUpdate(query);
}
public void outputValue() {
System.out.println("Item State ");
}
public void deleteDelete() {
System.out.println(" Id :" + id);
System.out.println(" Name :" + name);
DatabaseCheck databaseCheck2 = new DatabaseCheck();
String query = "DELETE FROM Employee WHERE empid=" + id + "";
databaseCheck2.getExecuteUpdate(query);
}
public void selectTables() {
System.out.println(" Id :" + id);
System.out.println(" Name :" + name);
System.out.println("In Select >>> ");
DatabaseCheck databaseCheck3 = new DatabaseCheck();
String query = "SELECT empid,emp_Name FROM Employee WHERE empid= "
+ id + " ";
ApplicationBean applicationBean = databaseCheck3.getExecuteQuery(query);
this.id = (applicationBean.getId());
this.name = (applicationBean.getName());
System.out.println(getId() + "#####" + getName());
this.idHtmlInputText.setValue(applicationBean.getId());
this.nameHtmlInputText.setValue(applicationBean.getName());
System.out.println(getIdHtmlInputText().getValue() + "#####@@@@@@@@@" + getNameHtmlInputText().getValue());
}
public void searchData() {
System.out.println(" Id :" + id);
System.out.println(" Name :" + name);
System.out.println("In Select >>> ");
DatabaseCheck databaseCheck3 = new DatabaseCheck();
String query = "SELECT empid,emp_Name FROM Employee WHERE empid= "
+ id + " ";
databaseCheck3.getExecuteQuery(query);
}
public void selectAllTables() {
DatabaseCheck databaseCheck4 = new DatabaseCheck();
String query = "SELECT empid,emp_Name FROM Employee ";
databaseCheck4.getExecuteQuery(query);
}
public ArrayList<SelectItem> getPopulatedList() {
DatabaseCheck databaseCheck5 = new DatabaseCheck();
String query = "SELECT empid,emp_Name FROM Employee";
System.out.println("getDataList ___________________________" + id
+ " " + name);
return databaseCheck5.getDataList(query);
}
public String getCurrentItem() {
return currentItem;
}
public void setCurrentItem(String currentItem) {
this.currentItem = currentItem;
}
public ArrayList<SelectItem> getNameComboArrayList() {
nameComboArrayList = getPopulatedList();
System.out.println(id + " " + name);
return nameComboArrayList;
}
public void setNameComboArrayList(ArrayList<SelectItem> nameComboArrayList) {
this.nameComboArrayList = nameComboArrayList;
}
public void processValueChange(ValueChangeEvent ae)
throws AbortProcessingException {
if (ae.getComponent().getId().equals("selectName")) {
ae.getComponent().saveState(FacesContext.getCurrentInstance());
System.out.println(ae.getComponent().getId() + " @@@@@@@@@"
+ ae.getNewValue());
System.out.println("@@@@@@");
setId(Integer.parseInt(ae.getNewValue().toString()));
selectTables();
System.out.println("=================== " + id);
FacesContext.getCurrentInstance().renderResponse();
//FacesContext.getCurrentInstance().getApplication()
//.getNavigationHandler().handleNavigation(
//FacesContext.getCurrentInstance(), null, "test");
//ResponseStateManager.
}
}
public HtmlInputText getIdHtmlInputText() {
return idHtmlInputText;
}
public void setIdHtmlInputText(HtmlInputText id1) {
this.idHtmlInputText = id1;
}
public HtmlInputText getNameHtmlInputText() {
if(nameHtmlInputText != null) {
System.out.println("####"+nameHtmlInputText.getValue()+"@@@@");
}
else {
System.out.println("NULLLLL");
}
return nameHtmlInputText;
}
public void setNameHtmlInputText(HtmlInputText name1) {
this.nameHtmlInputText = name1;
}
}
problem is after valueChangeListener i tried to load data from the bean
private String name =""; the value in the bean is not loaded in inputtext
but
private String name =" ";then it work
how can i solve it?
please help