javax.faces.component.UISelectOne Java Examples

The following examples show how to use javax.faces.component.UISelectOne. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StartInsertItemListener.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Standard process action method.
 * @param ae ValueChangeEvent
 * @throws AbortProcessingException
 */
public void processValueChange(ValueChangeEvent ae) throws AbortProcessingException {
  ItemAuthorBean itemauthorbean = (ItemAuthorBean) ContextUtil.lookupBean("itemauthor");

  String olditemtype = (String) ae.getOldValue();
  log.debug("StartInsertItemListener olditemtype ." + olditemtype);
  String selectedvalue= (String) ae.getNewValue();
  log.debug("StartInsertItemListener selecteevalue." + selectedvalue);
  String newitemtype = null;
  String insertItemPosition = null;
  String insertToSection = null;

  // only set itemtype when the value has indeed changed.
  if ((selectedvalue!=null) && (!selectedvalue.equals("")) ) {
    String[] strArray = selectedvalue.split(",");

    try {
      newitemtype = strArray[0].trim();
      ///////// SAK-3114: ///////////////////////////////////////////
      // note: you must include at least one selectItem in the form
      // type#,p#,q#
      // the rest, in a selectItems will get the p#,q# added in.
      ///////////////////////////////////////////////////////////////
      UISelectOne comp = (UISelectOne) ae.getComponent();
      List children = comp.getChildren();
      // right now there are two kids selectItems & selectItem
      // we use loop to keep this flexible
      for (int i = 0; i < children.size(); i++) {
        if (children.get(i) instanceof UISelectItem) {
            UISelectItem selectItem = (UISelectItem) children.get(i);
            log.debug("selectItem.getItemValue()="+selectItem.getItemValue());
            String itemValue =  (String) selectItem.getItemValue();
            log.debug("itemValue ="+ itemValue);
            String[] insertArray = itemValue.split(",");
            // add in p#,q#
            insertToSection = insertArray[1].trim();

            break;
        }
        if (ContextUtil.lookupParam("itemSequence") != null && !ContextUtil.lookupParam("itemSequence").trim().equals("")) {
      	insertItemPosition = ContextUtil.lookupParam("itemSequence");
        }
      }
    } catch (Exception ex) {
      log.warn("unable to process value change", ex);
      return;
    }
    itemauthorbean.setItemType(newitemtype);
    itemauthorbean.setInsertToSection(insertToSection);
    itemauthorbean.setInsertPosition(insertItemPosition);
    itemauthorbean.setInsertType(newitemtype);
    itemauthorbean.setItemNo(String.valueOf(Integer.parseInt(insertItemPosition) +1));
    // clean up before new question SAK-6506  
    itemauthorbean.setAttachmentList(null);
    itemauthorbean.setTagsList(null);
    itemauthorbean.setResourceHash(null);
    itemauthorbean.setItemId("");
    itemauthorbean.setRbcsToken(rubricsService.generateJsonWebToken(RubricsConstants.RBCS_TOOL_SAMIGO));
    itemauthorbean.setRubricStateDetails("");

    StartCreateItemListener listener = new StartCreateItemListener();
    if (!listener.startCreateItem(itemauthorbean)) {
      throw new RuntimeException("failed to startCreatItem.");
    }

  }
}
 
Example #2
Source File: StartInsertItemListener.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Standard process action method.
 * @param ae ValueChangeEvent
 * @throws AbortProcessingException
 */
public void processValueChange(ValueChangeEvent ae) throws AbortProcessingException {
  ItemAuthorBean itemauthorbean = (ItemAuthorBean) ContextUtil.lookupBean("itemauthor");

  String olditemtype = (String) ae.getOldValue();
  log.debug("StartInsertItemListener olditemtype ." + olditemtype);
  String selectedvalue= (String) ae.getNewValue();
  log.debug("StartInsertItemListener selecteevalue." + selectedvalue);
  String newitemtype = null;
  String insertItemPosition = null;
  String insertToSection = null;

  // only set itemtype when the value has indeed changed.
  if ((selectedvalue!=null) && (!selectedvalue.equals("")) ) {
    String[] strArray = selectedvalue.split(",");

    try {
      newitemtype = strArray[0].trim();
      ///////// SAK-3114: ///////////////////////////////////////////
      // note: you must include at least one selectItem in the form
      // type#,p#,q#
      // the rest, in a selectItems will get the p#,q# added in.
      ///////////////////////////////////////////////////////////////
      UISelectOne comp = (UISelectOne) ae.getComponent();
      List children = comp.getChildren();
      // right now there are two kids selectItems & selectItem
      // we use loop to keep this flexible
      for (int i = 0; i < children.size(); i++) {
        if (children.get(i) instanceof UISelectItem) {
            UISelectItem selectItem = (UISelectItem) children.get(i);
            log.debug("selectItem.getItemValue()="+selectItem.getItemValue());
            String itemValue =  (String) selectItem.getItemValue();
            log.debug("itemValue ="+ itemValue);
            String[] insertArray = itemValue.split(",");
            // add in p#,q#
            insertToSection = insertArray[1].trim();

            break;
        }
        if (ContextUtil.lookupParam("itemSequence") != null && !ContextUtil.lookupParam("itemSequence").trim().equals("")) {
      	insertItemPosition = ContextUtil.lookupParam("itemSequence");
        }
      }
    } catch (Exception ex) {
      log.warn("unable to process value change", ex);
      return;
    }
    itemauthorbean.setItemType(newitemtype);
    itemauthorbean.setInsertToSection(insertToSection);
    itemauthorbean.setInsertPosition(insertItemPosition);
    itemauthorbean.setInsertType(newitemtype);
    itemauthorbean.setItemNo(String.valueOf(Integer.parseInt(insertItemPosition) +1));
    // clean up before new question SAK-6506  
    itemauthorbean.setAttachmentList(null);
    itemauthorbean.setTagsList(null);
    itemauthorbean.setResourceHash(null);
    itemauthorbean.setItemId("");
    itemauthorbean.setRbcsToken(rubricsService.generateJsonWebToken(RubricsConstants.RBCS_TOOL_SAMIGO));
    itemauthorbean.setRubricStateDetails("");

    StartCreateItemListener listener = new StartCreateItemListener();
    if (!listener.startCreateItem(itemauthorbean)) {
      throw new RuntimeException("failed to startCreatItem.");
    }

  }
}