-1

I want to update the second SelectOneMenu when I select any item of the first SelectOnMenu.So there are my two SelectOneMenu:

     <p:outputLabel value="Table :" />
                   <p:selectOneMenu  id="tbName">
                                            <f:selectItem itemLabel="Select Table" itemValue="" />
                                            <f:selectItems value="#{infoTable.nameTa}" />

                                        </p:selectOneMenu> 
<p:outputLabel value="Foreignenkey :" />

               <p:selectOneMenu  id="cat">
                                        <f:selectItem itemLabel="Select Column" itemValue="" />
                                        <f:selectItems value="#{infoTable.fkName}" />

                                    </p:selectOneMenu> 

and this is his Java code :

public List<SelectItem> getNameTa() {
        List<SelectItem> subcat = new ArrayList<SelectItem>();
        try {
            ConnectionBase con = new ConnectionBase();
            TableInfo tt = new TableInfo();

            List<String> rs = tt.getTable(con, "%");
            Iterator i = rs.iterator();
            while (i.hasNext()) {
                subcat.add(new SelectItem(i.next()));
            }

        } catch (Exception e) {
            e.getStackTrace();
        }

        return subcat;

    }
public List<SelectItem> getFkName() {
        List<SelectItem> subcat = new ArrayList<SelectItem>();
        // if (catname != null && !catname.equals("")) {
        try {
            // Connection con = Database.getConnection();
            ConnectionBase con = new ConnectionBase();
            TableInfo tt = new TableInfo();

            List<String> rs = tt.getNameCtable(con, "%");


            Iterator i = rs.iterator();
            while (i.hasNext()) {
                subcat.add(new SelectItem(i.next()));
            }

        } catch (Exception ex) {
        }
        // }
        return subcat;
    }

As i know i should make a eventLestner but i don't know how and when i get the name of table from the first selectonemenu how can send the name to the second methode "getFkName" ?

Hamdi Dousdou
  • 57
  • 1
  • 12
  • Have you seen our [selectonemenu wiki](http://stackoverflow.com/tags/selectonemenu/info)? There is a chapter explaining exactly this. – perissf Jul 20 '14 at 10:15

1 Answers1

0

Store selected value in bean instance variable and use ajax event listner to update second p:selectOneMenu when this value changed.

<p:selectOneMenu id="tbName" value="#{infoTable.selectedTableName}">
  <p:ajax event="onchange" update="cat">
  <f:selectItem itemLabel="Select Table" itemValue="" />
  <f:selectItems value="#{infoTable.nameTa}" />
</p:selectOneMenu>

In your getFkName() you can use selectedTableName variable to obtain current selected value. And don`t forget to provide get/set methods for selectedTableName.

alexSunder
  • 417
  • 3
  • 11