Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSF-Questions dropdown list in jsf

Have Programming Question? Ask it here!
 
 
 


AVISEK PANDA
dropdown list in jsf
3 Answer(s)      a year and a month ago
Posted in : Java Server Faces Questions


I want to add a list box to display the country name from the lists on all countries.When I select for e.g India then in the second list box it will display the states related to India only and the flow continues for state and areas related to state.Please provide the code with and without using database.


Advertisement
View Answers

June 11, 2013 at 12:35 PM


hi friend,

Here is a sample code for value changing of list box in JSF, hope this will be helpful for you.

FruitBean.java

package devmanuals;

import java.util.LinkedHashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ValueChangeEvent;

@ManagedBean(name="fruit")
@RequestScoped
public class FruitBean {

    public int fruitPrice;
    private static Map<String,Integer> fruitName;
    static{
        fruitName = new LinkedHashMap<String,Integer>();
        fruitName.put("Select-Fruit", 0);
        fruitName.put("Apple", 110);
        fruitName.put("Mango", 80);
        fruitName.put("Guava", 40);
        fruitName.put("Grapes", 90);
        fruitName.put("PineApple", 50);
    }

    public Map<String,Integer> getFruitName() {
        return fruitName;
    }
    public int getFruitPrice() {
        return fruitPrice;
    }

    public void setFruitPrice(int fruitPrice) {
        this.fruitPrice = fruitPrice;
    }
}

Continue...



June 11, 2013 at 12:36 PM


FruitPriceListener.java

package devmanuals;

import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;

public class FruitPriceListener implements ValueChangeListener {

    @Override
    public void processValueChange(ValueChangeEvent e)
            throws AbortProcessingException {
        FruitBean fruit = (FruitBean) FacesContext.getCurrentInstance().
            getExternalContext().getRequestMap().get("fruit");

        fruit.setFruitPrice((Integer) e.getNewValue());
        System.out.println("Value of component has been changed");
        System.out.print("Component which value is being changed :");
        System.out.println(e.getComponent());
        System.out.println("JSF PhaseId : "+e.getPhaseId());        
    }
}

Continue...



June 11, 2013 at 12:37 PM


fruitPrice.xhtml

<?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" >
<head>
<title>JSF 2 f valueChangeListener example</title>
</head>
<body>
<f:view>
  <h:form>
   <h:panelGrid columns="2">

    <h:outputText value="Price of Fruit :"/> 
    <h:inputText value="#{fruit.fruitPrice}" />

    <h:outputText value="Select Fruit :"/> 
    <h:selectOneListbox value="#{fruit.fruitPrice}" onchange="submit()">
    <f:valueChangeListener type="devmanuals.FruitPriceListener" />
    <f:selectItems value="#{fruit.fruitName}" />
    </h:selectOneListbox>
    </h:panelGrid>
  </h:form>
</f:view>
</body>
</html>

Thanks.



