Search code examples
javadynamicradio-buttonzk

java code to get Radio Button label from database column entries in zk framework


I need to generate the radio button in the zk framework according to database column entries and labelling those radio buttons based on the particular column values. Now I am hardcoding the radio button label values. However these values should be taken from the database column entries. In an arraylist "name" I have taken all the values in column. How can assign these to the radio button labels? Please help me


Solution

  • It should be quite simple, if you use the MVC pattern with a Java class as a controller have a look at the following example:

    ArrayList<String> columnEntries = new ArrayList<String>();
    
    //populate the array list here, and then...
    
    Radiogroup radiogroup = new Radiogroup();
    
    for(String entry: columnEntries){
     radiogroup.appendItem(entry, entry);
    }
    

    The radiogroup.appendItem(entry, entry); adds automatically a radio button to the specified radiogroup. If you want that the radio button should contain a different value than its label, change the second parameter from entry to your desired value.