我只是想更改来自表单的值。我已经钩住一个Struts Action
,以更改该值,然后继续使用默认的processAction
。但是它没有应用更改。
这是我的摘机代码:
public class EditRecordDisplayPortletAction extends BaseStrutsPortletAction {
...
public void processAction(
StrutsPortletAction originalStrutsPortletAction,
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse)
throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
...
//Stuff that is working here ...
...
//Here I change the value that is comming from the form that should be used later:
DynamicActionRequest dynamicActionRequest = null;
Map<String, String[]> params = new HashMap();
String observationInputKey = getObservationInputKey();
params.put(observationInputKey, new String[]{"Here goes some text I have calculated in the hook."});
dynamicActionRequest = new DynamicActionRequest(actionRequest, params, false);
//Continues with the normal operation, but it's not using the new values:
originalStrutsPortletAction.processAction(
originalStrutsPortletAction, portletConfig, dynamicActionRequest,
actionResponse);
}
...
由于我无法更改DynamicActionRequest
,因此我正在使用__actionRequest__
。寻找更多信息,这里有人解释类似的东西,应该起作用:
Wrap actionRequest with a DynamicActionRequest
答案 0 :(得分:0)
按照您链接的论坛帖子的示例,您可以简化创建DynamicActionRequest的过程。请尝试:
public void processAction(
StrutsPortletAction originalStrutsPortletAction,
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse)
throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
...
//Stuff that is working here ...
...
DynamicActionRequest dynamicActionRequest = new DynamicActionRequest(actionRequest);
String observationInputKey = getObservationInputKey();
dynamicActionRequest.setParameter(observationInputKey, "Here goes some text I have calculated in the hook.");
//Continues with the normal operation, but it's not using the new values:
originalStrutsPortletAction.processAction(
originalStrutsPortletAction, portletConfig, dynamicActionRequest,
actionResponse);
}
...
诚然,javadoc for DynamicActionRequest所包含的方法名称不多,但您要为构造函数指定布尔参数inherit
作为false
。那可能是您唯一的问题。