How to get label of selected item in managed bean

maas maas

I need your help in getting the values of a list into two variables. My list is having descriptions and codes. However, I need to place the descriptions in a variable and the codes in a different variable, so how can I achieve this.

My Code is

private String[] selectedCertificates;
private List<SelectItem> Certificates;

    public List<SelectItem> getCertificatesList(){
    Certificates = new ArrayList<SelectItem>();
    Certificates.add(new SelectItem("Certificate A","A"));
    Certificates.add(new SelectItem("Certificate B","B"));
    return bankCertificates;

}

public void setCertificates(List<SelectItem> Certificates) {
    this.Certificates = Certificates;
}
// Setters and Getters

Select Item Code:

                         <p:selectManyCheckbox id="Certificates" value="#{user.selectedCertificates}"
                                              layout="pageDirection" disabled="#{user.secondToggle}">
                            <f:selectItems value="#{user.Certificates}" var="bankCertificates"
                                           itemLabel="#{user.CertificatesString}" itemValue="#{user.CertificatesCode}"/>
                        </p:selectManyCheckbox>

where can I define that the description should be the first value and the code should be the second value in the list and I can use them in the page.

Thanks

Tirath

Try

class SelectItem {
    private String code;
    private String description;

    SelectItem (String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode () {
        return code;
    }
    public String getDescription () {
        return description;
    }
}

Here is your main class

class MainClass {
    public static void main (String...arg) {
        //construct your list here using SelectItem class objects
        List<SelectItem> certificates =  = new ArrayList<SelectItem>();
        certificates.add(new SelectItem("Certificate A","A"));
        certificates.add(new SelectItem("Certificate B","B"));

        //now first read the SelectItem objects you have added to the list
        //or you can also iterate through the list, modify accordingly
        SelectItem si1 = certificates.get(0);
        //to read the code and description use the getters defined in SelectItem
        si1.getCode(); si1.getDescription();
    }
}

You can also choose to create a method to which you can pass the index which you wish to read from the list. Hope, this helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PrimeNg/Angular: How to display the label of a selected item?

From Dev

How to get the Keyboard curser focus to edit the label text, when we double click on CheckboxTreeViewer selected item

From Dev

How to Get the Selected Item of a ListPicker

From Dev

How to get the selected item in a QTreeView

From Dev

how to get specific item that selected?

From Dev

How to get the selected dropdown item

From Dev

How to get the selected item in a QTreeView

From Dev

how to get specific item that selected?

From Dev

jsf - How can i get inputText value in managed bean?

From Dev

JSF, How to get Id of <h:input> from Managed Bean

From Dev

jsf - How can i get inputText value in managed bean?

From Dev

How to get the title of the selected UIActionSheet button into a label?

From Dev

AngularJS how to get label and value from selected

From Java

How to show the numeric position from a selected item in a listbox in a label

From Dev

How to bind a JavaFX Label to the selected item from a ListView

From Dev

How share some f:event of f:metadata between selected XHTML with managed bean interface as parameter

From Dev

selected listview item displays in label

From Dev

How to get the selected item from a DropDownList?

From Dev

ListPicker, how to get the text from the selected item?

From Dev

How to get id of selected table item in php

From Dev

How to get the ID of selected item in a spinner?

From Dev

How to get listbox selected item value

From Dev

how to get value of selected item in autocomplete

From Dev

Wpf CheckedListbox - how to get selected item

From Dev

how to get id of selected item in autocompletetextview in android

From Dev

How to get selected item in table using pyqt?

From Dev

How to get alertdialg selected item in textview?

From Dev

How to get selected menu item in wxPython?

From Dev

How to get selected item from RecyclerView list?

Related Related

  1. 1

    PrimeNg/Angular: How to display the label of a selected item?

  2. 2

    How to get the Keyboard curser focus to edit the label text, when we double click on CheckboxTreeViewer selected item

  3. 3

    How to Get the Selected Item of a ListPicker

  4. 4

    How to get the selected item in a QTreeView

  5. 5

    how to get specific item that selected?

  6. 6

    How to get the selected dropdown item

  7. 7

    How to get the selected item in a QTreeView

  8. 8

    how to get specific item that selected?

  9. 9

    jsf - How can i get inputText value in managed bean?

  10. 10

    JSF, How to get Id of <h:input> from Managed Bean

  11. 11

    jsf - How can i get inputText value in managed bean?

  12. 12

    How to get the title of the selected UIActionSheet button into a label?

  13. 13

    AngularJS how to get label and value from selected

  14. 14

    How to show the numeric position from a selected item in a listbox in a label

  15. 15

    How to bind a JavaFX Label to the selected item from a ListView

  16. 16

    How share some f:event of f:metadata between selected XHTML with managed bean interface as parameter

  17. 17

    selected listview item displays in label

  18. 18

    How to get the selected item from a DropDownList?

  19. 19

    ListPicker, how to get the text from the selected item?

  20. 20

    How to get id of selected table item in php

  21. 21

    How to get the ID of selected item in a spinner?

  22. 22

    How to get listbox selected item value

  23. 23

    how to get value of selected item in autocomplete

  24. 24

    Wpf CheckedListbox - how to get selected item

  25. 25

    how to get id of selected item in autocompletetextview in android

  26. 26

    How to get selected item in table using pyqt?

  27. 27

    How to get alertdialg selected item in textview?

  28. 28

    How to get selected menu item in wxPython?

  29. 29

    How to get selected item from RecyclerView list?

HotTag

Archive