ITPub博客

首页 > Linux操作系统 > Linux操作系统 > A Programmatic SelectOneChoice Example

A Programmatic SelectOneChoice Example

原创 Linux操作系统 作者:05150214 时间:2011-04-05 11:30:09 0 删除 编辑
The application displays a list box and an input field. The user can add new items to the list box by typing a new value to the input field and clicking the “Add Item to List” button. Pressing the “Remove Selected Item From List” button will remove the current selected value from the list box.
 
 

 

Jspx:


                  binding="#{MyTestBean.newItemNameComponent}"/>

                        binding="#{MyTestBean.myTestListComponent}">
   
 


                      actionListener="#{MyTestBean.addNewItemToList}"/>

                      actionListener="#{MyTestBean.removeItemFromList}"
                    disabled="#{empty MyTestBean.listOfItems}"/>

MB:

public void addNewItemToList(ActionEvent actionEvent)
{
  String value = (String)newItemNameComponent.getValue();
  if(value != null && !value.equals(""))
  {
    SelectItem si = new SelectItem();
    si.setLabel(value);
    si.setValue(value);
    listOfItems.add(si);
    myTestListComponent.setValue(value);
    newItemNameComponent.setValue("");
  }
}

public void removeItemFromList(ActionEvent actionEvent)
{
  String removedValue = (String)myTestListComponent.getValue();
  if(removedValue != null && !removedValue.equals(""))
  {
    for(int i = 0; i < listOfItems.size(); i++)
    {
      SelectItem si = (SelectItem)listOfItems.get(i);
      if(si.getValue().equals(removedValue))
      {
        myTestListComponent.setValue(null);
        listOfItems.remove(i);
      }
    }
  }
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21900589/viewspace-691666/,如需转载,请注明出处,否则将追究法律责任。

上一篇: Introduction to ADF-BC
请登录后发表评论 登录
全部评论

注册时间:2009-06-15

  • 博文量
    13
  • 访问量
    10777