Related Tutorials/Questions & Answers:
dropdown list in jsf
dropdown list in jsf  I want to add a list box to display the country name from the lists on all countries.When I select for e.g India then in the second list box it will display the states related to India only and the flow
DropDown list
DropDown list  how to get mysql database values into dropdown usign java servlet and ajax?   Here is a jsp code that displays the database values into dropdown list. 1)country.jsp: <%@page import="java.sql.*"%>
Advertisements
dropdown list in jsp
dropdown list in jsp  hai, i have static dropdown list.. i want to get the selected value in string variable without jsp regards asha
struts dropdown list
struts dropdown list   In strtus how to set the dropdown list values from database ? I have a ArrayList object and set this object in dropdown jsp... = MasterDataDAO.getValues(list); request.setAttribute("masterlist", masterList
Retrieval of Dropdown list
Retrieval of Dropdown list  Hi frnds... Am having problem... ... for eg, let A1,A2,A3,A4 be the values in dropdown.. if i click A1, the corresponding value of A1, list of name corresponding to A1 wil be displayed in another
how to set value of dropdown list
how to set value of dropdown list  Hello Sir, I'd solved the earlier problems somehow but now this time another problem arised when I want to pass the value from a link to a dropdown list. I want to set the dropdown list selected
how to set value of dropdown list
how to set value of dropdown list  Hello Sir, I'd solved the earlier problems somehow but now this time another problem arised when I want to pass the value from a link to a dropdown list. I want to set the dropdown list selected
dropdown list and text fields in php
dropdown list and text fields in php  How could I use php to populate text fields by selecting a name of a business from dropdown list? Those text fields that will be populated by information in regards its company name, suite
getting values from dropdown list
getting values from dropdown list  I am having a dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from the database) My question is when i select a particular value it should be pass
jsp- database dependent dropdown list
jsp- database dependent dropdown list   i want 2 dropdown list 1- CLASS 2-SECTION both are should come from database. and if i select a class suppose class a the corresponding section dropdown list should retrieve the section
dropdown box in jsf - Java Server Faces Questions
dropdown box in jsf  Hi friends, AssigningJob... in dropdown... part" List countryList= new ArrayList(); List cityList= new ArrayList
dropdown box in jsf - Java Server Faces Questions
dropdown box in jsf  Hi friends, 1.how to create dropdown boxes in jsf. 2.if the dropdown box contains id values like 1,2,3,4..........,if i click... for above queries. And one more how to create morethan one dropdown box in one jsf
3 dropdown list from the database using JSP
3 dropdown list from the database using JSP  Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
how to load value in dropdown list after selecting value from first dropdown list using javascript
how to load value in dropdown list after selecting value from first dropdown list using javascript  how to load value in dropdown list after selecting value from first dropdown list using javascript
creating list in dropdown using struts - Struts
creating list in dropdown using struts   creating list in dropdown using struts : In action class list.add(new LabelValueBean("ID","Name")); In Jsp * Select Item Select In Form : getter
Dropdown Checkbox list
Dropdown Checkbox list This tutorial explains how to create jquery Dropdown... jquery Dropdown Checkbox list. The application directory structure should look like... dropdown , then displays dropdown list as checkbox  You can
How to add dropdown list in a row of a sort table applet?
How to add dropdown list in a row of a sort table applet?  How to add dropdown list in a row of a sort table applet
getting and storing dropdown list in database in jsp
getting and storing dropdown list in database in jsp  i have a drop down list to select book from database. i'm able to retrieve dropdown list from database. but unable to store the selected value in database table. please help
How to add a DropDown List in Flex DataGrid
How to add a DropDown List in Flex DataGrid  hi I am trying to add... the drop down list, the Item that I have selected is not reflected or did... select from one of the choices in the list. That's my reason for trying to add
How to add a DropDown List in Flex DataGrid
How to add a DropDown List in Flex DataGrid  hi I am trying to add... the drop down list, the Item that I have selected is not reflected or did... select from one of the choices in the list. That's my reason for trying to add
help to select a value from the dropdown list
help to select a value from the dropdown list  I have a html file called autoSuggestTextbox.html which is shown below. <!DOCTYPE html PUBLIC... from the drop down list created in a div and put it in the textbox kim
how to perform the client side validations to the dropdown list using javascript?
how to perform the client side validations to the dropdown list using javascript?  Hi Good Morning! This is Prasad, I want to perform the client side validation to the dropdown list using javascript. So give me sample.I am
Retriving value from dropdown list nad disply it in other page
Retriving value from dropdown list nad disply it in other page  Hello, I have a dropdownbox on my webpage and a map which contains a marker... of the selected value from the dropdown list and dispaly it to on the next page. i
how to use dropdown list in JSP and display value in same page
how to use dropdown list in JSP and display value in same page  I have a Dropdown list with some values say "A", "B" and "C" When the user selects one option the value must get displayed below it in the same page
JSP Get Data Into Dropdown list From Database
JSP Get Data Into Dropdown list From Database In this section we will discuss about how to fetch data dynamically into the dropdown list in JSP... it into the dropdown list dynamically. In this example we will explain the dynamically
how to add data dynamically from database into a dropdown list in a jsp
how to add data dynamically from database into a dropdown list in a jsp ... list.In that first list is for department and the 2nd list for the names of the persons who work in that department.The values into the drop down list should
How to display content in same page while selecting fron dropdown list
How to display content in same page while selecting fron dropdown list  Hai frnds, I am beginner of java.i have doubt in codings.I am using dropdownlist in jsp page.If i select any value in that list(for eg-rollno
dropdown
dropdown  how to hide textbox field when i deselect from select dropdown
How to display content in same page while selecting fron dropdown list
How to display content in same page while selecting fron dropdown list  Thanks for your suggesstion.but Please provide me coding by using only one dropdownlist in javascript or jquery.Thanks in advance
How to access Contacts from gmail using LDAP in JSP dropdown list
How to access Contacts from gmail using LDAP in JSP dropdown list  HI, I am creating a JSP page in which i have to make a dropdown box, and access gmail contacts in that drop downlist using LDAP. Can any one plz help me out
How can we save a data list in jsf?
How can we save a data list in jsf?  I have a code in jsf that fires... to fire query only if list is not-empty but the list gets empty each time... hampered.. some one suggested me with page scope list.. any idea
dropdown
dropdown  I have a dropdown having 2 options-"Open"& "closed".When i select "open" option the related rows of data are retrieved from database and same with the other option.My database is Mysql and coding in PHP
How to automatically change the value of the textbox based on the dropdown list?
How to automatically change the value of the textbox based on the dropdown list?  I want to know how to automatically change the value of price and the quantity text boxes. Here is my code: <%@ page import="java.sql.
how can i send a mail to a particular user from a many user dropdown list in jsp
how can i send a mail to a particular user from a many user dropdown list in jsp  how can i a sent a user question to a particular person from a drop down list in jsp
I tried to create a dropdown list using struts2.it is not working.can you find the errors in this code?
I tried to create a dropdown list using struts2.it is not working.can you find...;/*form created*/ <p:select name="designation" label="Enter Designation " list="design" /> /*dropdown list included*/ <p:submit name="submit"/>
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP  as i said i want to create 3 drop dropdown list each depend on the other and get the options from
dropdown cacheing
dropdown cacheing   I need code to create cache for load drop down list from db in struts1 example
how to make drop down list in JSF & fetch data Item from database
how to make drop down list in JSF & fetch data Item from database  how to make drop down list in JSF & fetch data Item from database
DropDown Menu
DropDown Menu  Hello, i have a program that can view,add,delete... me draw to your my mind my program.. in my homepage which i have a dropdown menu that has the list of Page 1- Page 5. if i select page 1 it will display only
creating dropdown lists in jsp
creating dropdown lists in jsp  i want to create two dropdown list which are dependent that is the first box choice have to evaluate the second boxs options
JSF Books
JSF Books          Introduction of JSF Books When we heard about JavaServer? Faces (JSF) at the 2002 Java One conference, we
Dependant Dropdown Lists
Dependant Dropdown Lists  Hello, I'm trying to create 2 dropdown lists. When the visitor chooses one option from the 1st list it will automatically update the 2nd dropdown. Ive already found some code which i edited but still
JSF
JSF  What is JSF
dropdown box
dropdown box  i need to have country,state and city in drop down box using ajax and use db2 database   Have a look at the following link: JSP dependent dropdown
Ajax Dropdown
Ajax Dropdown  hi I have One Dropdown that contains 2 options assume A and B,if i select A option then samepage one more Dropdown is their it should display values in german language using DWRUtil Parameter values in ajax. Only
JSF
JSF  In what way JSF makes the difference between Applets?? After reading this article I understood instead of using Request and response, we... and embed that into applets also rite.. Do u mean JSF also does the same internally
List
List  i do have one list object, i want to compare this list from database table and if match found i want to update the list
List
List  getting values from a form and make a list of them and store them into database
dropdown in struts - Struts
dropdown in struts  how to populate a drop down from database entries... write the query (in which file)to get the list from database and how and where can i set the list to context to get it from there in a collection object
Advertisements
 

 

 

DMCA.com