public static List<SelectItem> createSelectItems(UIComponent component) { List<SelectItem> items = new ArrayList<SelectItem>(); Iterator<UIComponent> children = component.getChildren().iterator(); while (children.hasNext()) { UIComponent child = children.next(); if (child instanceof UISelectItem) { UISelectItem selectItem = (UISelectItem) child; items.add(new SelectItem(selectItem.getItemValue(), selectItem.getItemLabel())); } else if (child instanceof UISelectItems) { Object selectItems = ((UISelectItems) child).getValue(); if (selectItems instanceof SelectItem[]) { SelectItem[] itemsArray = (SelectItem[]) selectItems; for (SelectItem item : itemsArray) items.add(new SelectItem(item.getValue(), item.getLabel())); } else if (selectItems instanceof Collection) { Collection<SelectItem> collection = (Collection<SelectItem>) selectItems; for (SelectItem item : collection) items.add(new SelectItem(item.getValue(), item.getLabel())); } } } return items; }
/** Move items from components to others. */ public static void moveAllItems( UISelectItems sourceItems, UISelectItems targetItems, UIEditableList hiddenTargetList, boolean setTargetIds) { SelectItem[] all = (SelectItem[]) sourceItems.getValue(); List<SelectItem> toMove = new ArrayList<SelectItem>(); List<SelectItem> toKeep = new ArrayList<SelectItem>(); List<String> hiddenIds = new ArrayList<String>(); if (all != null) { for (SelectItem item : all) { if (!item.isDisabled()) { toMove.add(item); } else { toKeep.add(item); } } } // reset left values sourceItems.setValue(toKeep.toArray(new SelectItem[] {})); // change right values List<SelectItem> newSelectItems = new ArrayList<SelectItem>(); SelectItem[] oldSelectItems = (SelectItem[]) targetItems.getValue(); if (oldSelectItems == null) { newSelectItems.addAll(toMove); } else { newSelectItems.addAll(Arrays.asList(oldSelectItems)); List<String> oldIds = new ArrayList<String>(); for (SelectItem oldItem : oldSelectItems) { String id = oldItem.getValue().toString(); oldIds.add(id); } if (setTargetIds) { hiddenIds.addAll(0, oldIds); } for (SelectItem toMoveItem : toMove) { String id = toMoveItem.getValue().toString(); if (!oldIds.contains(id)) { newSelectItems.add(toMoveItem); if (setTargetIds) { hiddenIds.add(id); } } } } targetItems.setValue(newSelectItems.toArray(new SelectItem[] {})); // update hidden values int numValues = hiddenTargetList.getRowCount(); if (numValues > 0) { for (int i = numValues - 1; i > -1; i--) { hiddenTargetList.removeValue(i); } } for (String newHiddenValue : hiddenIds) { hiddenTargetList.addValue(newHiddenValue); } }
/** * Return: <br> * - the supported languages (i.e languages with a translation for labels and messages) if the * parameter is set to true <br> * - the non supported languages if the parameter is set to false * * @param supported * @return */ private List<SelectItem> getsupportedLanguages(boolean supported) { List<SelectItem> l = new ArrayList<SelectItem>(); for (SelectItem iso : isolanguages) { if (supported && isSupported(iso.getValue().toString()) || (!supported && !isSupported(iso.getValue().toString()))) { l.add(iso); } } return l; }
protected void encodeOption( FacesContext context, SelectCheckboxMenu menu, Object values, Object submittedValues, Converter converter, SelectItem option, int idx) throws IOException { ResponseWriter writer = context.getResponseWriter(); String itemValueAsString = getOptionAsString(context, menu, converter, option.getValue()); String name = menu.getClientId(context); String id = name + UINamingContainer.getSeparatorChar(context) + idx; boolean disabled = option.isDisabled() || menu.isDisabled(); Object valuesArray; Object itemValue; if (submittedValues != null) { valuesArray = submittedValues; itemValue = itemValueAsString; } else { valuesArray = values; itemValue = option.getValue(); } boolean checked = isSelected(context, menu, itemValue, valuesArray, converter); if (option.isNoSelectionOption() && values != null && !checked) { return; } // input writer.startElement("input", null); writer.writeAttribute("id", id, null); writer.writeAttribute("name", name, null); writer.writeAttribute("type", "checkbox", null); writer.writeAttribute("value", itemValueAsString, null); if (checked) writer.writeAttribute("checked", "checked", null); if (disabled) writer.writeAttribute("disabled", "disabled", null); if (menu.getOnchange() != null) writer.writeAttribute("onchange", menu.getOnchange(), null); writer.endElement("input"); // label writer.startElement("label", null); writer.writeAttribute("for", id, null); if (disabled) writer.writeAttribute("class", "ui-state-disabled", null); if (option.isEscape()) writer.writeText(option.getLabel(), null); else writer.write(option.getLabel()); writer.endElement("label"); }
public String editar(MensagemConvencao me) { mensagemConvencao = me; vencimento = mensagemConvencao.getVencimento(); // listaMensagens.remove(listaMensagens.get(idIndex)); msgConfirma = ""; if (mensagemConvencao.getConvencao().getId() != -1) { for (int i = 0; i < getListaConvencoes().size(); i++) { if (Integer.parseInt(getListaConvencoes().get(i).getDescription()) == mensagemConvencao.getConvencao().getId()) { idConvencao = (Integer) getListaConvencoes().get(i).getValue(); break; } } } if (mensagemConvencao.getGrupoCidade().getId() != -1) { List<SelectItem> grupo = getListaGrupoCidade(); for (SelectItem grupo1 : grupo) { if (Integer.parseInt(grupo1.getDescription()) == mensagemConvencao.getGrupoCidade().getId()) { idGrupo = (Integer) grupo1.getValue(); break; } } } if (mensagemConvencao.getTipoServico().getId() != -1) { List<SelectItem> tipoServico = getListaTipoServico(); for (SelectItem tipoServico1 : tipoServico) { if (Integer.parseInt(tipoServico1.getDescription()) == mensagemConvencao.getTipoServico().getId()) { idTipoServico = (Integer) tipoServico1.getValue(); break; } } } if (mensagemConvencao.getServicos().getId() != -1) { List<SelectItem> servicos = getListaServico(); for (SelectItem servico : servicos) { if (Integer.parseInt(servico.getDescription()) == mensagemConvencao.getServicos().getId()) { idServico = (Integer) servico.getValue(); break; } } } return "mensagem"; }
public static Converter getSelectItemConverter( Application facesApplication, Iterator<SelectItem> selectItems) { Converter converter = null; while (selectItems.hasNext() && converter == null) { SelectItem selectItem = selectItems.next(); if (selectItem instanceof SelectItemGroup) { SelectItemGroup selectItemGroup = (SelectItemGroup) selectItem; Iterator<SelectItem> groupSelectItems = Iterators.forArray(selectItemGroup.getSelectItems()); // Recursively get the converter from the SelectItems of the SelectItemGroup converter = getSelectItemConverter(facesApplication, groupSelectItems); } else { Class<?> selectItemClass = selectItem.getValue().getClass(); if (String.class.equals(selectItemClass)) { return null; // No converter required for strings } try { converter = facesApplication.createConverter( selectItemClass); // Lookup the converter registered for the class } catch (FacesException exception) { // Converter cannot be created } } } return converter; }
public static String getLabelByValueOnSelectItems(Object value, List<SelectItem> list) { for (SelectItem item : list) { if (item.getValue().equals(value)) { return item.getLabel(); } } return null; }
public void setLowPriorityEvents(List<SelectItem> events) { this.lowPriorityEvents = new ArrayList<String>(); Iterator<SelectItem> i = events.iterator(); while (i.hasNext()) { SelectItem e = i.next(); lowPriorityEvents.add(e.getValue()); } }
/** * Return the label of the language * * @param lang * @return */ public String getLanguageLabel(String lang) { for (SelectItem iso : isolanguages) { if (((String) iso.getValue()).equals(lang)) { return iso.getLabel(); } } return lang; }
@SuppressWarnings("rawtypes") @Test public void metodo1() throws IllegalArgumentException, Exception { this.scanningProvider = new ClassPathScanningCandidateComponentProvider(false); this.scanningProvider.addIncludeFilter( new AnnotationTypeFilter(javax.persistence.Entity.class)); List<Class<? extends Object>> classes = new ArrayList<Class<? extends Object>>(); for (BeanDefinition beanDef : this.scanningProvider.findCandidateComponents("br.com")) { classes.add(Class.forName(beanDef.getBeanClassName())); } CLAZZ: for (Class clazz : classes) { Field listaCampo[] = clazz.getDeclaredFields(); for (Field campo : listaCampo) { if (campo.getName().trim().equalsIgnoreCase("id")) { for (Annotation anotacao : campo.getAnnotations()) { if (anotacao.toString().contains("sequenceName")) { String array[] = anotacao.toString().split(","); String sequence = ""; for (String item : array) { if (item.contains("sequenceName")) { sequence = item.replace("sequenceName=", ""); break; } } if (sequence != null && !sequence.equals("")) { // Descobre o maior id do banco Integer ultimoId = dao.max(clazz); if (ultimoId == null) { ultimoId = 1; } Session session = dao.getCurrentSession(); String sql = "SELECT setval('SISFIE." + sequence.trim() + "', " + ultimoId + ");"; if (duplicadas.contains(sequence.trim())) { throw new IllegalArgumentException(); } duplicadas.add(sequence.trim()); session.createSQLQuery(sql).uniqueResult(); sequences.add(new SelectItem(ultimoId, sequence.trim())); continue CLAZZ; } } } } } } System.out.println("Total :" + sequences.size()); for (SelectItem item : sequences) { System.out.println(item.getLabel() + ": " + item.getValue()); } }
public static List<ClientSelectItem> getClientSelectItems( FacesContext facesContext, AbstractSelectManyComponent select, Iterator<SelectItem> selectItems) { List<ClientSelectItem> clientSelectItems = new ArrayList<ClientSelectItem>(); Object object = select.getValue(); List values; if (object == null) { values = new ArrayList(); } else if (object instanceof List) { values = (List) object; } else if (object instanceof Object[]) { values = Arrays.asList((Object[]) object); } else { throw new IllegalArgumentException( "Value expression must evaluate to either a List or Object[]"); } int count = values.size(); // TODO: Deal with SelectItemGroups while (selectItems.hasNext()) { SelectItem selectItem = selectItems.next(); boolean selected; int sortOrder; if (values.contains( selectItem .getValue())) { // TODO: this requires value#equals() to be overridden. Redo with // comparators? selected = true; sortOrder = values.indexOf(selectItem.getValue()); } else { selected = false; sortOrder = count; } ClientSelectItem clientSelectItem = SelectHelper.generateClientSelectItem( facesContext, select, selectItem, sortOrder, selected); clientSelectItems.add(clientSelectItem); if (!selected) { count++; } } Collections.sort(clientSelectItems, clientSelectItemComparator); return clientSelectItems; }
/* (non-Javadoc) * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String) */ @Override public Object getAsObject(FacesContext ctx, UIComponent component, String value) { SelectItem selectedItem = this.getSelectedItemByIndex(component, Integer.parseInt(value)); if (selectedItem != null) { return selectedItem.getValue(); } return null; }
@Test public void shouldSupportMap() throws Exception { Map<Object, Object> map = new LinkedHashMap<Object, Object>(); map.put("ka", "va"); map.put(null, "vb"); map.put("c", null); Iterator<SelectItem> iterator = newSelectItemsIterator(map); SelectItem a = iterator.next(); SelectItem b = iterator.next(); SelectItem c = iterator.next(); assertFalse(iterator.hasNext()); assertThat(a.getLabel(), is("ka")); assertThat(a.getValue(), is((Object) "va")); assertThat(b.getLabel(), is("vb")); assertThat(b.getValue(), is((Object) "vb")); assertThat(c.getLabel(), is("c")); assertThat(c.getValue(), is((Object) "")); }
public void fillAvailableViews(String[] views) { this.viewsSelectItems.clear(); boolean bFirst = true; for (String view : views) { SelectItem viewSelectItem = new SelectItem(view); this.viewsSelectItems.add(viewSelectItem); if (bFirst) { this.setSelectedViewItem((String) viewSelectItem.getValue()); bFirst = false; } } }
protected void encodeOption( FacesContext context, SelectOneListbox listbox, SelectItem option, Object values, Object submittedValues, Converter converter) throws IOException { ResponseWriter writer = context.getResponseWriter(); String itemValueAsString = getOptionAsString(context, listbox, converter, option.getValue()); boolean disabled = option.isDisabled() || listbox.isDisabled(); Object valuesArray; Object itemValue; if (submittedValues != null) { valuesArray = submittedValues; itemValue = itemValueAsString; } else { valuesArray = values; itemValue = option.getValue(); } boolean selected = isSelected(context, listbox, itemValue, valuesArray, converter); if (option.isNoSelectionOption() && values != null && !selected) { return; } writer.startElement("option", null); writer.writeAttribute("value", itemValueAsString, null); if (disabled) writer.writeAttribute("disabled", "disabled", null); if (selected) writer.writeAttribute("selected", "selected", null); if (option.isEscape()) { writer.writeText(option.getLabel(), null); } else { writer.write(option.getLabel()); } writer.endElement("option"); }
/** * Menu with first, the supported languages out of the properties, second all the iso languages * * @param SUPPORTED_LANGUAGES */ public void initLanguagesMenu() { // Add first languages out of properties languages = new ArrayList<SelectItem>(); languages.addAll(getsupportedLanguages(true)); // add a separator // languages.add(new SelectItem(null, "--")); // Add the other languages (non supported) // languages.addAll(getsupportedLanguages(false)); // init the string of all languages languagesAsString = ""; for (SelectItem s : languages) { languagesAsString += s.getValue() + "," + s.getLabel() + "|"; } }
/** * Make a new SelectItem[] with items whose ids belong to selected first, preserving inner * ordering of selected and its complement in all. * * <p>Again this assumes that selected is an ordered sub-list of all * * @param selected ids of selected items * @param all * @return */ static SelectItem[] shiftFirst(String[] selected, SelectItem[] all) { SelectItem[] res = new SelectItem[all.length]; int sl = selected.length; int i = 0; int j = sl; for (SelectItem item : all) { if (i < sl && item.getValue().toString().equals(selected[i])) { res[i++] = item; } else { res[j++] = item; } } return res; }
public String undo_action() throws Exception { networkDataService.undoLastEvent(); NetworkDataAnalysisEvent lastEvent = getLastEvent(); if (lastEvent.getAddedAttribute() != null) { for (SelectItem selectItem : vertexAttributeSelectItems) { if (lastEvent.getAddedAttribute().equals(selectItem.getValue())) { vertexAttributeSelectItems.remove(selectItem); break; } } } events.remove(getLastEvent()); canUndo = false; return null; }
private String getTablePassword(String tableName) { String tablePass = ""; for (Iterator iter = getViewIconTablesManagedBean().getIconTableNameList().iterator(); iter.hasNext(); ) { SelectItem element = (SelectItem) iter.next(); // if we have a match if (((String) element.getValue()).equalsIgnoreCase(tableName)) { tablePass = element.getDescription(); getViewIconTablesManagedBean().setSelectedTableName(element.getLabel()); logger.info("Table Name: " + element.getLabel()); break; } } logger.info("In getTablePassword() -- Table Pass: " + tablePass); return tablePass; }
protected void renderSelectItems( FacesContext context, UIComponent component, ResponseWriter writer, Iterator it, String[] selectedValues) throws IOException { while (it.hasNext()) { final SelectItem selectItem = (SelectItem) it.next(); if (selectItem instanceof SelectItemGroup) { SelectItemGroup selectItemGroup = (SelectItemGroup) selectItem; SelectItem[] selectItems = selectItemGroup.getSelectItems(); Iterator selectItemsIt = new ArrayIterator(selectItems); writer.startElement(JsfConstants.OPTGROUP_ELEM, component); RendererUtil.renderAttribute(writer, JsfConstants.LABEL_ATTR, selectItemGroup.getLabel()); // TODO case: optgroup is disabled renderSelectItems(context, component, writer, selectItemsIt, selectedValues); writer.endElement(JsfConstants.OPTGROUP_ELEM); } else { writer.startElement(JsfConstants.OPTION_ELEM, component); final Object value = selectItem.getValue(); RendererUtil.renderAttribute(writer, JsfConstants.VALUE_ATTR, value); final boolean disabled = UIComponentUtil.isDisabled(component) || selectItem.isDisabled(); final String labelClass = getLabelStyleClass(component, disabled); if (labelClass != null) { RendererUtil.renderAttribute(writer, JsfConstants.CLASS_ATTR, labelClass); } if (value != null && isSelected(selectedValues, value.toString())) { renderSelectedAttribute(writer); } if (selectItem.isDisabled()) { renderDisabledAttribute(writer); } writer.writeText(selectItem.getLabel(), null); writer.endElement(JsfConstants.OPTION_ELEM); } } }
protected void encodeFilter(FacesContext context, DataTable table, UIColumn column) throws IOException { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); ResponseWriter writer = context.getResponseWriter(); String separator = String.valueOf(UINamingContainer.getSeparatorChar(context)); String filterId = column.getContainerClientId(context) + separator + "filter"; String filterStyleClass = column.getFilterStyleClass(); String filterValue = null; if (table.isReset()) { filterValue = ""; } else { if (params.containsKey(filterId)) { filterValue = params.get(filterId); } else { ValueExpression filterValueVE = column.getValueExpression("filterValue"); if (filterValueVE != null) { filterValue = (String) filterValueVE.getValue(context.getELContext()); } else { filterValue = ""; } } } if (column.getValueExpression("filterOptions") == null) { filterStyleClass = filterStyleClass == null ? DataTable.COLUMN_INPUT_FILTER_CLASS : DataTable.COLUMN_INPUT_FILTER_CLASS + " " + filterStyleClass; writer.startElement("input", null); writer.writeAttribute("id", filterId, null); writer.writeAttribute("name", filterId, null); writer.writeAttribute("class", filterStyleClass, null); writer.writeAttribute("value", filterValue, null); writer.writeAttribute("autocomplete", "off", null); if (column.getFilterStyle() != null) writer.writeAttribute("style", column.getFilterStyle(), null); if (column.getFilterMaxLength() != Integer.MAX_VALUE) writer.writeAttribute("maxlength", column.getFilterMaxLength(), null); writer.endElement("input"); } else { filterStyleClass = filterStyleClass == null ? DataTable.COLUMN_FILTER_CLASS : DataTable.COLUMN_FILTER_CLASS + " " + filterStyleClass; writer.startElement("select", null); writer.writeAttribute("id", filterId, null); writer.writeAttribute("name", filterId, null); writer.writeAttribute("class", filterStyleClass, null); SelectItem[] itemsArray = (SelectItem[]) getFilterOptions(column); for (SelectItem item : itemsArray) { Object itemValue = item.getValue(); writer.startElement("option", null); writer.writeAttribute("value", item.getValue(), null); if (itemValue != null && String.valueOf(itemValue).equals(filterValue)) { writer.writeAttribute("selected", "selected", null); } writer.writeText(item.getLabel(), null); writer.endElement("option"); } writer.endElement("select"); } }
protected void encodeItem( FacesContext context, SelectOneListbox listbox, SelectItem option, Object values, Object submittedValues, Converter converter, boolean customContent) throws IOException { ResponseWriter writer = context.getResponseWriter(); String itemValueAsString = getOptionAsString(context, listbox, converter, option.getValue()); boolean disabled = option.isDisabled() || listbox.isDisabled(); String itemClass = disabled ? SelectOneListbox.ITEM_CLASS + " ui-state-disabled" : SelectOneListbox.ITEM_CLASS; Object valuesArray; Object itemValue; if (submittedValues != null) { valuesArray = submittedValues; itemValue = itemValueAsString; } else { valuesArray = values; itemValue = option.getValue(); } boolean selected = isSelected(context, listbox, itemValue, valuesArray, converter); if (option.isNoSelectionOption() && values != null && !selected) { return; } if (selected) { itemClass = itemClass + " ui-state-highlight"; } if (customContent) { String var = listbox.getVar(); context.getExternalContext().getRequestMap().put(var, option.getValue()); writer.startElement("tr", null); writer.writeAttribute("class", itemClass, null); if (option.getDescription() != null) { writer.writeAttribute("title", option.getDescription(), null); } for (UIComponent child : listbox.getChildren()) { if (child instanceof Column && child.isRendered()) { writer.startElement("td", null); renderChildren(context, child); writer.endElement("td"); } } writer.endElement("tr"); } else { writer.startElement("li", null); writer.writeAttribute("class", itemClass, null); if (option.isEscape()) { writer.writeText(option.getLabel(), null); } else { writer.write(option.getLabel()); } writer.endElement("li"); } }
private void initialize() { this.setWspServiceEndPoint("http://<wsp-host-name:portnumber>/<webService>"); this.setWspSecurityMechanisms( new Integer[] { SecurityMechanism.SAML2_HOK.toInt(), SecurityMechanism.SAML2_SV.toInt(), SecurityMechanism.USERNAME_TOKEN.toInt(), SecurityMechanism.X509_TOKEN.toInt() }); this.setWspAuthenticationChain(null); this.setResponseSigned(false); this.setResponseEncrypted(false); this.setRequestSignatureVerified(true); this.setRequestHeaderDecrypted(false); this.setRequestDecrypted(false); this.setWscServiceName("WebServiceName"); this.setWscSecurityMechanism(SecurityMechanism.STS_SECURITY.toInt()); this.setConfigureWsc(false); this.setEncryptionAlgorithm(EncryptionAlgorithm.AES_256.toInt()); this.setUserNameTokenUserName(null); this.setUserNameTokenPassword(null); this.setX509TokenSigningReferenceType(X509SigningRefType.DIRECT.toInt()); this.setKerberosDomain(null); this.setKerberosDomainServer(null); this.setKerberosServicePrincipal(null); this.setKerberosTicketCache(null); List<SelectItem> stsConfigs = this.getStsConfigurationNameList(); if (stsConfigs.size() == 1) { SelectItem stsConfig = stsConfigs.iterator().next(); this.setStsConfigurationName((String) stsConfig.getValue()); } else { this.setStsConfigurationName(null); } List<SelectItem> aliases = this.getPrivateKeyAliasList(); if (aliases.size() == 1) { SelectItem alias = aliases.iterator().next(); this.setPrivateKeyAlias(alias.getLabel()); } else { this.setPrivateKeyAlias(null); } aliases = this.getPublicKeyAliasList(); if (aliases.size() == 1) { SelectItem alias = aliases.iterator().next(); this.setPublicKeyAlias(alias.getLabel()); } else { this.setPublicKeyAlias(null); } this.setSummaryRealm(new WssCreateWizardSummaryRealm(this)); this.setSummaryServiceEndPoint(new WssCreateWizardSummaryServiceEndPoint(this)); this.setSummaryWspSecurity(new WssCreateWizardSummaryWspSecurity(this)); this.setSummaryServiceName(new WssCreateWizardSummaryServiceName(this)); this.setSummaryWscSecurity(new WssCreateWizardSummaryWscSecurity(this)); this.setSummarySignEncrypt(new WssCreateWizardSummarySignEncrypt(this)); this.setSummaryKeyAliases(new WssCreateWizardSummaryKeyAliases(this)); this.setSummaryEncryptAlgorithm(new WssCreateWizardSummaryEncryptAlgorithm(this)); }