/** * Adds an account info.<p> * * @param field the field * @param addInfoKey the additional info key * @param editable the editable flag */ public void addAccountInfo(String field, String addInfoKey, String editable) { addAccountInfo(new CmsAccountInfo(field, addInfoKey, editable)); }
/** * Returns the field label.<p> * * @param info the info * * @return the label */ private String getLabel(CmsAccountInfo info) { if (info.isAdditionalInfo()) { String label = CmsVaadinUtils.getMessageText("GUI_USER_DATA_" + info.getAddInfoKey().toUpperCase() + "_0"); if (CmsMessages.isUnknownKey(label)) { return info.getAddInfoKey(); } else { return label; } } else { return CmsVaadinUtils.getMessageText("GUI_USER_DATA_" + info.getField().name().toUpperCase() + "_0"); } }
PropertyUtilsBean propUtils = new PropertyUtilsBean(); for (CmsAccountInfo info : OpenCms.getWorkplaceManager().getAccountInfos()) { if (info.isEditable()) { if (info.isAdditionalInfo()) { m_user.setAdditionalInfo(info.getAddInfoKey(), m_infos.getItemProperty(info).getValue()); } else { propUtils.setProperty( m_user, info.getField().name(), m_infos.getItemProperty(info).getValue());
/** * Builds the text field for the given property.<p> * * @param label the field label * @param info the property name * * @return the field */ private TextField buildField(String label, CmsAccountInfo info) { TextField field = (TextField)m_binder.buildAndBind(label, info); field.setConverter(new CmsNullToEmptyConverter()); field.setWidth("100%"); field.setEnabled(info.isEditable()); if (info.isEditable()) { field.addValidator(new FieldValidator(info.getField())); } field.setImmediate(true); return field; }
/** * Initializes the form fields.<p> */ private void initFields() { m_infos = new PropertysetItem(); for (CmsAccountInfo info : OpenCms.getWorkplaceManager().getAccountInfos()) { String value = info.getValue(m_user); if (value == null) { value = ""; } m_infos.addItemProperty(info, new ObjectProperty<String>(value)); } m_binder = new FieldGroup(m_infos); for (CmsAccountInfo info : OpenCms.getWorkplaceManager().getAccountInfos()) { m_form.addComponent(buildField(getLabel(info), info)); } }
for (CmsAccountInfo info : accountInfos) { Element infoElement = infosElement.addElement(N_ACCOUNTINFO); infoElement.addAttribute(A_FIELD, info.getField().name()); if (info.isAdditionalInfo()) { infoElement.addAttribute(A_ADD_INFO_KEY, info.getAddInfoKey()); infoElement.addAttribute(A_EDITABLE, Boolean.toString(info.isEditable()));
/** * Returns the account info value for the given user.<p> * * @param user the user * * @return the value */ public String getValue(CmsUser user) { String value = null; if (isAdditionalInfo()) { value = (String)user.getAdditionalInfo(getAddInfoKey()); } else { try { PropertyUtilsBean propUtils = new PropertyUtilsBean(); value = (String)propUtils.getProperty(user, getField().name()); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOG.error("Error reading account info field.", e); } } return value; }