没有调用JSF setpropertyactionlistener

时间:2013-12-18 15:23:57

标签: jsf jsf-2 primefaces

我在数据表中有一个f:setPropertyActionListener,并且单击一个命令按钮,没有调用setpropertyaction监听器。任何人都会看到我出错的地方?

感谢

 <?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>

在我的bean中,我有以下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 个答案:

答案 0 :(得分: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;
}

你可以继续使用你的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();
}

要了解更多调用的顺序

查看