您的位置:首页 > 其它

af:selectManyChoose使用的获取值问题

2014-03-17 12:23 441 查看
组件绑定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);
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