the multiple choice list problem

UI Components for JSF
Post Reply
primer
Posts: 44
Joined: 23 May 2011, 15:25

27 Aug 2011, 03:19

Hello everybody,

I want to have a field, named Country, into my form , and the user must select between 3 countries (Spain, Italy, France) ! :geek:

I want to do that with the multiple choice list (like the font size field into the editor). I don't know how to do it with primefaces cause I am new ! :roll:

Thanks for helping me ! ;)

primer
Posts: 44
Joined: 23 May 2011, 15:25

27 Aug 2011, 16:43

T tried to follow this tuto :

http://www.primefaces.org/showcase-labs ... Column.jsf

I make something like this (in my classBean):

Code: Select all

 static {
         countries = new String[3];
        countries [0] = "France";
        countries [1] = "Italy";
        countries [2] = "Spain";
    }
     
    private final static String[] countries;
and in mypage.xhtml:

Code: Select all

<h:outputLabel  value="Country:" />
            <h:selectOneMenu >
                <f:selectItems value="#{userController.countries}" var="country" itemLabel="#{user}" itemValue="#{user}" />
            </h:selectOneMenu>
When I execute, I got this error:

Code: Select all

value="#{userController.countries}": The class 'jpa.controllers.UserController' does not have the property 'countries'.
:oops:

What should I do :?

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

27 Aug 2011, 17:16

Hi,

<h:selectOneMenu> can not be empty without attributes. You should define value="#{....}" for (pre)selected value.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

primer
Posts: 44
Joined: 23 May 2011, 15:25

27 Aug 2011, 17:34

OK, I edit it like this:

Code: Select all

<h:selectOneMenu value="#{userController.selectedUser.country}" rendered="#{userController.editMode}">
       <f:selectItems value="#{userController.countries}" var="country" itemLabel="#{user}" itemValue="#{user}" />
</h:selectOneMenu>
The error message had disappeared, but the output of the country field is empty ... I mean I got nothing in front of "Country:" in my page :(

fcastlerock
Posts: 5
Joined: 06 Aug 2011, 04:11

28 Aug 2011, 17:57

hmmm....

value="#{userController.countries} , here "countries" refers to an ArrayList.

Then,You should have a method called in any moment which load your ArrayList named "countries"!

Your method "loadArrayListCountries" can be called in the Constrctor of your backBean .


http://www.primefaces.org/showcase/ui/d ... eBasic.jsf

public class UserController{

List countries;

public userController() { //This is the Constrctor of your backBean .

countries= new ArrayList<Countries>();
loadArrayListCountries();
}

private void loadArrayListCountries() {

// get Countries from Database!

}

}


CASTLEROCK

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 30 guests