java - Ajax 调用上的渲染不起作用

标签 java jsf-2

在我的应用程序中,我有以下代码:

<h:form>
    <h:outputLabel for="type" style="font-weight: bold" value="*Type: " />
    <h:selectOneMenu label="type" id="type" binding="#{type}">
        <f:ajax execute="type" render="text article video" />
        <f:selectItem itemValue="article" itemLabel="Article" />
        <f:selectItem itemValue="video"   itemLabel="Video" />
    </h:selectOneMenu>
    <p:message for="type" />

    <h:outputText id="text" value="#{type.value}" />

    <h:panelGrid id="article" rendered="#{type.value == 'article'}" >
        ...
    </h:panelGrid>

    <h:panelGrid id="video" rendered="#{type.value == 'video'}" >
        ...
    </h:panelGrid>
</h:form>

当我从菜单中选择一个选项时,我确信 Ajax 调用已被触发,因为 <h:outputText>渲染为type.value正确。然而,<h:panelGrid> 都没有。已渲染。

如果您能告诉我应该如何解决这个问题,我将不胜感激。

最诚挚的问候,

詹姆斯·特兰

最佳答案

JavaScript/Ajax 无法更新未由 JSF 呈现的 HTML 元素。将其包装在始终渲染的组件中,然后更新它。

<h:form>
    <h:outputLabel for="type" style="font-weight: bold" value="*Type: " />
    <h:selectOneMenu label="type" id="type" binding="#{type}">
        <f:ajax execute="type" render="text grids" />
        <f:selectItem itemValue="article" itemLabel="Article" />
        <f:selectItem itemValue="video"   itemLabel="Video" />
    </h:selectOneMenu>
    <p:message for="type" />

    <h:outputText id="text" value="#{type.value}" />

    <h:panelGroup id="grids">
        <h:panelGrid id="article" rendered="#{type.value == 'article'}" >
            ...
        </h:panelGrid>

        <h:panelGrid id="video" rendered="#{type.value == 'video'}" >
            ...
        </h:panelGrid>
    </h:panelGroup>
</h:form>

关于java - Ajax 调用上的渲染不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10755398/

相关文章:

java - 动态内存处理 Java 与 C++

java - ANTLR解析后生成字符串列表的哈希集

jsf - 基于bean属性动态渲染组件

java - 已用堆大小持续增加

java - 在jsf 2.2中上传文件

java - 将顺序 Java 转换为并发 Java 代码

java - 发送和接收短信以验证手机号码

java - 更改按钮文本并在android studio中执行相应的onClick函数

java - 减少 If 语句中的代码重复

java - JSF 2.0 问题(faces-config)