您的位置:首页 > 其它

rich:pickList标签的使用

2015-07-01 13:36 260 查看
使用标签之前要引入:xmlns:rich="http://richfaces.org/rich"

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"

      xmlns:ui="http://java.sun.com/jsf/facelets"

      xmlns:h="http://java.sun.com/jsf/html"

      xmlns:f="http://java.sun.com/jsf/core"

      xmlns:t="http://myfaces.apache.org/tomahawk"

      xmlns:a4j="http://richfaces.org/a4j"

      xmlns:i="http://www.fhdata.com/jsf"

      xmlns:rich="http://richfaces.org/rich">

<h:head>

    <title>选择显示的列</title>

 

    <script type="text/javascript">

    //<![CDATA[

       function saveEnd() {

           window.close();

           return false;

       }

    //]]>

    </script>

    

</h:head>

<h:body>

    <h:form id="SelectColumnForm">

        

        <rich:pickList converter="#{staffConverter}" id="selectedItem" value="#{productBean.selectedTradeSystemIndex}" targetCaption="已选项"

                        sourceCaption="待选项" listWidth="200px" listHeight="320px" orderable="true" addAllText=">>>" addText=">"  

                        removeAllText="<<<" removeText="<" downText="Down" upText="Up" upTopText="First" downBottomText="Last">

             <f:selectItems value="#{productBean.selectedIndex}"  />

             <f:selectItems value="#{productBean.unSelectedIndex}"  />

        </rich:pickList>

         <t:div id="operateBtn" style="position:fixed;right:0;bottom:0">

            <h:panelGrid columns="2" style="float:right;" cellspacing="5px">

                <a4j:commandButton id="okBtn" styleClass="btn" value="确定" action="#{productBean.changeIndex}" oncomplete="return saveEnd();"/>

                <h:commandButton id="cancelBtn" styleClass="btn" value="取消" onclick="window.close();return false;"/>

            </h:panelGrid>

        </t:div>

    </h:form>

</h:body>

</html>

对应的bean:

public class productBean{

    private List<String> selectedIndex;

    public List<String> getSelectedIndex() throws SQLException {

        List<String> selectedIndexs = new ArrayList<String>();

        selectedIndexs .add("cc");

       selectedIndexs .add("dd");

        return selectedIndexs ;

    }

    

    public List<String> getUnSelectedIndex() throws SQLException {

        List<String> unSelectedIndexs = new ArrayList<String>();

        unSelectedIndexs .add("aa");
       unSelectedIndexs .add("bb");

        return unSelectedIndexs ;

    }

    

    public void setSelectedIndex(List<String> selectedIndex) {

        this.selectedIndex= selectedIndex;

    }

   public void changeIndex() {

    //根据得到的selectedIndex的值进行处理

    }

}

xhtml页面写的rich:pickList标签,value对应的是右侧区域显示的内容,具体的内容来自于它下面对应的第一个f:selectItem标签里面的内容,左侧的区域来自于第二个f:selectItem标签,页面加载后,左侧区域显示cc,dd,右侧区域显示aa,bb

点击页面上的保存按钮,此时,会调用setSelectedIndex方法,将页面上选中的右侧区域的值赋值给 this.selectedIndex,此时就可以得到选中区域的值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息