介绍
ADF中的多选组件多种多样,有<af:SelectManyCheckbox>,<af:SelectManyChoice>, <af:SelectManyListbox>,<af:selectManyShuttle>等,各组件使用起来都大同小异,都以数组来存储选中的值。
selectManyShuttle组件提供了用户的良好体验,本文简单介绍selectManyShuttle使用,其它多选组件可以自行举一反三。
selectManyShuttle组件效果预览如下图:
步骤
编写和配置Manage Bean(说明参见注释)
- package adf.selectmanyshuttle.view.bean;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import javax.faces.event.ValueChangeEvent;
- import oracle.adf.view.rich.context.AdfFacesContext;
- public class SelectManyShuttleBean {
- //保存选中值的数组
- private String[] selectedValues;
- //显示选中结果
- private String showMessage = "";
- //用于提供SelectManyShuttle中的列表值
- private List<String> values;
- public SelectManyShuttleBean() {
- super();
- //初始化选框列表
- if(values == null) {
- values = new ArrayList<String>();
- }
- values.add("AAAAAAA");
- values.add("BBBBBBB");
- values.add("CCCCCCC");
- values.add("DDDDDDD");
- values.add("EEEEEEE");
- //初始化选择的值
- selectedValues = new String[] {"AAAAAAA", "BBBBBBB"};
- }
- public String showSelectedValues() {
- // Add event code here...
- if(selectedValues != null) {
- for(int i=0; i<selectedValues.length; i++) {
- showMessage = showMessage + selectedValues[i] + ";";
- }
- }
- return null;
- }
- public void setSelectedValues(String[] selectedValues) {
- String[] tempValues = selectedValues;
- if(selectedValues != null) {
- List<String> newValues = new ArrayList<String>(Arrays.asList(selectedValues));
- List<String> oldValues = new ArrayList<String>(Arrays.asList(this.selectedValues));
- //特殊处理,选中DDDDDDD的同时,选中自动选中EEEEEEE
- if(newValues.contains("DDDDDDD") && !oldValues.contains("DDDDDDD")) {
- if(!newValues.contains("EEEEEEE") ) {
- newValues.add("EEEEEEE");
- tempValues = newValues.toArray(new String[] {});
- }
- }
- }
- this.selectedValues = tempValues;
- }
- public String[] getSelectedValues() {
- return selectedValues;
- }
- public void setValues(List<String> values) {
- this.values = values;
- }
- public List<String> getValues() {
- return values;
- }
- public void setShowMessage(String showMessage) {
- this.showMessage = showMessage;
- }
- public String getShowMessage() {
- return showMessage;
- }
- }
- <?xml version="1.0" encoding="UTF-8" ?>
- <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
- <managed-bean id="__2">
- <managed-bean-name id="__4">SelectManyShuttleBean</managed-bean-name>
- <managed-bean-class id="__3">adf.selectmanyshuttle.view.bean.SelectManyShuttleBean</managed-bean-class>
- <managed-bean-scope id="__1">request</managed-bean-scope>
- </managed-bean>
- </adfc-config>
构建页面
- <?xml version='1.0' encoding='UTF-8'?>
- <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
- <jsp:directive.page contentType="text/html;charset=UTF-8"/>
- <f:view>
- <af:document id="d1">
- <af:form id="f1">
- <af:panelGroupLayout id="pgl1" layout="vertical"
- inlineStyle="margin:5.0%;">
- <!--value属性初始化选中结果和保存选中结果-->
- <af:selectManyShuttle
- value="#{SelectManyShuttleBean.selectedValues}"
- id="sms1" autoSubmit="true"
- partialTriggers="sms1">
- <!--通过for each循环List初始化列表值-->
- <af:forEach items="#{SelectManyShuttleBean.values}" var="item">
- <af:selectItem id="si1" value="#{item}" label="#{item}"/>
- </af:forEach>
- </af:selectManyShuttle>
- <af:spacer width="10" height="10" id="s1"/>
- <af:outputText id="ot1" value="#{SelectManyShuttleBean.showMessage}"/>
- <af:commandButton text="Show Selected Values" id="cb1"
- action="#{SelectManyShuttleBean.showSelectedValues}"/>
- </af:panelGroupLayout>
- </af:form>
- </af:document>
- </f:view>
- </jsp:root>
参考文档
http://docs.oracle.com/cd/E23943_01/apirefs.1111/e12419/tagdoc/af_selectManyShuttle.html
转自:http://blog.csdn.net/ygj26/article/details/8822388