af:selectManyChoose使用的获取值问题

来源:互联网 发布:电脑雕刻制图软件 编辑:程序博客网 时间:2024/05/21 09:11

组件绑定VO代码如下:

<af:selectManyChoice value="#{bindings.allDepartments.inputValue}"                       label="#{bindings.allDepartments.label}"                     id="smc1">  <f:selectItems value="#{bindings.allDepartments.items}" id="si1"/></af:selectManyChoice>

在实际开发中,获取下拉值出现的最多的二种问题是:1拿到的索引;2拿到选中值的前一条记录:

参考代码:

public String cb1_action() {  BindingContext bctx = BindingContext.getCurrent();  BindingContainer bindings = bctx.getCurrentBindingsEntry();  JUCtrlListBinding allDepartsmentList =            (JUCtrlListBinding) bindings.get("allDepartments");    Object[] selVals = allDepartsmentList.getSelectedValues();    for (int i = 0; i < selVals.length; i++) {      Integer val = (Integer)selVals[i];      //...    }   return null;}


public String cb1_action() {  BindingContext bctx = BindingContext.getCurrent();  BindingContainer bindings = bctx.getCurrentBindingsEntry();  JUCtrlListBinding allDepartsmentList =           (JUCtrlListBinding) bindings.get("allDepartments");  int[] selVals = allDepartsmentList.getSelectedIndices();  for (int indx : selVals ) {    Row rw = allDepartsmentList.getRowAtRangeIndex(indx);    //... do your stuff  }  return null;}

    /**     *      * @param attrName     * @param ind 选择的下拉索引值     * @param retrunStr 返回的属性字段名称     * @return     */    public static Object getSelectListValue(String attrName,Object ind,String retrunStr){        BindingContext bctx = BindingContext.getCurrent();        BindingContainer bindings = bctx.getCurrentBindingsEntry();        JUCtrlListBinding listBinding = (JUCtrlListBinding) bindings.get(attrName);        listBinding.setSelectedIndex(Integer.parseInt(ind.toString()));        Row selectedValue = (Row) listBinding.getSelectedValue();        return selectedValue.getAttribute(retrunStr);    }



0 0
原创粉丝点击