You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Volker Weber <we...@googlemail.com> on 2006/07/10 13:30:58 UTC

Re: selectonemenuitem problems Value is not a valid option

Hi,

the value of f:selectItems must be a array of SelectItem.

you shoud have:

public SelectItem[] getHosts() {
...
}

regards,
  Volker

2006/7/10, sarma <ss...@mahindrabt.com>:
>
> Hi,
>    I am working with two selectOneListBox  in jsf
>    If I selected one item in first list box the corresponding values(from
> the database (setting that values to     preparedstatement))
>     must displayed in second list box
>    For that I used value change listener .
>    When I am submitting this form   I  am getting an error
>
>          cpuids": Value is not a valid option.
>
>    This is my code.
>     This is jsp code.
>
>      <h:outputText value="SelectHOST   "/></th>
>                <h:panelGroup>
>                              <h:selectOneMenu id="hostids"
> value="#{HRselforeachcpuanduser.host}"
>                                   valueChangeListener="#{HRselforeachcpuanduser.hostSelection}"
> onchange="submit();"immediate="true" required="true">
>                              <f:selectItem itemValue="" itemLabel=""/>
>                                          <f:selectItems value="#{HRselforeachcpuanduser.hosts}"/>
>                </h:selectOneMenu>
>                   <h:message for="hostids" style="color:red"/>
>              </h:panelGroup> <br>
>                  <h:outputText value="SelectCPU" />
>              <h:panelGroup>
>                    <h:selectOneMenu id="cpuids" value="#{HRselforeachcpuanduser.cpuid}" >
>                        <f:selectItems value="#{HRselforeachcpuanduser.cpuids}"/>
>                    </h:selectOneMenu>
>                    <h:message for="cpuids" style="color:red"/>
>         </h:panelGroup>
>
>
> // this is backing bean code
>
> Corresponding java code
> // this is for value change listener
>
> public void hostSelection(ValueChangeEvent e) {
>       FacesContext context = FacesContext.getCurrentInstance();
>       hostid=(String) e.getNewValue();
>           getCpuids();
>       context.renderResponse();
>  }
> //this is for  host select
>
> public Map getHosts(){
>     try{
>       openConnection();
>           selhostnames=new HashMap();
>       String str="select distinct hostid from  system_cpu";
>       st=con.createStatement();
>           rs=st.executeQuery(str);
>
>           while(rs.next()){
>                     hostname=rs.getString("hostid");
>                         System.out.println(hostname);
>             selhostnames.put(hostname,hostname);
>       }
>           return selhostnames;
> }
>
> public String getHost(){
>     return hostselected;
>   }
>   public void setHost(String hostselected){
>     this.hostselected = hostselected;
>   }
>
> //this is for  cpu  selection
> public Map getCpuids(){
>    try{
>
>      if(hostid==null){
>          System.out.println("if it is null");  // imp  note
>              return selcpunames;
>      }
>           openConnection();
>           String str="select distinct cpuid from system_cpu where hostid=?";
>       System.out.println("setting cpuids from host");
>           ps=con.prepareStatement(str);
>           ps.setString(1,hostid);
>           ps.execute();
>           rs=ps.getResultSet();
>       while(rs.next()){
>                     cpuname=rs.getString("cpuid");
>                         System.out.println(cpuname);
>             selcpunames.put(cpuname,cpuname);
>       }
>           return selcpunames;
>    }
>
>
> public void setCpuid(String cpuid){
>   this.cpuid=cpuid;
> }
> public String getCpuid(){
>
>   return cpuid;
> }
>
>
>
> When I am running
> If its  null    //    in tomcat
>
> And
>
> cpuids": Value is not a valid option.
>
> What is the problem with my code please tell  and  what to change
>
> With regards
> Shannu sarma
> --
> View this message in context: http://www.nabble.com/selectonemenuitem-problems--Value-is-not-a-valid-option-tf1917733.html#a5249864
> Sent from the MyFaces - Users forum at Nabble.com.
>
>