0

这是使用带有参数的richfaces jsFunction 的简短示例。

<r:jsFunction name="addTag" action="#{bean.method}">
   <r:param name="param" assignTo="#{bean.tagId}"/>
</r:jsFunction>

然后你可以使用来自 javascript addTag('1') 并且参数将被存储到 bean 中。

我需要以编程方式创建 jsFunction 和 ading 参数来完成相同的功能。这是我使用但不起作用的代码:

UIAjaxFunction jsFunctionAddTag = new UIAjaxFunction();
jsFunctionAddTag.setName("addTag");
FacesContext fc = FacesContext.getCurrentInstance();
ExpressionFactory ef = fc.getApplication().getExpressionFactory();
MethodExpression me = ef.createMethodExpression(fc.getELContext(), "#{bean.method}", 
                      null, new Class[]{});
jsFunctionAddTag.setActionExpression(me);
UIParameter param = new UIParameter();
param.setName("param");
param.setAssignToExpression(ef.createValueExpression(fc.getELContext(), 
                            "#{bean.tagId}", String.class));
jsFunctionAddTag.getChildren().add(param);

执行该方法时,未设置 tagId 的值。我做错了什么?

4

1 回答 1

0

作为服务器端的解决方法,可以从 ExternalContext 获取参数:

FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String paramValue = (String)map.get("paramName");
于 2014-10-02T20:30:22.887 回答