Primefaces 6.2 TabView onTabChange表单数据为空

问题描述 投票:1回答:2

我不确定我是否犯了一个愚蠢的错误,但在一个非常简单的情况下,这对我来说并不适用:在我的tabview / tabs中,当我从一个选项卡切换到另一个选项卡时,我想保存在表单中输入的数据。 “提交”按钮在每个选项卡上都可以正常工作,但tabchange事件会将我的所有表单数据显示为null。我已经尝试过@all,@ form,@ this,似乎没什么用。与更新选项相同。

这是XHTML:

    <h:form id="form">
    <p:growl id="msgs" showDetail="true" keepAlive="5000"  />
    <p:tabView id="tView" dynamic="true" cache="false" >
        <p:ajax event="tabChange" listener="#{deleteMe.onTabChange}" update=":form:msgs" />
        <p:tab title="MyTitle I" id="tab1">
            <p:fieldset legend="Personal Information" toggleable="false" >
                <h:panelGrid columns="2" cellpadding="10"> 
                    Value 1: <p:inputText value="#{deleteMe.thingOne}"></p:inputText>
                    Value 2: <p:inputText value="#{deleteMe.thingTwo}"></p:inputText>
                    <p:commandButton value="Submit" id="ajax" update=":form:msgs" action="#{deleteMe.onSubmit}" />
                </h:panelGrid>
            </p:fieldset>
        </p:tab>
        <p:tab title="MyTitle II" id="tab2">
            <p:fieldset legend="Social Information" toggleable="false">
                <h:panelGrid columns="2" cellpadding="10">
                    <p:inputText value="#{deleteMe.thingThree}"></p:inputText>
                    <p:commandButton value="Submit" id="ajax2" update=":form:msgs" action="#{deleteMe.onSubmit}" />
                </h:panelGrid>
          </p:fieldset>  
        </p:tab>
    </p:tabView>
</h:form>   

这是我的支持bean:

`

import javax.annotation.PostConstruct;
import javax.inject.Named;

import org.primefaces.event.TabChangeEvent;
import org.springframework.context.annotation.Scope;


@Named(value = "deleteMe")
@Scope("view")
public class DeleteBean implements Serializable {
    private static final long serialVersionUID = 47L;

    private String thingOne;
    private String thingTwo;
    private String thingThree;

    @PostConstruct
    public void initialize() {

    }   

    public void onTabChange(TabChangeEvent event) {
        System.out.println("Saving draft, current index: "+ event.getTab().getTitle());
        System.out.println(thingOne);
        System.out.println(thingTwo);
        saveDraft();
    }

    public void onSubmit() {
        System.out.println(thingOne);
        System.out.println(thingTwo);
        System.out.println(thingThree);
        saveDraft();
    }

    public void saveDraft() {
        System.out.println("This is thing 1 value: "+thingOne);
        System.out.println("This is thing 2 value: "+thingTwo);
        System.out.println("This is thing 2 value: "+thingThree);
    }


    public String getThingOne() {
        return thingOne;
    }

    public void setThingOne(String thingOne) {
        this.thingOne = thingOne;
    }

    public String getThingTwo() {
        return thingTwo;
    }

    public void setThingTwo(String thingTwo) {
        this.thingTwo = thingTwo;
    }

    public String getThingThree() {
        return thingThree;
    }

    public void setThingThree(String thingThree) {
        this.thingThree = thingThree;
    }
}

`

在tabchange事件上,它触发方法,但值都为null。

SystemOut     O This is thing 1 value: null
SystemOut     O This is thing 2 value: null
SystemOut     O This is thing 2 value: null

如果我犯了一些愚蠢的错误,你能指出吗?谢谢。

jsf primefaces jsf-2.2
2个回答
0
投票

正确的答案是在p:ajax命令中使用skipChildren =“false”。

https://github.com/primefaces/primefaces/issues/2525

 <p:ajax event="tabChange" 
         skipChildren="false"
         listener="#{deleteMe.onTabChange}" 
         update=":form:msgs" />

-2
投票

看到了解决方法,但我不确定它为什么这样工作:

我必须在tabView上添加带有tabchange监听器的远程命令。

<p:remoteCommand name="onTabChangeProcess" process="tView, @this"/> 
    <p:tabView activeIndex="#{deleteMe.activeIndex}" id="tView" onTabChange="onTabChangeProcess()">
            <p:ajax event="tabChange" listener="#{deleteMe.onTabChange}" update="tView" process="tView"/>

这使表单按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.