1

p:tabView用来在不同的选项卡中显示多个页面。

在我打开的一个选项卡上p:dialog(我什至尝试过使用 javascript window),一旦对话框或窗口打开,整个p:tabView组件就会被重置。

某些选项卡中的 ManagedBeans@ViewScoped因此成为与范围相关的巨大问题。

在下面的代码中,我只是在尽可能少的代码中重新创建场景(我的 ManagedBeans 和 Xhtml 比下面的代码大)。

如果您遇到同样的问题,请提供任何解决方案或解决方法来解决此问题。

索引.xhtml

<h:body>
    <h:form>
        <p:tabView dynamic="true"> 
            <p:tab title="Tab1">
                <ui:include src="tab1.xhtml"/>
            </p:tab>

            <p:tab title="Tab2">
                <ui:include src="tab2.xhtml"/>
            </p:tab>
        </p:tabView>
    </h:form>
</h:body>

tab1.xhtml

<h:body>
    <h:form>
        <h:outputLabel value="#{tab1Bean.tab1BeanString}"/>
    </h:form>
</h:body>

tab2.xhtml

<h:body>
    <h:form>
        <h:inputText value="#{tab2Bean.tab2BeanString}">
            <p:ajax event="keyup"/>
        </h:inputText>
        <p:button onclick="dlg.show()"/>
    </h:form>
    <p:dialog widgetVar="dlg" appendToBody="true">
        <ui:include src="popup.xhtml"/>
    </p:dialog>
</h:body>

popup.xhtml

<h:body>
    <h:form>
        <h:outputText value="#{tab2Bean.tab2BeanString}"/>
        <h:inputText value="#{tab2Bean.popupString}">
            <p:ajax event="keyup"/>
        </h:inputText>
    </h:form>
</h:body>

Tab1Bean.java

@ManagedBean
@ViewScoped
public class Tab1Bean implements Serializable{

    private String tab1BeanString="default String";

    @PostConstruct
    public void init(){
        System.out.println("Tab1 Bean PostConstruct");
    }

    public Tab1Bean() {
        System.out.println("Tab1 Bean Constructor");
    }

    public String getTab1BeanString() {
        return tab1BeanString;
    }

    public void setTab1BeanString(String tab1BeanString) {
        this.tab1BeanString = tab1BeanString;
    }

}

Tab2Bean.java

@ManagedBean
@SessionScoped
public class Tab2Bean implements Serializable {

    private String tab2BeanString;
    private String popupString;

    @PostConstruct
    public void init(){

        System.out.println("Tab2 Bean @PostConstruct");
    }

    public Tab2Bean() {
        System.out.println("Tab2 Bean Constructor");
    }


    public String getTab2BeanString() {
        return tab2BeanString;
    }
    public void setTab2BeanString(String tab2BeanString) {
        this.tab2BeanString = tab2BeanString;
    }

    public String getPopupString() {
        return popupString;
    }
    public void setPopupString(String popupString) {
        this.popupString = popupString;
    }
}

使用:Primefaces 3.5 和 Mojarra 2.1

4

1 回答 1

1

p:tabView组件没有重置,它只是导航到第一个选项卡。
由于您的 Tab1Bean 正在一遍又一遍地@ViewScope调用。使用Clisntside javascript 函数 打开窗口后创建与选定选项卡相同的选项卡:@PostConstructConstructors
p:tabView

(PrimeFaces.widget.TabView).select(index)
于 2013-09-10T14:58:00.260 回答