我有一個Action類有4個操作方法。 所有四個動作操作方法都使用json結果。Struts2行動被調用兩次,如果結果類型是json
通過日誌語句和調試,我已驗證如果我調用操作方法1,操作方法2和3也被調用。但不是4.最後,再次調用操作方法1並生成json結果
如果我將Action方法1的結果類型更改爲帶有jsp位置的缺省調度程序,則只調用操作方法1。 (這是我想要的json結果的行爲) 希望是有道理的。
任何人有任何想法? 這裏提問這個問題https://stackoverflow.com/questions/3767698/struts2-if-result-type-json-and-method-defined-then-all-methods-get-invoked
但是沒有答案。 如果您需要更多信息,請讓我知道。
@ResultPath("/WEB-INF/jsp/dta/")
public class GroupEntityAction extends BaseAction {
/**
*
*/
private static final long serialVersionUID = 6750675222824235086L;
private static Logger log = Logger.getLogger(GroupEntityAction.class);
private List<EntityBusiness> theUnusedEntityBusinessList;
private String assignedEntities[];
private long groupId;
private long businessId;
private String parentMe;
private long rptYear;
private String ssoId;
private String isSubmitted;
private String delimGoLiveEmails;
private List<String> theEmailList;
@Action(value = "ajaxGetAvailableEntityList",
results = { @Result(name = "success", type = "json") }
,
interceptorRefs = { @InterceptorRef("dtaStack"),
@InterceptorRef(value = "dtaStack", params = { "appInterceptor.allowedRoles", "ADMIN" }) }
)
public String getEntityListsByBusiness() throws Exception {
if (rptYear == 0) {
return SUCCESS;
}
LookupService theSvc = new LookupService();
if (businessId != 0) {
setTheUnusedEntityBusinessList(theSvc.getAvailableEntityListBizExceptIds(rptYear, businessId, ssoId, assignedEntities));
} else {
setTheUnusedEntityBusinessList(theSvc.getAvailableEntityListParentMeExceptIds(rptYear, parentMe, ssoId, assignedEntities));
}
log.debug(theUnusedEntityBusinessList.size());
return SUCCESS;
}
@Action(value = "ajaxToggleGroupBusinessSubmitted",
results = { @Result(name = "success", type = "json") }
,
interceptorRefs = { @InterceptorRef("dtaStack") }
)
public String toggleGroupBusinessReview() {
try {
new ProformaService().toggleIsSubmitted(getCurrentUser().getSsoId(), groupId, rptYear, businessId);
} catch (SQLException e) {
log.error(e.getMessage());
return ERROR;
}
return SUCCESS;
}
@Action(value = "ajaxGetGoLiveEmailList",
results = { @Result(type = "json") }
,
interceptorRefs = { @InterceptorRef("dtaStack"),
@InterceptorRef(value = "dtaStack", params = { "appInterceptor.allowedRoles", "ADMIN" }) }
)
public String getGoLiveEmailList() {
try {
List<TaxUser> theUserList = new SecurityService().getAll();
List<String> theEmailList = new ArrayList<String>();
for (TaxUser theUser : theUserList) {
if ((!theUser.getRoles().contains("ADMIN")) && (theUser.getIsActive().equalsIgnoreCase("Y"))) {
if (!theEmailList.contains(theUser.getEmail())) {
theEmailList.add(theUser.getEmail());
}
}
}
setDelimGoLiveEmails(StringUtils.join(theEmailList.toArray(), "|"));
setTheEmailList(theEmailList);
} catch (SQLException e) {
log.error(e.getMessage());
return ERROR;
}
return SUCCESS;
}
@Action(value = "ajaxGetChaserEmailList",
results = { @Result(name = "success", type = "json") }
,
interceptorRefs = { @InterceptorRef("dtaStack"),
@InterceptorRef(value = "dtaStack", params = { "appInterceptor.allowedRoles", "ADMIN" }) }
)
public String getChaserEmailList() {
try {
List<String> theEmailList = new LookupService().getChaserEmailList();
setDelimGoLiveEmails(StringUtils.join(theEmailList.toArray(), "|"));
setTheEmailList(theEmailList);
} catch (SQLException e) {
log.error(e.getMessage());
return ERROR;
}
return SUCCESS;
}
public void setTheUnusedEntityBusinessList(
List<EntityBusiness> theUnusedEntityBusinessList) {
this.theUnusedEntityBusinessList = theUnusedEntityBusinessList;
}
public List<EntityBusiness> getTheUnusedEntityBusinessList() {
return theUnusedEntityBusinessList;
}
public void setAssignedEntities(String assignedEntities[]) {
this.assignedEntities = assignedEntities;
}
public String[] getAssignedEntities() {
return assignedEntities;
}
public void setGroupId(long groupId) {
this.groupId = groupId;
}
public long getGroupId() {
return groupId;
}
public void setBusinessId(long businessId) {
this.businessId = businessId;
}
public long getBusinessId() {
return businessId;
}
public void setParentMe(String parentMe) {
this.parentMe = parentMe;
}
public String getParentMe() {
return parentMe;
}
public void setRptYear(long rptYear) {
this.rptYear = rptYear;
}
public long getRptYear() {
return rptYear;
}
public void setSsoId(String ssoId) {
this.ssoId = ssoId;
}
public String getSsoId() {
return ssoId;
}
public void setIsSubmitted(String isSubmitted) {
this.isSubmitted = isSubmitted;
}
public String getIsSubmitted() {
return isSubmitted;
}
public void setDelimGoLiveEmails(String delimGoLiveEmails) {
this.delimGoLiveEmails = delimGoLiveEmails;
}
public String getDelimGoLiveEmails() {
return delimGoLiveEmails;
}
public void setTheEmailList(List<String> theEmailList) {
this.theEmailList = theEmailList;
}
public List<String> getTheEmailList() {
return theEmailList;
}
}
在這個動作類,我試圖調用ajaxGetGoLiveEmailList
,和我所得到的是ajaxGetGoLiveEmailList
首先調用,然後ajaxGetChaserEmailList
,然後ajaxGetAvailableEntityList
,然後ajaxGetGoLiveEmailList
被再次調用。跳過ajaxToggleGroupBusinessSubmitted
。
如果我改變的ajaxGetGoLiveEmailList
結果註釋
results={@Result(location="something.jsp")
,只有ajaxGetGoLiveEmailList
被調用。
當我查看配置瀏覽器時,所有的動作映射都配置正確,指向正確的方法調用。
請張貼您的操作代碼或顯示問題的測試用例。 – 2011-05-19 16:29:06