【发布时间】:2013-01-16 11:46:07
【问题描述】:
我正在尝试找到与此 XHTML 代码等效的代码:
<h:selectBooleanCheckbox value="#{sandboxBean.selected}" >
<f:ajax listener="#{sandboxBean.handleToggle}" render="outputText" />
</h:selectBooleanCheckbox>
<br /><br />
<h:outputText value="#{sandboxBean.selected}" id="outputText"/>
对于整个复选框必须由支持 bean 动态创建的情况。我已经设法通过这段代码获得了一些 Ajax 优点:
checkbox = new HtmlSelectBooleanCheckbox();
checkbox.setId(makeCheckboxId());
AjaxBehavior valueChangeAction = (AjaxBehavior)FacesContext.getCurrentInstance().getApplication().createBehavior(AjaxBehavior.BEHAVIOR_ID);
valueChangeAction.addAjaxBehaviorListener(new AjaxBehaviorListener() {
@Override
public void processAjaxBehavior(AjaxBehaviorEvent event) throws AbortProcessingException {
System.out.println("Ajax behavior called");
}
});
checkbox.addClientBehavior("valueChange", valueChangeAction);
但我不知道如何让 Ajax 调用来执行我的 handleToggle 方法,也不知道如何让它轻松访问我想要呈现的 outputText 元素(在这个精简的示例中) .
此外,这似乎出乎意料地复杂:这一切都源于对具有未知列数的表的需求。我是否可能只是通过在代码中创建整个表格从根本上错误的角度来解决这个问题?
【问题讨论】: