0
在Struts應用程序中,一些控制器將Javascript代碼寫入HTTP響應(此JS代碼將在提交結束時執行)。你認爲這是一種糟糕的做法還是可以接受的?設置一個屬性並將JS代碼移動到視圖會更好嗎?將Javascript代碼寫入控制器的HTTP響應
@UserInterfaceEvent
public void aceptar_onClick(FormActionContext ctx) {
IGenerateDocListOutputBF bproxy = ProxyFactory.newBusinessProxy(getBusinessComponent(), IGenerateDocListOutputBF.class);
GenerateDocListOutputForm form = (GenerateDocListOutputForm) ctx.form();
String mode = form.getDetailMode();
removeErrors(ctx);
GemaBrowseControl browse = (GemaBrowseControl) ctx.session().getAttribute("outputs");
SelectedData data = browse.getAllSelectedData(ctx, true);
try {
bproxy.generateOutputs(data.getSelectedDboids(), form.getDboid(), false);
if (GemaAppErrorMgr.currentScopeHasErrors()) {
ctx.request().setAttribute(DetailRequest.MODE, mode);
showErrorPopUp(ctx);
} else {
String javascript = "<script>window.opener.refreshDivDocsRelated(); window.close();</script>";
ctx.response().getOutputStream().print(javascript);
ctx.forwardToResponse();
}
} catch (Exception e) {
handleException(e, ctx.request());
}
}
是的,它可以通過Ajax調用完成,但需要大量的重構(這是一箇舊的應用程序)。 –