2013-12-18 40 views
0

我有一個f:setPropertyActionListener在一個數據表內,並點擊一個命令按鈕,setpropertyaction監聽器沒有被調用。任何人看到我要去哪裏錯了?JSF setpropertyactionlistener不被調用

感謝

<?xml version="1.0" encoding="UTF-8"?> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 
     <h:form id="userDetailsForm" style="padding:5px"> 
     <p:growl id="messages" showDetail="true" autoUpdate="true" life="2000"/> 
     <p:spacer height="15"></p:spacer> 

    <div class="row">  
     <div class="col-lg-4"> 
     <div class="input-group"> 
      <p:inputText type="text" styleClass="form-control" value="#{emailArticleBean.searchText}" /> 
      <span class="input-group-btn" style="margin:3px;"> 
      <p:commandButton actionListener="#{emailArticleBean.search}" value="Go!" update=":userDetailsForm:emailArticleTable" /> 
      </span> 
     </div><!-- /input-group --> 
     </div><!-- /.col-lg-6 --> 
    </div><!-- /.row --> 

    <p:spacer height="15"></p:spacer> 
    <h:messages/> 

    <div class="row"> 
     <div class="col-lg-1"> 

     </div> 
     <div class="col-lg-11"> 
     <p:dataTable var="email" value="#{emailArticleBean.emailArticles}" scrollRows="20" 
        scrollable="true" liveScroll="true" scrollHeight="750" id="emailArticleTable" 
        > 
      <p:column> 
       <p:accordionPanel multiple="true" activeIndex="-1" id="panel#{email.id}"> 

        <p:tab title="#{email.headline}" titleStyleClass="email-header"> 
          <div style="clear:both;margin-bottom:10px;"> 
          <h6 style="font-weight:bold;">Summary</h6> 
          <h:outputText 
           value="#{email.summary}" />  
          </div> 
          <div style="clear:both;margin-bottom:10px;"> 
          <h6 style="font-weight:bold;">Implication</h6> 
          <h:outputText 
           value="#{email.implication}" />  
          </div>   
          <div style="float:left;clear:both"> 
           <p:commandButton value="View Existing Actions" 
            oncomplete="PF('dlg2').show();" update=":userDetailsForm:emailActionDialog"> 
            <f:setPropertyActionListener value="#{email}" target="#{emailArticleBean.selectedEmail}" /> 
           </p:commandButton>     
          </div> 
          <br/> 
          <br/> 
          <div style="margin-top:10px;">   
           <h:inputTextarea id="accordian1" value="#{email.tempAction}" cols="90" rows="3" />       
          </div> 
          <h6 style="font-weight:bold;">Due Date</h6> 
          <p:calendar value="#{email.tempDate}" id="popupCal" pattern="dd MMM, yyyy"/> 
          <p:commandButton actionListener="#{emailArticleBean.updateAction}" value="Add Action" 
           style="margin-left:5px;"> 
           <f:setPropertyActionListener value="#{email}" target="#{emailArticleBean.selectedEmail}" /> 
          </p:commandButton> 

        </p:tab> 
       </p:accordionPanel> 
      </p:column> 
     </p:dataTable> 
     </div> 

    </div> 

    <p:dialog id="emailActionDialog" header="Email Actions" widgetVar="dlg2" modal="true" height="100"> 
     <h3>Email Actions</h3> 
     <p:dataList value="#{emailArticleBean.selectedEmail.actions}" var="action" itemType="disc"> 
      #{action.action} --- #{action.username} 
     </p:dataList> 
    </p:dialog> 



    </h:form> 



</html> 

在我的豆我有以下的getter/setter

public EmailArticle getSelectedEmail() { 
     return selectedEmail; 
    } 

    public void setSelectedEmail(EmailArticle selectedEmail) { 

     this.selectedEmail = selectedEmail; 

    } 

public void updateAction(ActionEvent ae) { 
     selectedEmail.getActions().add(new EmailActions(emailAction, "testUser", actionDueDate)); 
     selectedEmail.merge(); 

    } 

回答

1

這裏的主要問題是調用順序,首先你actionListener被稱爲然後 f:setPropertyActionListener

要解決此問題,請將您的actionListener更改爲action,並更新您的操作方法以返回字符串。

按鈕

<p:commandButton action="#{emailArticleBean.updateAction}" 
        value="Add Action" style="margin-left:5px;"> 
      <f:setPropertyActionListener value="#{email}" 
       target="# {emailArticleBean.selectedEmail}" /> 
    </p:commandButton> 

updateAction

public String updateAction() { 
    selectedEmail.getActions().add(new EmailActions(emailAction, "testUser", actionDueDate)); 
    selectedEmail.merge(); 
    return null; 
} 

OR

您可以繼續使用您的ActionListener並通過selectedEmail給它(不使用F:setPropertyActionListener) 。

按鈕

<p:commandButton actionListener="#{emailArticleBean.updateAction(email)}" 
       value="Add Action" style="margin-left:5px;"> 
</p:commandButton> 

updateAction

public void updateAction(EmailArticle selectedEmail) { 
    selectedEmail.getActions().add(new EmailActions(emailAction, "testUser", actionDueDate)); 
    selectedEmail.merge(); 
} 

要了解調用更多的順序

+0

沒有設置屬性爲@this沒有工作。 \t \t \t \t \t \t \t \t \t \t \t \t \t user1107753

+0

您的updateAction取決於selectedEmail? –

+0

你可以把你的updateAction方法... –

相關問題