java - PrimeFaces 组件未根据需要更新(生成嵌套按钮)

标签 java jsf primefaces commandbutton

我的 JSF 页面上有 commandButton 组件:

initial button

<p:commandButton id="period"
    value="#{myBean.isMonthly == false ? 'Yearly' : 'Monthly'}"
    action="#{myBean.doSomeOtherStuff()}"
    update="period myDataTable">
</p:commandButton>

我正在尝试通过单击上面的按钮来更新dataTable。 当我单击它时,dataTable 根据需要进行更新,而 commandButton 的行为很奇怪,导致显示如下:

button after update

有人可以帮助我了解这种奇怪情况的原因,并告诉我解决方案(如果可能)吗?

注释:

  • JSF 实现和版本: Mojarra (javax.faces-2.1.11.jar)
  • 查看技术: Facelets (XHTML)
  • 复制、粘贴和运行示例! (SSCCE)如下:

FilterBean.java:

package com.turkcell.mdealer.bean.impl;

import org.springframework.stereotype.Component;

@Component
public class FilterBean {
    private boolean monthly = true;

    public String applyPeriod(String caller) {
        monthly = !monthly;
        return caller;
    }

    public boolean isMonthly() {
        return monthly;
    }

    public void setMonthly(boolean monthly) {
        this.monthly = monthly;
    }
}

sample.xhtml:

<f:view xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:turkcell="http://turkcell.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
    xmlns:of="http://omnifaces.org/functions"
    xmlns:pm="http://primefaces.org/mobile" contentType="text/html"
    renderKitId="PRIMEFACES_MOBILE">
    <pm:page title="Bayi Raporlari">
        <pm:view id="FaturasizAktivasyon" swatch="c">
            <p:outputPanel id="FaturasizPanel">
                <h:form id="FaturasizForm">
                    <pm:content>
                        <p:commandButton id="period"
                            value="#{filterBean.monthly == false ? 'Yearly' : 'Monthly'}"
                            action="#{filterBean.applyPeriod('sample')}" update="period">
                        </p:commandButton>
                    </pm:content>
                </h:form>
            </p:outputPanel>
        </pm:view>
    </pm:page>
</f:view>

库的总体 View :

enter image description here

最佳答案

我不知道这种奇怪行为的原因

但是,您可以使用两个条件渲染按钮来达到相同的效果:

<p:panelGroup>
    <p:commandButton value="Monthly"
        action="#{myBean.doSomeOtherStuff()}"
        update="myDataTable @parent" rendered="#{myBean.isMonthly}" />
    <p:commandButton value="Yearly"
        action="#{myBean.doSomeOtherStuff()}"
        update="myDataTable @parent" rendered="#{not myBean.isMonthly}" />
</p:panelGroup>

关于java - PrimeFaces 组件未根据需要更新(生成嵌套按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15676571/

相关文章:

javascript - HTTP 请求中的 Angular2 Set-Cookie JSESSIONID

jsf - p :push not working with atmosphere spring boot

java - 当我在导航栏中单击某个项目时如何重定向到另一个页面

css - 禁止子元素从父元素继承样式

ajax - 使用 bean 方法的结果 <h :selectBooleanCheckbox/> 时出现 PropertyNotFoundException

java - 选择 JDBC 驱动程序

java - Lucene + 经典查询搜索语法与使用 AND 相同

java - HQL 选择结果范围

javascript - f :ajax by onchange event

java - 在 JSF 页面中硬绑定(bind)托管 bean 以检测编译中的名称问题