<h:selectOneRadio> inside <h:dataTable>
asookazian Oct 2, 2007 6:36 PMusing Seam 1.2.1.GA and JBoss 4.0.5.GA with MyFaces, I'm able to render the Yes/No radio button outside of a dataTable but not inside one. Anybody know what I'm doing wrong here?? I duplicated some member variables and methods in both .java classes to "try things" since it wasn't rendering the radio buttons inside the dataTable.
In h:dataTable, it doesn't make a difference if I reference the backing bean or the Car POJO for the currentCar and carRadioButtons getter EL methods... Any tips would be appreciated. thx.
test3.xhtml:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.ajax4jsf.org/rich" template="layout/template.xhtml"> <ui:define name="body"> <h:dataTable value="#{carBean.myCars}" var="myRow" > <h:column> <f:facet name="header">VIN</f:facet> <h:outputText value="#{myRow.VIN}"/> </h:column> <h:column> <f:facet name="header">model</f:facet> <h:outputText value="#{myRow.model}"/> </h:column> <h:column> <f:facet name="header">make</f:facet> <h:outputText value="#{myRow.make}"/> </h:column> <h:selectOneRadio value="#{myRow.currentCar}"> <f:selectItems value="#{myRow.carRadioButtons}" /> </h:selectOneRadio> </h:dataTable> outside datatable <h:selectOneRadio value="#{carBean.currentCar}"> <f:selectItems value="#{carBean.carRadioButtons}" /> </h:selectOneRadio> </ui:define> </ui:composition>
CarBean.java session-scoped backing bean:
package com.cox.beans.session; import java.util.ArrayList; import java.util.List; import javax.faces.model.SelectItem; import com.cox.beans.entity.Car; public class CarBean { private List<SelectItem> myRadioButtonList; private List<Car> myCarList; private String currentCar; public List<SelectItem> getCarRadioButtons() { myRadioButtonList = new ArrayList<SelectItem>(); myRadioButtonList.add(new SelectItem("1", "Yes", "Yes it is")); myRadioButtonList.add(new SelectItem("2", "No", "No it isn't")); return myRadioButtonList; } public void setCarRadioButtons(List<SelectItem> myRadioButtonList) { this.myRadioButtonList = myRadioButtonList; } public void setCurrentCar(String currentCar) { this.currentCar = currentCar; } public String getCurrentCar() { return currentCar; } public List getMyCars() { myCarList = new ArrayList<Car>(); Car car1 = new Car("123", "Diablo", "Lamborghini"); Car car2 = new Car("456", "Corolla", "Toyota"); Car car3 = new Car("789", "Accord", "Honda"); myCarList.add(car1); myCarList.add(car2); myCarList.add(car3); return myCarList; } }
Car.java POJO:
package com.cox.beans.entity; import java.util.ArrayList; import java.util.List; import javax.faces.model.SelectItem; public class Car { private String VIN; private String model; private String make; private List<SelectItem> myRadioButtonList; private String currentCar; public List<SelectItem> getCarRadioButtons() { myRadioButtonList = new ArrayList<SelectItem>(); myRadioButtonList.add(new SelectItem("1", "Yes", "Yes it is")); myRadioButtonList.add(new SelectItem("2", "No", "No it isn't")); return myRadioButtonList; } public void setCarRadioButtons(List<SelectItem> myRadioButtonList) { this.myRadioButtonList = myRadioButtonList; } public void setCurrentCar(String currentCar) { this.currentCar = currentCar; } public String getCurrentCar() { return currentCar; } public Car(String VIN, String model, String make) { this.VIN = VIN; this.model = model; this.make = make; } public String getVIN(){ return VIN; } public void setVIN(String VIN) { this.VIN = VIN; } public String getModel(){ return this.model; } public void setModel(String model) { this.model = model; } public String getMake(){ return this.make; } public void setMake(String make) { this.make = make; } }