You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2006/06/26 22:56:35 UTC
[Myfaces Wiki] Update of "Display Radio Buttons In Columns" by PaulSpencer
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.
The following page has been changed by PaulSpencer:
http://wiki.apache.org/myfaces/Display_Radio_Buttons_In_Columns
New page:
The example below will display a list of 9 buttons in 3 columns.
JSF that displays the buttons. Notice the use of <t:radio> inside <t:dataTable>.
{{{
<t:dataTable newspaperColumns="3" var="row" value="#{buttonList.dataModel}" rowIndexVar="index">
<t:selectOneRadio id="buttons" layout="spread">
<f:selectItems value="#{buttonList.selectList}" />
</t:selectOneRadio>
<h:column>
<t:radio for="buttons" index="#{index}" />
</h:column>
</t:dataTable>
}}}
The class below creates a the list of 9 buttons and provides two views of the list. getSelectList()
provides a list of SelectItems required by <t:selectOneRadio>. getDataModel() is the same list, but
as a DataModel for <t:dataModel> to iterator over and provide an index to <t:radio>.
{{{
package com.foo.om;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
public class RadioButtons
{
private List selectList = new ArrayList();
private DataModel dataModel;
public RadioButtons()
{
selectList.add(new SelectItem("Button 1"));
selectList.add(new SelectItem("Button 2"));
selectList.add(new SelectItem("Button 3"));
selectList.add(new SelectItem("Button 4"));
selectList.add(new SelectItem("Button 5"));
selectList.add(new SelectItem("Button 6"));
selectList.add(new SelectItem("Button 7"));
selectList.add(new SelectItem("Button 8"));
selectList.add(new SelectItem("Button 9"));
dataModel = new ListDataModel(selectList);
}
/** Used by <t:selectOneRadio> **/
public List getSelectList()
{
return selectList;
}
/** Used by <t:dataTable> **/
public DataModel getDataModel()
{
return dataModel;
}
}
}}}
Declaration of the manage bean used above.
{{{
<managed-bean>
<managed-bean-name>buttonList</managed-bean-name>
<managed-bean-class>com.foo.om.RadioButtons</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
}}}