4

こんにちは、primefaces tabView は次のようになっています

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
    <h:head></h:head>
    <h:body>
        <p:messages />
        <h:form id="form">
            <p:tabView dynamic="true">
                <p:tab title="Tab">
                    <p:inputText required="true" value="value"></p:inputText>
                </p:tab>
                <p:tab title="Select">
                    <p:selectOneMenu value="#{dummyController.selectedValue}" id="select" required="true" requiredMessage="Select is required">
                        <f:selectItem itemValue="1" itemLabel="asd"></f:selectItem>
                        <f:selectItem itemValue="2" itemLabel="qwe"></f:selectItem>
                        <f:selectItem itemValue="3" itemLabel="zc"></f:selectItem>
                    </p:selectOneMenu>
                    <p:message for="select" />
                </p:tab>
                <p:tab title="Tab">
                    <p:inputText required="true" value="value"></p:inputText>
                </p:tab>
            </p:tabView>
            <h:commandButton action="#{dummyController.submit}" />
        </h:form>
    </h:body>
</ui:composition>

そしてコントローラーです

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class DummyController implements Serializable {

    private static final long serialVersionUID = 1L;
    private int selectedValue;

    public void submit() {

    }

public int getSelectedValue() {
    return selectedValue;
}

public void setSelectedValue(int selectedValue) {
    this.selectedValue = selectedValue;
}

}

奇妙な動作をしています。手順に従って再現してください。

  • 選択タブを開く
  • 他のタブを開く
  • [送信] を 2 回押します

最初に押すと何も起こらず、次に押すと選択に必要なメッセージがトリガーされますが、常に値があります

何か足りないものや解決策があれば教えてください

4

3 に答える 3

2

これに対する直接的な解決策はありません。これは、primefaces tabView のバグです。私はこの回避策を使用して作業しました

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
    <h:head></h:head>
    <h:body>
        <p:messages />
        <h:form id="form">
            <p:tabView dynamic="true" activeIndex="#{dummyController.activeindex}" >
                <p:tab title="Tab" id="tab1">
                    <p:inputText required="true" value="value"></p:inputText>
                </p:tab>
                <p:tab title="Select" id="selectTab">
                    <p:selectOneMenu disabled="#{dummyController.activeindex != 1}" value="#{dummyController.selectedValue}" id="select" required="true" requiredMessage="Select is required">
                        <f:selectItem itemValue="" itemLabel=""></f:selectItem>
                        <f:selectItem itemValue="1" itemLabel="asd"></f:selectItem>
                        <f:selectItem itemValue="2" itemLabel="qwe"></f:selectItem>
                        <f:selectItem itemValue="3" itemLabel="zc"></f:selectItem>
                    </p:selectOneMenu>
                    <p:message for="select" />
                </p:tab>
                <p:tab title="Tab" id="tab3">
                    <p:inputText required="true" value="value"></p:inputText>
                </p:tab>
            </p:tabView>
            <h:commandButton action="#{dummyController.submit}" />
        </h:form>
    </h:body>
</ui:composition>

そしてコントローラー:

package com.ibm.sa.kap.ui.controller;

import java.io.Serializable;

@ManagedBean
@ViewScoped
public class DummyController implements Serializable {

    private static final long serialVersionUID = 1L;

    private int selectedValue;

    private int activeindex;

    public void submit() {

    }

    public int getSelectedValue() {
        return selectedValue;
    }

    public void setSelectedValue(int selectedValue) {
        this.selectedValue = selectedValue;
    }

    public int getActiveindex() {
        return activeindex;
    }

    public void setActiveindex(int activeindex) {
        this.activeindex = activeindex;
    }

}

タブのインデックスに応じて条件付きで無効になっているため、タブビューが値をリセットするのを防ぐために、なんて汚いのでしょう!!

于 2013-07-03T09:05:43.083 に答える
1

残念ながら、 with の実装にp:tabViewdynamic="true"バグがあります。さまざまな問題があります: http://code.google.com/p/primefaces/issues/list?can=2&q=tabView+dynamic&colspec=ID+Type+Status+Priority+TargetVersion+Reporter+Owner+Summary&y=5000&cells=tilesしかし、最も影響を受けるのは などのコンポーネントp:selectOneMenuです。

私自身のプロジェクトでこの問題が発生しました - 選択リストの値が他のタブでアクティブになっている場合、それらの値は送信されませんでした。解決策は、固定されない限り、動的タブを使用しないことです。内部にはバグが多すぎます。

うまくいかないもう 1 つのことは、ajax イベントからタブ ビューを更新することonTabChangeです。

于 2013-07-02T06:54:16.607 に答える
0

選択した要素を保存するには<p:selectOneMenuが必要なためです。

于 2013-07-01T06:32:45.537 に答える