【问题标题】:a4j:jsFunction not called from another scripta4j:jsFunction 未从另一个脚本调用
【发布时间】:2014-04-25 16:29:36
【问题描述】:

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

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's working!),可以。

【问题讨论】:

  • 请注意,showcase 使用的是 RichFaces 4.3,有些东西可能不适用于 RF 4.1。你可以从控制台调用 deleteArchive() 吗?
  • Chromes InteliSense 知道它,但调用它时出现未定义的错误。
  • 我已经更新到 4.3.5,但没什么不同。
  • bean 名称应该以小写字母开头,但我不知道这是否是问题所在。检查生成的 HTML 中的函数定义,看起来问题就在那里。
  • 按照上面的方法改变bean的名字对页面的行为没有任何影响。

标签: javascript jsf richfaces


【解决方案1】:

尝试在弹出面板中移动 deleteArchive jsFunction 并直接调用它而不是 callRemove

【讨论】:

  • 感谢您的回答,但将 jsFunction 移至弹出窗口并不能解决此问题。抱歉回复晚了!
猜你喜欢
  • 2011-02-23
  • 2011-06-01
  • 2022-08-02
  • 1970-01-01
  • 2019-06-18
  • 1970-01-01
  • 1970-01-01
  • 2020-03-22
  • 2015-07-07
相关资源
最近更新 更多