javax.faces.component.UISelectItem Java Examples

The following examples show how to use javax.faces.component.UISelectItem. 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: SelectItemsIterator.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @return the next valid child for processing
 */
private Object findNextValidChild() {
	if (kids.hasNext()) {
		Object next = kids.next();
		while (kids.hasNext() && !(next instanceof UISelectItem || next instanceof UISelectItems)) {
			next = kids.next();
		}
		if (next instanceof UISelectItem || next instanceof UISelectItems) {
			return next;
		}
	}
	return null;
}
 
Example #2
Source File: SelectMultiMenuRenderer.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * Parts of this class are an adapted version of
 * InputRenderer#getSelectItems() of PrimeFaces 5.1.
 *
 * @param rw
 * @param selectedOption
 * @throws IOException
 */
protected void renderOptions(FacesContext context, ResponseWriter rw, String[] selectedOption, SelectMultiMenu menu)
		throws IOException {
	Converter converter = menu.getConverter();
	List<SelectItemAndComponent> items = SelectItemUtils.collectOptions(context, menu, converter);

	for (int index = 0; index < items.size(); index++) {
		Object option = items.get(index).getSelectItem();
		if (option instanceof SelectItem) {
			renderOption(rw, (SelectItem) option, selectedOption, index);
		} else {
			renderOption(rw, (UISelectItem) option, selectedOption, index);
		}
	}
}
 
Example #3
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 #4
Source File: SelectMultiMenuRenderer.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
/** Receives the value from the client and sends it to the JSF bean. */
@Override
public void decode(FacesContext context, UIComponent component) {
	SelectMultiMenu menu = (SelectMultiMenu) component;
	if (menu.isDisabled() || menu.isReadonly()) {
		return;
	}
	List<String> submittedValues = new ArrayList<String>();
	String clientId = menu.getClientId().replace(":", "-");
	Map<String, String> map = context.getExternalContext().getRequestParameterMap();
	for (String key : map.keySet()) {
		if (key.startsWith(clientId + ":")) {
			submittedValues.add(map.get(key));
		}
	}
	Converter converter = menu.getConverter();
	List<SelectItemAndComponent> items = SelectItemUtils.collectOptions(context, menu, converter);


	if (!submittedValues.isEmpty()) {
		// check for manipulated input
		String result = null;
		for (String submittedOptionValue : submittedValues) {
			boolean found = false;
			for (int index = 0; index < items.size(); index++) {
				Object currentOption = items.get(index).getSelectItem();
				String currentOptionValueAsString;
				Object currentOptionValue;
				if (currentOption instanceof SelectItem) {
					currentOptionValue = ((SelectItem) currentOption).getValue();
				} else {
					currentOptionValue = ((UISelectItem) currentOption).getItemValue();
				}
				if (currentOptionValue instanceof String) {
					currentOptionValueAsString = (String) currentOptionValue;
				} else if (currentOptionValue instanceof Number) {
					currentOptionValueAsString = currentOptionValue.toString();
				} else
					currentOptionValueAsString = String.valueOf(index);
				if ("".equals(currentOptionValueAsString) && submittedOptionValue.equalsIgnoreCase("on")) {
					// this is a special case which occurs when the value is
					// set to "".
					// In this case, the browser sends "on" instead of the
					// empty string.
					submittedOptionValue = "";
				}
				if (submittedOptionValue.equals(currentOptionValueAsString)) {
					if (null == result)
						result = currentOptionValueAsString;
					else
						result += "," + currentOptionValue;
					found = true;
					break;
				}
			}
			if (!found) {
				FacesMessages.error(clientId, "Invalid data",
						"Couldn't set the value of the b:selectMultiMenu because an option that wasn't defined by the JSF source code was passed.");
				menu.setSubmittedValue(result);
				menu.setValid(false);
				return;
			}
		}
		menu.setSubmittedValue(result);
		menu.setValid(true);
		new AJAXRenderer().decode(context, component, clientId);
		return;
	}

	menu.setSubmittedValue("");
	menu.setValid(true);
	new AJAXRenderer().decode(context, component, clientId);
}
 
Example #5
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 #6
Source File: SelectMultiMenuRenderer.java    From BootsFaces-OSP with Apache License 2.0 3 votes vote down vote up
/**
 * Renders a single &lt;option&gt; tag. For some reason,
 * <code>SelectItem</code> and <code>UISelectItem</code> don't share a
 * common interface, so this method is repeated twice.
 *
 * @param rw
 *            The response writer
 * @param selectItem
 *            The current SelectItem
 * @param selectedOption
 *            the currently selected option
 * @throws IOException
 *             thrown if something's wrong with the response writer
 */
protected void renderOption(ResponseWriter rw, UISelectItem selectItem, String[] selectedOption, int index)
		throws IOException {

	String itemLabel = selectItem.getItemLabel();
	final String itemDescription = selectItem.getItemDescription();
	final Object itemValue = selectItem.getItemValue();

	boolean isItemLabelBlank = itemLabel == null || itemLabel.trim().length() == 0;
	itemLabel = isItemLabelBlank ? "&nbsp;" : itemLabel;

	renderOption(rw, selectedOption, index, itemLabel, itemDescription, itemValue);
}