Thank you for the replies folks.

I'm not that experienced with neither JSF nor Tobago, but I find it a bit 
strange that I have to tie in a converter in this case.
Could you explain why I need one? The selectOneChoice is able to initially set 
the correct selected object based on getSelectedServiceReportType(), if I 
modify my test code to set the private selectedServiceReportType, without a 
converter.

The converter interface defines methods for converting from String to Object 
and from Object to String. In my case ServiceReportType is a complex type and a 
conversion to it from a String would not be possible. In theory all my 
ServiceReportTypes could have the same description/label. I'm confused as you 
might have noticed.. :)

My focus has been on the SelectItem class. As far as I can see these objects 
should be enough. Shouldn't the framework be able to forward the value of the 
SelectItem(Object) to my bound controller property when selected, via a set 
method?? At least this is the behaviour I'm used to other frameworks. 

Thanks again

Jarle Halvorsen

-----Opprinnelig melding-----
Fra: weber.vol...@googlemail.com på vegne av Volker Weber
Sendt: ma 08.06.2009 19:47
Til: MyFaces Discussion
Emne: Re: [Tobago] Binding selected item from <tx:selectOneChoice>
 
Hi Jarle,

you need a converter for ServiceReportType.


Regards,
    Volker

2009/6/8 Jarle Halvorsen <j...@multiplus.as>:
> 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;
>
>   }
>
>
>
> }
>
>



-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13      | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX:  +49 441 4082 355 | www.inexso.de

<<winmail.dat>>

Reply via email to