本文整理匯總了Java中org.apache.struts.action.ActionMessage類的典型用法代碼示例。如果您正苦於以下問題:Java ActionMessage類的具體用法?Java ActionMessage怎麽用?Java ActionMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ActionMessage類屬於org.apache.struts.action包,在下文中一共展示了ActionMessage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getActionMessage
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
/**
* Gets the <code>ActionMessage</code> based on the
* <code>ValidatorAction</code> message and the <code>Field</code>'s
* arg objects.
* @param request the servlet request
* @param va Validator action
* @param field the validator Field
*/
public static ActionMessage getActionMessage(
HttpServletRequest request,
ValidatorAction va,
Field field) {
String args[] =
getArgs(
va.getName(),
getMessageResources(request),
RequestUtils.getUserLocale(request, null),
field);
String msg =
field.getMsg(va.getName()) != null
? field.getMsg(va.getName())
: va.getMsg();
return new ActionMessage(msg, args);
}
示例2: handleCancelCommand
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
/**
* NOT YET DOCUMENTED
*
* @param mapping NOT YET DOCUMENTED
* @param form NOT YET DOCUMENTED
* @param request NOT YET DOCUMENTED
* @param response NOT YET DOCUMENTED
* @return NOT YET DOCUMENTED
*/
protected ActionForward handleCancelCommand(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
SuggestCommentForm scf = (SuggestCommentForm) form;
ActionErrors errors = new ActionErrors();
scf.clear();
scf.setItemID("");
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("comment.cancel"));
saveMessages(request, errors);
return mapping.findForward("home");
}
示例3: validateIsDirectory
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
/**
* Validates that the field value is an existing directory on the server that the application is running on.
*
* @param bean The Struts bean
* @param va the ValidatorAction
* @param field The Field
* @param messages The ActionMessages
* @param validator The Validator
* @param request The HttpServletRequest
* @param servletContext The ServletContext
* @return True if the directory exists
*/
public static boolean validateIsDirectory(
Object bean,
ValidatorAction va,
Field field,
ActionMessages messages,
Validator validator,
HttpServletRequest request,
ServletContext servletContext) {
// Get the value the user entered:
String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
File dir = new File(value.trim());
// Validate that this is a directory on the server that already exists:
if (!dir.isDirectory()) {
ActionMessage message = Resources.getActionMessage(validator, request, va, field);
messages.add(field.getKey(), message);
return false;
}
else
return true;
}
示例4: validateNamespaceIdentifier
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
/**
* Validates that the String is a valid namespace identifier for OAI.
*
* @param bean The Struts bean
* @param va the ValidatorAction
* @param field The Field
* @param messages The ActionMessages
* @param validator The Validator
* @param request The HttpServletRequest
* @param servletContext The ServletContext
* @return True if valid
*/
public static boolean validateNamespaceIdentifier(
Object bean,
ValidatorAction va,
Field field,
ActionMessages messages,
Validator validator,
HttpServletRequest request,
ServletContext servletContext) {
// Get the value the user entered:
String repositoryIdentifier = ValidatorUtils.getValueAsString(bean, field.getProperty());
boolean isValid = (
repositoryIdentifier == null ||
repositoryIdentifier.length() == 0 ||
repositoryIdentifier.matches("[a-zA-Z][a-zA-Z0-9\\-]*(\\.[a-zA-Z][a-zA-Z0-9\\-]+)+"));
if(!isValid) {
ActionMessage message = Resources.getActionMessage(validator, request, va, field);
messages.add(field.getKey(), message);
}
return isValid;
}
示例5: validateImageFile
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
/**
* Validate imageGallery item.
*
* @param itemForm
* @return
*/
private ActionErrors validateImageFile(AuthoringForm itemForm) {
ActionErrors errors = new ActionErrors();
// validate file size
FileValidatorUtil.validateFileSize(itemForm.getFile(), true, errors);
// for edit validate: file already exist
if (!itemForm.isHasFile()
&& ((itemForm.getFile() == null) || StringUtils.isEmpty(itemForm.getFile().getFileName()))) {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(PixlrConstants.ERROR_MSG_FILE_BLANK));
}
// check for allowed format : gif, png, jpg
if (itemForm.getFile() != null) {
String contentType = itemForm.getFile().getContentType();
if (StringUtils.isEmpty(contentType) || !(contentType.equals("image/gif") || contentType.equals("image/png")
|| contentType.equals("image/jpg") || contentType.equals("image/jpeg")
|| contentType.equals("image/pjpeg"))) {
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage(PixlrConstants.ERROR_MSG_NOT_ALLOWED_FORMAT));
}
}
return errors;
}
示例6: validate
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (iExternalId ==null || iExternalId.trim().length()==0)
errors.add("externalId", new ActionMessage("errors.required", ""));
else if (!"Update".equals(getOp()) && User.findByExternalId(getExternalId())!=null) {
errors.add("externalId", new ActionMessage("errors.exists", iExternalId));
}
if (iName==null || iName.trim().length()==0)
errors.add("name", new ActionMessage("errors.required", ""));
else {
try {
User user = User.findByUserName(iName);
if (user!=null && !user.getExternalUniqueId().equals(iExternalId))
errors.add("name", new ActionMessage("errors.exists", iName));
} catch (Exception e) {
errors.add("name", new ActionMessage("errors.generic", e.getMessage()));
}
}
if (iPassword==null || iPassword.trim().length()==0)
errors.add("password", new ActionMessage("errors.required", ""));
return errors;
}
示例7: addGenericError
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
/**
* Creates two ActionErrors signifying a Generic error, one for the top of
* page message, and one for the error message that is attached to a specific
* field.
*
* @param errors error list to which we add
* @param msg error msg content
* @param xpath The feature to be added to the GenericError attribute
*/
public static void addGenericError(SchemEditActionErrors errors,
String xpath,
String msg) {
prtln("addGenericError()");
//debegging messages
prtln("\txpath: " + xpath);
prtln("\tmsg: " + msg);
String encodedPath = XPathUtils.encodeXPath(xpath);
String id = xpath2Id(xpath);
String fieldProperty = "valueOf(" + encodedPath + ")";
String msgKey = "generic.field.error";
errors.add(fieldProperty,
new ActionMessage(msgKey, msg));
errors.add("pageErrors",
new ActionMessage(msgKey + ".link", msg, id));
}
示例8: validate
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(name==null || name.trim().length()==0)
errors.add("name", new ActionMessage("errors.required", ""));
else {
if ("Save".equals(op)) {
SolverParameterGroup gr = SolverParameterGroup.findByName(name);
if (gr!=null)
errors.add("name", new ActionMessage("errors.exists", name));
}
}
if(description==null || description.trim().length()==0)
errors.add("description", new ActionMessage("errors.required", ""));
return errors;
}
示例9: validate
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(name==null || name.trim().length()==0)
errors.add("name", new ActionMessage("errors.required", ""));
else {
if ("Save".equals(op)) {
SolverParameterDef def = SolverParameterDef.findByNameGroup(name, group);
if (def!=null)
errors.add("name", new ActionMessage("errors.exists", name));
}
}
if(group==null || group.trim().length()==0)
errors.add("group", new ActionMessage("errors.required", ""));
if(type==null || type.trim().length()==0)
errors.add("type", new ActionMessage("errors.required", ""));
if(description==null || description.trim().length()==0)
errors.add("description", new ActionMessage("errors.required", ""));
return errors;
}
示例10: addEntityError
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
/**
* Creates two ActionErrors, one for the top of page message, and one for the
* error message that is attached to a specific field.
*
* @param errors ActionErrors object to which the new errors are added
* @param field The InputField containing an error
* @param errorMsg The feature to be added to the EntityError attribute
*/
public static void addEntityError(SchemEditActionErrors errors, InputField field, String errorMsg) {
prtln("addEntityError()");
String elementName = field.getFieldName();
// String pathArg = XPathUtils.encodeXPath(field.getXPath());
String fieldProperty = field.getParamName();
String msgKey = "entity.error";
String id = xpath2Id(field.getXPath());
//debegging messages
prtln("\txpath (field.xpath): " + field.getXPath());
// prtln ("\tpathArg (encoded xpath): " + pathArg);
prtln("\tid: " + id);
prtln("\tfieldProperty (field.paramName): " + fieldProperty);
prtln("\t errors class: " + errors.getClass().getName());
errors.add(fieldProperty,
new ActionMessage(msgKey, errorMsg));
errors.add("entityErrors",
// new ActionMessage(msgKey + ".link", elementName, errorMsg, pathArg));
new ActionMessage(msgKey + ".link", elementName, id));
}
示例11: validate
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (iOrgName==null || iOrgName.length()==0) {
errors.add("orgName", new ActionMessage("errors.generic", "Please enter the name of the organization."));
} else {
for (Iterator i=SponsoringOrganization.findAll().iterator(); i.hasNext();) {
SponsoringOrganization so2 = (SponsoringOrganization) i.next();
if (iOrgName.compareToIgnoreCase(so2.getName())==0) {
if (iId != null) {
if (iId.compareTo(so2.getUniqueId())!=0) {
errors.add("orgNameExists", new ActionMessage("errors.generic", "Another organization with this name already exists."));
break;
}
} else {
errors.add("orgNameExists", new ActionMessage("errors.generic", "Another organization with this name already exists."));
break;
}
}
}
}
return errors;
}
示例12: validateSurveyItem
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
/**
* Vaidate survey item regards to their type (url/file/learning object/website zip file)
*
* @param itemForm
* @param instructionList
* @return
*/
private ActionErrors validateSurveyItem(QuestionForm itemForm, List<String> instructionList) {
ActionErrors errors = new ActionErrors();
if (StringUtils.isBlank(itemForm.getQuestion().getDescription())) {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(SurveyConstants.ERROR_MSG_DESC_BLANK));
}
short type = getQuestionType(itemForm);
if (type != SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) {
if (instructionList == null || instructionList.size() < 2) {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(SurveyConstants.ERROR_MSG_LESS_OPTIONS));
}
}
return errors;
}
示例13: validateChildClassExistence
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
private void validateChildClassExistence(ActionErrors errors){
for(int index = 0 ; index < this.getClassIds().size(); index++){
if (Boolean.valueOf((String) this.getMustHaveChildClasses().get(index)).booleanValue()){
String classId = (String) this.getClassIds().get(index);
if ((index + 1) == this.getClassIds().size()){
errors.add("mustHaveChildClasses",
new ActionMessage("errors.generic", MSG.errorClassMustHaveChildClasses((String) this.getClassLabels().get(index))));
this.getClassHasErrors().set(index, new Boolean(true));
} else {
String parentOfNextClass = (String) this.getParentClassIds().get(index + 1);
if (parentOfNextClass == null || !parentOfNextClass.equals(classId)){
errors.add("mustHaveChildClasses",
new ActionMessage("errors.generic", MSG.errorClassMustHaveChildClasses((String) this.getClassLabels().get(index))));
this.getClassHasErrors().set(index, new Boolean(true));
}
}
}
}
}
示例14: validateAnswers
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
private void validateAnswers(HttpServletRequest request, AnswerDTO question, ActionErrors errors,
SurveyAnswer answer) {
boolean isAnswerEmpty = ((answer.getChoices() == null) && StringUtils.isBlank(answer.getAnswerText()));
// for mandatory questions, answer can not be null.
if (!question.isOptional() && isAnswerEmpty) {
errors.add(SurveyConstants.ERROR_MSG_KEY + question.getUid(),
new ActionMessage(SurveyConstants.ERROR_MSG_MANDATORY_QUESTION));
}
if ((question.getType() == SurveyConstants.QUESTION_TYPE_SINGLE_CHOICE) && question.isAppendText()
&& !isAnswerEmpty) {
// for single choice, user only can choose one option or open text (if it has)
if (!StringUtils.isBlank(answer.getAnswerChoices()) && !StringUtils.isBlank(answer.getAnswerText())) {
errors.add(SurveyConstants.ERROR_MSG_KEY + question.getUid(),
new ActionMessage(SurveyConstants.ERROR_MSG_SINGLE_CHOICE));
}
}
}
示例15: validate
import org.apache.struts.action.ActionMessage; //導入依賴的package包/類
/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (op.equals(MSG.actionAddCourseToCrossList())) {
// Check Added Course
if (this.addCourseOfferingId==null || this.addCourseOfferingId.intValue()<=0) {
errors.add("addCourseOfferingId", new ActionMessage("errors.generic", MSG.errorRequiredCourseOffering()));
}
}
if (op.equals(MSG.actionUpdateCrossLists())) {
// Check controlling course
if (this.ctrlCrsOfferingId==null || this.ctrlCrsOfferingId.intValue()<=0) {
errors.add("ctrlCrsOfferingId", new ActionMessage("errors.generic", MSG.errorRequiredControllingCourse()));
}
}
return errors;
}