| Author |
Problem with loading the data after Value Change Listener on selectonemenu
|
Sherin Koshy Varghese
Greenhorn
Joined: Mar 28, 2008
Posts: 6
|
|
Hi I am new to jsf. i am facing problem on selectonmenu I used selectonemenu ,on selecting one item i want to load some data to inputText box .i used like this <h:selectOneMenu id="selectName" onchange="submit()" valueChangeListener="#{application.processValueChange}" immediate="true" value="#{application.name}"> <f:selectItem itemValue="0" itemLabel="Select"/> <f:selectItems value="#{application.populatedList}"/> </h:selectOneMenu > <h:inputText id="empId" value="#{application.id}" required="true" ></h:inputText> but it not loading . Please help me Koshy
|
 |
Zack Marrapese
Greenhorn
Joined: Jul 02, 2008
Posts: 27
|
|
|
What does your value change listener look like?
|
 |
Bhaskar GR
Greenhorn
Joined: Jun 13, 2008
Posts: 28
|
|
|
Hi,Can you expain clearly whats is the problem
|
 |
Sherin Koshy Varghese
Greenhorn
Joined: Mar 28, 2008
Posts: 6
|
|
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 utputText value=" Add Employee "></h utputText> </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 utputText value="Employee Id"></h utputText> </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 utputText value="Employee Name"></h utputText> </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
|
 |
 |
|
|
subject: Problem with loading the data after Value Change Listener on selectonemenu
|
|
|