1

p:tabView複数のページを異なるタブに表示するために 使用しています。

私が開いているタブの1つでp:dialog( javascript で試してみましたwindow)、ダイアログまたはウィンドウが開くとすぐに、p:tabViewコンポーネント全体がリセットされます。

一部のタブの ManagedBeans は、@ViewScopedスコープに関連する大きな問題になりました。

次のコードでは、できるだけ少ないコードでシナリオを再作成しています (私の ManagedBeans と Xhtml は、次のコードよりも大きくなっています)。

同じ問題に直面している場合は、この問題を解決するための解決策または回避策を提供してください。

index.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その呼び出しにあるので@PostConstructConstructorsもう一度。の Clisntside JavaScript 関数
を使用してウィンドウを開いた後、選択したタブと同じタブを作成します。p:tabView

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