📄 a_cmsedituserdialog.java
字号:
result.append(createDialogRowsHtml(9, 11));
} else {
result.append(createDialogRowsHtml(9, 9));
}
result.append(createWidgetTableEnd());
result.append(dialogBlockEnd());
}
result.append(createWidgetTableEnd());
return result.toString();
}
/**
* Creates a new user.<p>
*
* @param name the name
* @param pwd the password
* @param desc the description
* @param info the additional information map
*
* @return the new user
*
* @throws CmsException if something goes wrong
*/
protected abstract CmsUser createUser(String name, String pwd, String desc, Map info) throws CmsException;
/**
* Creates the list of widgets for this dialog.<p>
*/
protected void defineWidgets() {
// initialize the user object to use for the dialog
initUserObject();
setKeyPrefix(KEY_PREFIX);
// widgets to display
if (m_user.getId() == null && isEditable(m_user)) {
addWidget(new CmsWidgetDialogParameter(m_user, "name", PAGES[0], new CmsInputWidget()));
} else {
addWidget(new CmsWidgetDialogParameter(m_user, "name", PAGES[0], new CmsDisplayWidget()));
}
if (isEditable(m_user)) {
addWidget(new CmsWidgetDialogParameter(m_user, "description", "", PAGES[0], new CmsTextareaWidget(), 0, 1));
addWidget(new CmsWidgetDialogParameter(m_user, "lastname", PAGES[0], new CmsInputWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "firstname", PAGES[0], new CmsInputWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "email", PAGES[0], new CmsInputWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "address", "", PAGES[0], new CmsInputWidget(), 0, 1));
addWidget(new CmsWidgetDialogParameter(m_user, "zipcode", "", PAGES[0], new CmsInputWidget(), 0, 1));
addWidget(new CmsWidgetDialogParameter(m_user, "city", "", PAGES[0], new CmsInputWidget(), 0, 1));
addWidget(new CmsWidgetDialogParameter(m_user, "country", "", PAGES[0], new CmsInputWidget(), 0, 1));
} else {
addWidget(new CmsWidgetDialogParameter(m_user, "description", PAGES[0], new CmsDisplayWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "lastname", PAGES[0], new CmsDisplayWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "firstname", PAGES[0], new CmsDisplayWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "email", PAGES[0], new CmsDisplayWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "address", PAGES[0], new CmsDisplayWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "zipcode", PAGES[0], new CmsDisplayWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "city", PAGES[0], new CmsDisplayWidget()));
addWidget(new CmsWidgetDialogParameter(m_user, "country", PAGES[0], new CmsDisplayWidget()));
}
addWidget(new CmsWidgetDialogParameter(m_user, "enabled", PAGES[0], new CmsCheckboxWidget()));
if (isPwdChangeAllowed(m_user)) {
addWidget(new CmsWidgetDialogParameter(m_pwdInfo, "newPwd", PAGES[0], new CmsPasswordWidget()));
addWidget(new CmsWidgetDialogParameter(m_pwdInfo, "confirmation", PAGES[0], new CmsPasswordWidget()));
}
}
/**
* Returns the dialog class name of the list to refresh.<p>
*
* @return the list dialog class name
*/
protected abstract String getListClass();
/**
* Returns the root path for the list tool.<p>
*
* @return the root path
*/
protected abstract String getListRootPath();
/**
* @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
*/
protected String[] getPageArray() {
return PAGES;
}
/**
* @see org.opencms.workplace.CmsWorkplace#initMessages()
*/
protected void initMessages() {
// add specific dialog resource bundle
addMessages(Messages.get().getBundleName());
// add default resource bundles
super.initMessages();
}
/**
* Initializes the user object to work with depending on the dialog state and request parameters.<p>
*
* Two initializations of the user object on first dialog call are possible:
* <ul>
* <li>edit an existing user</li>
* <li>create a new user</li>
* </ul>
*/
protected void initUserObject() {
Object o = null;
try {
if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
// edit an existing user, get the user object from db
m_user = getCms().readUser(new CmsUUID(getParamUserid()));
m_pwdInfo = new CmsPasswordInfo();
return;
} else {
// this is not the initial call, get the user object from session
o = getDialogObject();
Map dialogObject = (Map)o;
m_user = (CmsUser)dialogObject.get(USER_OBJECT);
m_pwdInfo = (CmsPasswordInfo)dialogObject.get(PWD_OBJECT);
// test
m_user.getId();
return;
}
} catch (Exception e) {
// noop
}
// create a new user object
m_user = new CmsUser();
m_pwdInfo = new CmsPasswordInfo();
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
// initialize parameters and dialog actions in super implementation
super.initWorkplaceRequestValues(settings, request);
// save the current state of the user and pwd (may be changed because of the widget values)
Map dialogObject = new HashMap();
dialogObject.put(USER_OBJECT, m_user);
dialogObject.put(PWD_OBJECT, m_pwdInfo);
setDialogObject(dialogObject);
}
/**
* Tests if the given user is editable or not.<p>
*
* Not editable means that the user can only be activated and deactivated.<p>
*
* @param user the user to test
*
* @return the editable flag
*/
protected abstract boolean isEditable(CmsUser user);
/**
* Indicates if the pwd can be edited or not.<p>
*
* @param user the edited cms user
*
* @return <code>true</code> if the pwd can be edited
*/
protected boolean isPwdChangeAllowed(CmsUser user) {
return user == user; // to avoid warning
}
/**
* @see org.opencms.workplace.CmsWidgetDialog#validateParamaters()
*/
protected void validateParamaters() throws Exception {
if (!isNewUser()) {
// test the needed parameters
getCms().readUser(new CmsUUID(getParamUserid())).getName();
}
}
/**
* Writes a user to the db.<p>
*
* @param user the user to write
*
* @throws CmsException if something goes wrong
*/
protected abstract void writeUser(CmsUser user) throws CmsException;
/**
* Checks if the new user dialog has to be displayed.<p>
*
* @return <code>true</code> if the new user dialog has to be displayed
*/
private boolean isNewUser() {
return getCurrentToolPath().equals(getListRootPath() + "/new");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -