3

p:tabView編集可能なデータをセクションに分割するために使用しています。すべての編集要素は、p:inplaceコンポーネント内に配置されます。問題は特にp:selectOneMenuコンポーネントにあります。

タブ ビュー全体が更新さp:selectOneMenu れると、アクティブな他のタブにある の値は null に設定されます。どうしてか分かりません。これはバグですか、それともPrimeFacesコンポーネントの間違った使い方ですか?

環境:

  • プライムフェイス 3.4
  • マイフェイス 2.0.7
  • IBM WebSphere 7.0

エラーを再現する方法:

  • 複数のタブで tabView を作成する
  • 1 つのタブに selectOneMenu を inplace 内に配置する
  • tabView を更新する make ボタン
  • selectOneMenu の値を選択し、タブを変更し、更新をクリックして、selectOneMenu でタブに戻ります。

サンプルページと Bean のコード:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html 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>
   <f:facet name="first">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   </f:facet>
   <title>QMWPSUI</title>
   <h:outputScript library="qm" name="qmutils.js" />
   <h:outputScript library="qmwpsui" name="process.js" />
</h:head>
<h:body>


<h:form id="main">
   <p:blockUI block="main" trigger="refreshButton" widgetVar="block">
   <p:graphicImage
            value="#{resource['primefaces-qmui:images/waitprogress.gif']}" />
   </p:blockUI> 

   <h3>Test</h3>

      <p:commandButton id="refreshButton" widgetVar="refreshButton"
               action="#{test.refresh}" 
               icon="ui-icon-refresh"   title="#{i18n['action.reload']}"
               onclick="block.show()"
               update="tabView"/>

      <p:tabView id="tabView" orientation="top" dynamic="TRUE">
         <p:tab id="tab1" title="Tab 1" process="@this">
            <h:outputLabel value="Type*:" for="type"/>
            <p:inplace emptyLabel="Click here to change">
               <p:selectOneMenu id="typ" value="#{test.type}" effect="fade"
                  style="width:300px">
                  <f:selectItem itemLabel="" itemValue="" />
                  <f:selectItem itemLabel="Type a" itemValue="a" />
                  <f:selectItem itemLabel="Type b" itemValue="b" />
                  <f:selectItem itemLabel="Type c" itemValue="c" />
               </p:selectOneMenu>
            </p:inplace>
         </p:tab>
         <p:tab id="tab2" title="Tab 2" process="@this">
         </p:tab>
         <p:tab id="tab3" title="Tab 3" process="@this">
         </p:tab>
      </p:tabView>      

</h:form>

</h:body>

Bean クラス:

import java.io.Serializable;

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

@ManagedBean(name = "test")
@ViewScoped
public class TestBean implements Serializable {

   private static final long serialVersionUID = 1L;

   private static final Logger log = LoggerFactory.getLogger(TestBean.class);
   private String type;

   public String getType() {
      return type;
   }

   public void setType(String type) {
      this.type = type;
   }

   @Override
   public String toString() {
      StringBuilder builder = new StringBuilder();
      builder.append("TestBean [");
      if (type != null) {
         builder.append("type=");
         builder.append(type);
      }
      builder.append("]");
      return builder.toString();
   }

   public void refresh() {
      log.info("Refresh");
      log.info("Test = <{}>", this);
   }

}
4

1 に答える 1

-1

この場合はコンバーターが必要です

public class EmptyToNullConverter は Converter {

@Override
public Object getAsObject(FacesContext facesContext, UIComponent component,
        String value) {
    Object retorno = value;
    if (value == null || value.isEmpty()) {
        if (component instanceof EditableValueHolder) {
            ((EditableValueHolder) component).setSubmittedValue(null);
        }
        retorno = null;
    }
    return retorno;
}

@Override
public String getAsString(FacesContext facesContext, UIComponent component,
        Object value) {
    return (value == null) ? null : value.toString();
}

}

そしてfaces-config.xmlで定義します

<converter>
    <converter-for-class>java.lang.String</converter-for-class>
    <converter-class>org.converter.EmptyToNullConverter</converter-class>
</converter>
于 2013-09-03T22:24:38.753 に答える