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

Implementing tokenizer and adding tokens to the linked list

Finding missing numbers from billion sequential number list file

Find K Complementary numbers from array Java implementation

Find longest palindrom from sequence of characters

Check if two strings are anagrams or not

Find the first occurence of number in the sorted array

Array reversal in Recurrsion

testing k complementary pairs algorithm with junit

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

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

Leave a Reply

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

*
*