I don't think a command button is a valid child of a selectitem tag.

-Richard

Sent from my iPhone

On Jun 8, 2009, at 4:22 AM, "Jarle Halvorsen" <j...@multiplus.as> wrote:

Hi.



Im on tobago 1.0.20



I'm think I've missed something here. I just can't find out what is wrong with my code. I'm trying to bind the selected item of a selectOneChoice to a property on a controller.

The selectOneChoice is initially rendered correctly with data from my database. But when I try to select from the list, I get a validation error, and the setSelectedServiceReportType to set the value back to the controller is never called. If I set the test up with an int og even a Long as values for the selectItems it all works fine..



What am I doing wrong??



I have this test code:



jsp:

            <tc:box label="Register New Report">

                  <tc:panel>

                             <f:facet name="layout">

<tc:gridLayout columns="*;*;" rows="fixed;" border="0" />

                              </f:facet>

<tx:selectOneChoice label="Select One" value="#{testController.selectedServiceReportType}">

<f:selectItems value="#{testController.serviceReportTypes}"/>

                             <f:facet name="change">

<tc:command action="#{testController.selectedServiceReportTypeAction}"/>

                             </f:facet>

                              </tx:selectOneChoice>



                        <tx:label value="TEsting"/>

                  </tc:panel>

            </tc:box>





controller:



public class TestController {



  private ArrayList<ServiceReportType> serviceReportTypes;

  private ServiceReportType selectedServiceReportType;



public void setSelectedServiceReportType(ServiceReportType selectedServiceReportType) {

    this.selectedServiceReportType = selectedServiceReportType;

  }



  public ServiceReportType getSelectedServiceReportType() {

      return selectedServiceReportType;

  }



  public ArrayList<SelectItem> getServiceReportTypes() {

    if (serviceReportTypes == null) {

      serviceReportTypes = new ArrayList<ServiceReportType>();

      for (int i = 0; i < 3; i++) {

        ServiceReportType serviceReportType = new ServiceReportType();

        serviceReportType.setDescription("Decription " + i);

        serviceReportTypes.add(serviceReportType);

      }

    }



    ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>();

    for (ServiceReportType serviceReportType : serviceReportTypes) {

selectItems.add(new SelectItem(serviceReportType, serviceReportType.getDescription()));

    }

    return selectItems;

  }



  public String selectedServiceReportTypeAction() {

    return "OK";

  }



}



ServiceReportType entity (which is Hibernate mapped):



public class ServiceReportType implements Serializable {



  private static final long serialVersionUID = 2869236275653791385L;



  private Long id;

  private String typeCode;

  private String description;



  public Long getId() {

    return id;

  }



  public void setId(Long id) {

    this.id = id;

  }



  public String getTypeCode() {

    return typeCode;

  }



  public void setTypeCode(String typeCode) {

    this.typeCode = typeCode;

  }



  public String getDescription() {

    return description;

  }



  public void setDescription(String description) {

    this.description = description;

  }



}



ze:10.0pt;font-family:"Courier New";color:black'>.description = description;
  }



}


Reply via email to