这是使用带有参数的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 的值。我做错了什么?