简体   繁体   English

f:ajax渲染表单组件

[英]f:ajax render form component

I want to render a single component (h:selectManyCheckbox) inside a form based on a check-box that I select or not. 我想基于我选择或不选择的复选框在表单内呈现单个组件(h:selectManyCheckbox)

<h:form> 
    <h:selectBooleanCheckbox value="#{bean.var}">
        <f:ajax event="click" render="employeeCheckboxes" />
    </h:selectBooleanCheckbox>

    <h:selectManyCheckbox 
        id="employeeCheckboxes"
        value="#{bean.checkboxes}"
        rendered="#{var}">
    </h:selectManyCheckbox>
</h:form>

However, the component isn't re-rendered on selecting or deselecting the check-box. 但是,在选择或取消选中复选框时不会重新渲染组件。 I can however re-render the whole form but I don't want that. 但是,我可以重新渲染整个表格,但是我不想要那样。

You can't reference a component in <f:ajax render> which is in first place never rendered in HTML output. 您不能在<f:ajax render>引用一个组件,而该组件首先不会在HTML输出中呈现。 The <f:ajax render> uses under the covers JavaScript document.getElementById() to find the HTML element in order to update it with the new HTML structure from the ajax response. <f:ajax render>使用JavaScript document.getElementById()来查找HTML元素,以便使用ajax响应中的新HTML结构对其进行更新。 However, if a JSF component is in first place never rendered in HTML output, then JavaScript can't find it anywhere either. 但是,如果最初没有在HTML输出中呈现JSF组件,那么JavaScript也无法在任何地方找到它。

You need to wrap it in another component which is always rendered. 您需要将其包装在始终呈现的另一个组件中。

<h:form> 
    <h:selectBooleanCheckbox value="#{bean.var}">
        <f:ajax render="employeeCheckboxesGroup" />
    </h:selectBooleanCheckbox>

    <h:panelGroup id="employeeCheckboxesGroup">
        <h:selectManyCheckbox 
            id="employeeCheckboxes"
            value="#{bean.checkboxes}"
            rendered="#{bean.var}">
        </h:selectManyCheckbox>
    </h:panelGroup>
</h:form>

(note that I removed event="click" as it's the default already) (请注意,我已经删除了event="click"因为它已经是默认设置了)

See also: 也可以看看:

Hi i think you missed managed bean name in 嗨,我认为您错过了托管Bean名称

rendered attribute 渲染的属性

of checkbox tag. 复选框标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM