javascript - a4j :jsFunction not called from another script

标签 javascript jsf richfaces

我将 jsf 与 richfaces 4.1 一起使用,并且想要以与展示中完全相同的方式修改表格内容(删除给定行):

http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=dataTable&sample=dataTableEdit&skin=wine

但在我的例子中,辅助 bean 函数不会被调用。我还尝试在 a4j:jsFunction oncomplete 事件中插入alert(),但也没有调用,甚至尝试直接从弹出窗口的命令按钮调用deleteArchive() 函数。
我读过该主题的不同文章,但没有一篇文章解决了我的问题。

我的代码如下:

<h:form class="page_frame">
    <rich:dataTable value="#{RunArchiveBean.archivedRuns}" var="run" id="run_table" style="margin-top: 50px; border: none !important; margin-left: auto; margin-right: auto;">
        <f:facet name="header">
            <h:outputText class="output_text_header" value="Session Run History" />
        </f:facet>
        <rich:column filterValue="#{RunArchiveBean.sessionNameFilter}"
                     filterExpression="#{fn:containsIgnoreCase(run.session.sessionName,RunArchiveBean.sessionNameFilter)}">
            <f:facet name="header">Session Name 
                <h:inputText value="#{RunArchiveBean.sessionNameFilter}">
                    <a4j:ajax event="keyup" render="run_table@body" execute="@this" />
                </h:inputText>
            </f:facet>
                <h:outputText value="#{run.session.sessionName}"></h:outputText>
        </rich:column>
        <rich:column>
            <f:facet name="header">Network</f:facet>
                <h:outputText value="#{run.session.network}"></h:outputText>
        </rich:column>
        <rich:column>
            <f:facet name="header">Network Element</f:facet>
                <h:outputText value="#{run.session.networkElement}"></h:outputText>
        </rich:column>
        <rich:column>
            <f:facet name="header">Creation Date of Session</f:facet>
                <h:outputText value="#{run.session.creationDate}"></h:outputText>
        </rich:column>
        <rich:column>
            <f:facet name="header">Run Date of Session</f:facet>
                <h:outputText value="#{run.logDate}"></h:outputText>
        </rich:column>
        <rich:column>
            <f:facet name="header">Results</f:facet>
            <a4j:commandLink execute="@this" action="#{SessionActionBean.showSessionLog(run.session, run.logDate)}" >
                <h:graphicImage id="log_image" name="log.png" library="images" style="border:0" />
                <rich:tooltip followMouse="true" target="log_image" value="Log" />
            </a4j:commandLink>
            <a4j:commandLink execute="@this" action="#{AnalyzerBean.setup(run.session, run.logDate)}">
                <h:graphicImage id="ida_icon" name="idaicon.png" library="images" style="border:0" />
                <rich:tooltip followMouse="true" target="ida_icon" value="IDA Results" />
            </a4j:commandLink>
            <h:commandLink id="hitLink" action="#{TraceBean.traceRead(run.session,run.logDate)}" disabled="#{!RunArchiveBean.fileExists(run.session, run.logDate, 'traceResult.log')}">
                <h:graphicImage id="hit_icon" name="#{RunArchiveBean.getHitIcon(run.session,run.logDate)}" library="images" style="border:0" />
                <rich:tooltip followMouse="true" target="hit_icon" value="HIT Results" />
            </h:commandLink>
            <a4j:commandLink id="delete_result" rendered="#{SessionActionBean.checkUserLevel()}" execute="@this" render="@none" onclick="#{rich:component('delete_archive')}.show();">
                <h:graphicImage id="delete_icon" name="delete.png" library="images" style="border:0"/>
                <rich:tooltip followMouse="true" target="delete_icon" value="Remove archived run" />
                <a4j:param value="#{run.index}" assignTo="#{RunArchiveBean.indexofDeleteArchive}"/>
            </a4j:commandLink>

        </rich:column>
    </rich:dataTable>

    <rich:jQuery selector="#run_table tr:odd" query="addClass('odd-row')" />
    <rich:jQuery selector="#run_table tr:even" query="addClass('even-row')" />

    <a4j:jsFunction name="deleteArchive" action="#{RunArchiveBean.removeArchivedRun}" render="run_table" execute="@this" oncomplete="#{rich:component('delete_archive')}.hide();" />

    <rich:popupPanel id="delete_archive" autosized="true" resizeable="false"
                 onmaskclick="#{rich:component('delete_archive')}.hide();">
        <f:facet name="header">
            <h:outputText value="Deleting archived run" />
        </f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('delete_archive')}.hide();">
                <h:graphicImage name="close.png" library="images" />
            </h:outputLink>
        </f:facet>
        <table>
            <tr>
                <td>
                    <h:outputText value="Are you sure to delete selected results?" />
                </td>
            </tr>
            <tr>
                <td>
                    <a4j:commandButton styleClass="fieldset_button" value="Yes" onclick="callRemove(); #{rich:component('delete_archive')}.hide(); return false;"/>
                </td>
                <td>
                    <a4j:commandButton styleClass="fieldset_button" value="Cancel" onclick="#{rich:component('delete_archive')}.hide();" />
                </td>
            </tr>
        </table>
    </rich:popupPanel>
</h:form>

使用脚本:

function callRemove() {
    deleteArchive();
}

有什么想法吗?任何帮助将不胜感激。

更新#1:
a4j:jsFunction 在客户端生成以下脚本:

<script type="text/javascript"><!--
deleteArchive=function(){RichFaces.ajax("j_id_1d:j_id_2d",null,{"incId":"1"} )};
//--></script>

更新#2:
直接从 a4j:commandButton 操作属性调用removeArchivedRun()函数也不起作用,但调用其他JavaScript表单onclick方法,如alert('It'sworking!),则有效。

最佳答案

尝试将deleteArchive jsFunction移入弹出面板内并直接调用它而不是callRemove

关于javascript - a4j :jsFunction not called from another script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22505680/

相关文章:

javascript - 将 java 变量传递给 javascript 函数

java - Weblogic 9.2.1 上的 RichFaces

javascript - Vue挂载getBoundingClientRect().height但是得到0

javascript - 如何在 ASP.NET MVC 4 Beta 中禁用 Javascript/CSS 缩小

javascript - NodeJS SRCDS 查看孙子进程日志

java - 在 RichFaces 4.x ExtendedDataTable 中将列宽设置为百分比

java - Apache Tomcat、Eclipse、JBoss 和 RichFaces

javascript - 在 php 中使用 Onsubmit 函数

java - 更新复合组件?

java - 面板内命令按钮的问题