2017-12-08 3 views
0

PrimeFacesのダイアログは、ダイアログページで日付の差分を更新して計算しません。PrimeFacesのダイアログで日付の更新が更新されず、計算されない

ダイアログページ:

 <p:dialog id="GrupoCreateDlg" widgetVar="GrupoCreateDialog" modal="true" resizable="false" appendTo="@(body)" header="#{bundle.CreateGrupoTitle}"> 
     <h:form id="GrupoCreateForm"> 
      <h:panelGroup id="display"> 
       <p:panelGrid columns="2" rendered="#{grupoController.selected != null}"> 
        <p:outputLabel value="#{bundle.CreateGrupoLabel_grupo}" for="grupo" /> 
        <p:inputText id="grupo" value="#{grupoController.selected.grupo}" title="#{bundle.CreateGrupoTitle_grupo}" required="true" requiredMessage="#{bundle.CreateGrupoRequiredMessage_grupo}"/> 
        <p:outputLabel value="#{bundle.CreateGrupoLabel_usuario}" for="usuario" /> 
        <p:inputText id="usuario" value="#{grupoController.selected.usuario}" title="#{bundle.CreateGrupoTitle_usuario}" required="true" requiredMessage="#{bundle.CreateGrupoRequiredMessage_usuario}"/> 
        <p:outputLabel value="#{bundle.CreateGrupoLabel_clave}" for="clave" /> 
        <p:inputText id="clave" value="#{grupoController.selected.clave}" title="#{bundle.CreateGrupoTitle_clave}" required="true" requiredMessage="#{bundle.CreateGrupoRequiredMessage_clave}"/> 
        <p:outputLabel value="#{bundle.CreateGrupoLabel_detalle}" for="detalle" /> 
        <p:inputText id="detalle" value="#{grupoController.selected.detalle}" title="#{bundle.CreateGrupoTitle_detalle}" /> 
        <p:outputLabel value="#{bundle.CreateGrupoLabel_fechainicio}" for="fechainicio" /> 
        <p:calendar id="fechainicio" pattern="dd/MM/yyyy" value="#{grupoController.selected.fechainicio}" title="#{bundle.EditGrupoTitle_fechainicio}" 
           locale="es" showOn="button" showButtonPanel="true"/> 
        <p:outputLabel value="#{bundle.CreateGrupoLabel_fechafin}" for="fechafin" /> 
        <p:calendar id="fechafin" pattern="dd/MM/yyyy" value="#{grupoController.selected.fechafin}" title="#{bundle.EditGrupoTitle_fechafin}" 
           locale="es" showOn="button" showButtonPanel="true"> 
         <p:ajax event="change" update="dias"/> 
        </p:calendar> 
        <p:outputLabel value="Dias"/> 
        <h:outputText id="dias" value="#{grupoController.calcularFechas()}"> 
         <f:convertNumber type="number"/> 
        </h:outputText> 
        <p:outputLabel value="#{bundle.CreateGrupoLabel_incidencia}" for="incidencia" /> 
        <p:selectBooleanCheckbox id="incidencia" value="#{grupoController.selected.incidencia}" /> 
        <p:outputLabel value="#{bundle.CreateGrupoLabel_fechaincidencia}" for="fechaincidencia" /> 
        <p:calendar id="fechaincidencia" pattern="dd/MM/yyyy" value="#{grupoController.selected.fechaincidencia}" title="#{bundle.EditGrupoTitle_fechaincidencia}" 
           locale="es" showOn="button" showButtonPanel="true"/> 
        <p:outputLabel value="#{bundle.CreateGrupoLabel_fechaavisocaducidad}" for="fechaavisocaducidad" /> 
        <p:calendar id="fechaavisocaducidad" pattern="dd/MM/yyyy HH:mm:ss" value="#{grupoController.selected.fechaavisocaducidad}" title="#{bundle.EditGrupoTitle_fechaavisocaducidad}" 
           locale="es" showOn="button" showButtonPanel="true"/> 
       </p:panelGrid> 
       <p:commandButton actionListener="#{grupoController.create}" value="#{bundle.Save}" update="display,:GrupoListForm:datalist,:growl" oncomplete="handleSubmit(args,'GrupoCreateDialog');"/> 
       <p:commandButton value="#{bundle.Cancel}" onclick="GrupoCreateDialog.hide()"/> 
      </h:panelGroup> 
     </h:form> 
    </p:dialog> 

GROUPOコントローラ:

public int calcularFechas() throws ParseException { 
    diasDuracion = 0; 
    try { 
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 

     Date fechaFinal = selected.getFechainicio(); 
     Date fechaInicial = selected.getFechainicio(); 

     diasDuracion = (int) ((fechaFinal.getTime() - fechaInicial.getTime())/86400000); 

     System.out.println("Hay " + diasDuracion + " dias de diferencia"); 

    } catch (NullPointerException e) { 
     e.printStackTrace(); 
    } 
    return diasDuracion; 

} 

HTMLはoutputTextの中(の日)の日付の初期と仕上がりの違いを示している必要があります。 どうしたの? outputText diasは、ダイアログページを閉じることなく更新する必要があります。

答えて

0

私はコピーして、自分のプロジェクトに自分のものを貼り付けて、そのようにそれを編集します。

(calcularFechasを入れて)

<p:ajax event="change" update="dias" listener="#{grupoController.calcularFechas()"/> 

へと

getCalcularFechas(){ ... }

メソッドを書くことイベントが起こった後にリスナーが呼び出されたので、私のように働いていました。

+0

何ですか?本当に ?私はそれを試してみましたが、これまでにNullPointと会いました。Grave:java.lang.NullPointerException \t servicio.controller.GrupoController.getCalcularFechas(GrupoController.java:168) - >次の行にあります:diasDuracion =(int)((fechaFinal .getTime() - fechaInicial.getTime())/ 86400000); –

関連する問題