关于struts2中@validations对于方法的校验

在struts2中,我使用下面的方法请求。
通过Action!Method.action的方法实现了dispatchAction。现在的情况是action里的execute已经没有了。被若干个crud方法取代。

现在想使用@validations用来针对crud方法中的变量做校验.但是比如下面的action.
package com.tongcard.merchant.web.actions.privilege;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.struts2.config.Namespace;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.apache.struts2.dispatcher.ServletRedirectResult;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.Validation;
import com.opensymphony.xwork2.validator.annotations.Validations;
import com.opensymphony.xwork2.validator.annotations.ValidatorType;
import com.tongcard.merchant.web.helper.BaseAction;
import com.tongcard.merchant.web.helper.BusinessResult;
import com.tongcard.merchant.web.helper.PageHelperList;
import com.tongcard.merchant.web.manager.PrivilegeManager;
import com.tongcard.merchant.web.manager.impl.PrivilegeManagerImpl;
import com.tongcard.merchant.web.model.Role;
import com.tongcard.merchant.web.model.User;

@Namespace("/privilege")
@Results( {
		@Result(name = "success", value = "/privilege/roleSearch.jsp"),
		@Result(name = "input", value = "/privilege/roleNew.jsp", type = ServletRedirectResult.class),
		@Result(name = "modify", value = "/privilege/roleModify.jsp"),
		@Result(name = "login", value = "/login/login.jsp") })
public class RoleAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static int pageSize = 5;

	private int currentPage = 1;

	private PageHelperList pageHelper;

	private Role role;

	private List<String> pages;

	private String actions;

	private String info;

	private String roleId;

	private List<Role> roles;

	private PrivilegeManager privilegeManager;

	[color=red]@Validations(requiredStrings = { @RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "role.roleName", message = "角色名称不能为空") })[/color]
	public String create() {
		BusinessResult bres = null;
		role
				.setOrgCode(request.getSession().getAttribute("orgCode")
						.toString());
		bres = privilegeManager.newRole(role);
		info = bres.getInfo();
		return Action.INPUT;
	}
	
	// 分页查询得到当前管理员所在机构下的角色。
	public List<Role> buildRoleDivPageData(HashMap<String, String> map) {
		List<Role> roles = null;
		int count = privilegeManager.countRole(map.get("orgCode"));
		if (count == 0) {
			return null;
		}
		pageHelper = new PageHelperList(count, currentPage, pageSize);
		map.put("begin", pageHelper.getPageStartRow() + "");
		map.put("end", pageHelper.getPageEndRow() + "");
		roles = privilegeManager.searchRoleByPage(map);
		pages = new ArrayList<String>();
		for (int i = 0; i < pageHelper.getTotalPages(); i++) {
			pages.add(String.valueOf(i + 1));
		}
		return roles;
	}

	
	public String search() {
		HashMap<String, String> map = new HashMap<String, String>();
		User user = (User) (request.getSession().getAttribute("user"));
		if (null == user) {
			return "login";
		}
		map.put("orgCode", user.getOrgCode());
		roles = buildRoleDivPageData(map);
		return Action.SUCCESS;
	}

	public String show() {
		role = privilegeManager.searchSimpleRoleByRoleId(Long.valueOf(roleId));
		return "modify";
	}



	public String init() {
		return Action.INPUT;
	}

	// @Validations(requiredStrings = { @RequiredStringValidator(type
	// =ValidatorType.SIMPLE, fieldName = "role.roleName", message = "角色名称不能为空")
	// })
	public String update() {
		BusinessResult bres = null;
		bres = privilegeManager.modifyRole(role);
		info = bres.getInfo();
		request.setAttribute("role", role);
		return "modify";
	}

	// 得到全部当前管理员所在机构下的角色
	public List<Role> getRoles(String orgCode) {
		List<Role> list = null;
		list = privilegeManager.searchRolesByOrg(orgCode);
		return list;
	}

	public String getActions() {
		return actions;
	}

	public void setActions(String actions) {
		this.actions = actions;
	}

	public PrivilegeManager getPrivilegeManager() {
		return privilegeManager;
	}

	public void setPrivilegeManager(PrivilegeManagerImpl privilegeManager) {
		this.privilegeManager = privilegeManager;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public void setPrivilegeManager(PrivilegeManager privilegeManager) {
		this.privilegeManager = privilegeManager;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public List<String> getPages() {
		return pages;
	}

	public void setPages(List<String> pages) {
		this.pages = pages;
	}

	public static int getPageSize() {
		return pageSize;
	}

	public static void setPageSize(int pageSize) {
		RoleAction.pageSize = pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public PageHelperList getPageHelper() {
		return pageHelper;
	}

	public void setPageHelper(PageHelperList pageHelper) {
		this.pageHelper = pageHelper;
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
}

create方法上的红色字体表示create时的一个校验。但是当我执行另一个请求:role!search.action时,却会执行role!create.action方法。真的很奇怪。不知道是哪里配置的问题。

你可能感兴趣的:(apache,jsp,Web,struts,配置管理)