我正在尝试Ajax从我的 . xhtml页面到我的支持ManagedBean功能,如下所示:
.xhtml 表单代码
<h:form id = "jsfform">
<h:commandButton id="button" action="#{cellBean.children()}">
<f:ajax render=":results" />
</h:commandButton> </h:form>
<h:panelGroup id="results">
<th>Child cells</th>
<td>
<ui:repeat value="#{cellBean.childCells}" var="cell">
<tr>#{cell.cellName}</tr>
</ui:repeat>
</td>
</h:panelGroup>
托管bean的功能代码
public List<Cell> children(){
this.childCells.add(new Cell("cell1"));
return this.childCells;
}
上面的代码工作正常,因为每次我触发 commandButton 时,都会将一个新的“ Cell”对象添加到列表中并在我的表单中异步呈现。
我使用棘手的方式触发commandButtonfrom javascript(在我看来这不是最好的选择)
document.getElementById('jsfform:button').onclick();
我现在想要实现的是做一些类似的事情,但cellBean.children函数有参数(fe 一个字符串列表),将它传递给支持 bean 函数并做一些事情,我该怎么办?显然我不能像以前那样触发命令按钮,因为我不能传递这样的参数
例子:
<h:form id = "jsfform">
<h:commandButton id="button" action="#{cellBean.children(a_list)}">
<f:ajax render=":results" />
</h:commandButton> </h:form>
<h:panelGroup id="results">
<th>Child cells</th>
<td>
<ui:repeat value="#{cellBean.childCells}" var="cell">
<tr>#{cell.cellName}</tr>
</ui:repeat>
</td>
</h:panelGroup>
public List<Cell> children(List<String> alist){
this.childCells.add(new Cell("cell1"));
return this.childCells;
}
提前致谢。
蝴蝶不菲
相关分类