Showing error message on selectOneMenu while selecting default

Showing error message on selectOneMenu while selecting default

So, we have a menu, brimmed with our objects from list/database. The intention would be creating a default “Select” kind of the first row and to brag on the user when s/he selects the default.

The trick is simple, create the first list with null object and label it as Select. Lets show it with simple example.
We want to have a list of programming languages on our select menu. And, the first would be a default object.

    //Actual domain class
    class Language{
        private String name;
        private String type;
        private boolan isCompiled;

       getters/setters goes here
   //Bean class
   class someBean{
        private List languages;
        public String getLanguages(){
            //Let languages would be filled by some service or factory
            this.languages = someLanguageFactory.getAllLanguages(); 
           //Assign the first element as null
           this.languages.add(0, null);
   //JSF page
   <h:selectOneMenu id="selectLanguage" value="someBean.languages" 
     requred="true" ....

This should do the task, make the list required, and populate the first list null. So, during validation if the selection is null it would be rejected as we have told it to watch an eye on blank fields.

See how you would solve these known algorithm problems

Java solution for checking anagram strings – tell if phrases are anagrams

Check if two strings are anagrams or not

Finding missing numbers from billion sequential number list file

Find K Complementary numbers from array Java implementation

Find longest palindrom from sequence of characters

testing k complementary pairs algorithm with junit

Find the pairs that makes K Complementary in the given array java solution

Kadane’s algorithm in C – Dynamic Programming

binary tree problems with solution

Check if there are three numbers a, b, c giving a total T from array A

Leave a Reply

Your email address will not be published. Required fields are marked *