p:commandLink不会在p:dataTable中调用actionlistener

时间:2014-11-08 20:48:22

标签: jsf primefaces

这是XHTML代码

<p:commandLink style="width: 10px;height: 10px;" 
               actionListener="#{InboxBean.archiveInboxRecord(actionEvent)}">
   <img src="../resources/images/arch.png" />
   <f:setPropertyActionListener value="#{inboxitem}" 
                                target="#{InboxBean.selectedInbox}"/>
</p:commandLink>

这是bean

public  void archiveInboxRecord(ActionEvent actionEvent){
   System.err.println("Record Title is " + this.selectedInbox.AppTitle);
}

3 个答案:

答案 0 :(得分:1)

使用actionListener时,参数actionEvent不需要发送。您应该使用以下代码。

<p:commandLink style="width: 10px;height: 10px;" 
               actionListener="#{InboxBean.archiveInboxRecord}" >
   <img src="../resources/images/arch.png" />
   <f:setPropertyActionListener value="#{inboxitem}" 
                                target="#{InboxBean.selectedInbox}" />
</p:commandLink>

答案 1 :(得分:0)

检查您的数据表是否在表单标记中 那样:

<h:form id="form">
<p:datatable var="student" value="#{studentbean.listStd}">
<p:column headerText="column 1">Something here ..</p:column>
<p:column headerText="Action">
<p:commandLink style="width: 10px;height: 10px;" 
               actionListener="#{InboxBean.archiveInboxRecord}" >
   <img src="../resources/images/arch.png" />
   <f:setPropertyActionListener value="#{inboxitem}" 
                                target="#{InboxBean.selectedInbox}" />
</p:commandLink>
</p:column>
</p:datatable>
</h:form>

或者尝试将commandLink放在from标签中:

<h:form id="formLink">
<p:commandLink style="width: 10px;height: 10px;" 
               actionListener="#{InboxBean.archiveInboxRecord}" >
   <img src="../resources/images/arch.png" />
   <f:setPropertyActionListener value="#{inboxitem}" 
                                target="#{InboxBean.selectedInbox}" />
</p:commandLink>
</h:form>

答案 2 :(得分:0)

在朋友帮助之后......

正确的代码是

<p:commandLink  style="width: 10px;height: 10px;" 
                                                   process="inboxdt"  
                                                   actionListener ="#{InboxBean.archiveInboxRecord(actionEvent)}" >

                                      <img src="../resources/images/arch.png" />
                                        <f:setPropertyActionListener value="#{inboxitem}" target="#{InboxBean.selectedInbox}" />
                                    </p:commandLink>

并且关键解决方案是处理数据表Id&#34; inboxdt&#34;