2017-03-15 25 views
0

これは私の一部の制限またはコーディングエラーであるかわかりません。私はPrimefaces DataTableを持っていて、それを選択することができます(単一のラジオを選択)し、CommandButtonをクリックしてダイアログ内のデータを編集することができます。Primefaces DataTable Selectionのアトリビュートがダイアログに表示されない場合はNullです

選択したオブジェクトを表示するHTMLコードでは、人間のユーザーがこれらの属性に触れてはならないため、ID、Lat、およびLong属性は省略しました。ダイアログで選択した属性が正しく表示されていますが、選択したオブジェクトIDを使用して既存のレコードを検索しようとしたときに、結果エラーがスローされました。選択したオブジェクトのID属性をチェックすると、値はNULLになります。

私はHTMLコードを使いこなして、選択したオブジェクトに属性のいずれかをコピーするには、その属性をXHTMLで表示する必要があることがわかりました。 Render = Falseのように属性を含めると、属性の値はNULLになります。人間のユーザがタグ属性を無効にすることのほかに変更してはならない属性を隠すことに関する提案はありますか?

Class Property{ 
    Int ID; 
    String Address; 
    Long Lat; 
    Long Long; 
    String Desc; 
} 

public void modifyCurrentProject() { 
    HashMap<String, Object> params = new HashMap(); 
    params.put("id", currentProject.getId()); 

    //fails to find Project by ID as currentProject.getID == null 
    Project temp = (Project) dbu.findByNamedQuery("project.findID", params); 

    //Omit statements to overwrite attached object's values before writing back to database 
    dbu.modifyEntity(); //dbu is another object to control database access 
    currentProject = null; 
} 

<h:body> 
    <p:growl id="projectMsg" showDetail="true"/> 
    <h:form id="form"> 

     <p:dataTable id="projectTable" var="project" value="#{projectBacking.builder.projects}" selection="#{projectBacking.currentProject}" rowKey="#{project.id}"> 
      <f:facet name="header">My Project List 
       <p:commandButton value="Add" type="button" onclick="PF('projectAdd').show()"/> 
       <p:commandButton value="Edit" update=":editForm" oncomplete="PF('projectEdit').show()"/> 
      </f:facet> 

      <p:column selectionMode="single"/> 
      <p:column headerText="ID"> 
       <h:outputText value="#{project.id}"/> 

      <p:column headerText="Description"> 
       <h:outputText value="#{project.property.description}"/> 
      </p:column> 

      <p:column headerText="Street"> 
       <h:outputText value="#{project.street}"/> 
      </p:column> 
      <p:column headerText="City"> 
       <h:outputText value="#{project.city}"/> 
      </p:column> 
      <p:column headerText="Province"> 
       <h:outputText value="#{project.state}"/> 
      </p:column> 

      <p:column headerText="Latitude"> 
       <h:outputText value="#{project.latitude}"/> 
      </p:column> 

      <p:column headerText="Longitude"> 
       <h:outputText value="#{project.longitude}"/> 
      </p:column> 

      <p:column headerText="Status"> 
       <h:outputText value="#{project.status}"/> 
      </p:column> 

     </p:dataTable> 
    </h:form> 

<!-- Omitted the Add Project Dialog box --> 

    <p:dialog header="Edit Project" modal="true" height="400" width="80%" widgetVar="projectEdit"> 
     <h:form id="editForm"> 
      <p:panel id="editProject" header="Edit Project" toggleable="true" closable="false"> 
       <!--<h:inputText id="id" value="#{projectBacking.currentProject.id}"/>--> 

       <h:inputText id="country" value="#{projectBacking.currentProject.country}"/> 

       <h:inputText id="lat" rendered="true" value="#{projectBacking.currentProject.latitude}"/> 

       <h:inputText id="long" rendered="true" value="#{projectBacking.currentProject.longitude}"/> 

       <h:outputLabel for="desc" value="Description" /> 
       <h:inputText id="desc" value="#{projectBacking.currentProject.description}"/> 

       <h:outputLabel for="street" value="Street" /> 
       <h:inputText id="street" value="#{projectBacking.currentProject.street}"/> 
       <h:message for="street"/> 

       <h:outputLabel for="city" value="City:" /> 
       <h:inputText id="city" required="false" value="#{projectBacking.currentProject.city}"/> 
       <h:message for="city" /> 

       <h:outputLabel for="state" value="Province" /> 
       <h:inputText id="state" required="true" value="#{projectBacking.currentProject.state}"/>    

       <h:commandButton value="Save Project" type="submit" action="#{projectBacking.modifyCurrentProject()}"> 
       </h:commandButton> 

      </p:panel> 
     </h:form> 
    </p:dialog>     
</h:body> 
+0

あなたのダイアログとあなたの管理している方法(あなたがデータを取得する方法)を追加してください。問題を理解するのに役立つと確信しています。 –

答えて

0

コードにいくつかのブレークポイントを配置した後、ダイアログに変更を保存すると、新しいバッキングビーンが作成されることがわかりました。 Render = false、Disabled = true、またはReadOnly = trueに設定すると、新しいバッキングBeanのオブジェクトの値は設定されず、オブジェクトのコンストラクタで指定された初期値が保持されます。

原因は、基本的に範囲が正しくありません。私は、問題が発生したときにリクエストスコープを使用していました。しかし、セッションスコープに変更すると解決されました。

関連する問題