【问题标题】:Call same bean method from multiple onclick with different parameters not working [duplicate]从多个onclick调用相同的bean方法,不同的参数不起作用[重复]
【发布时间】:2016-02-26 07:42:27
【问题描述】:

我在我的应用程序中使用 Primefaces 和 jsf。我正在使用带有 onclick 功能的多个 commandlink。所有的 onclick 函数调用相同的 bean 方法,但参数不同。即使所有页面都显示相同的指标,页面工作正常且传递参数也不同。 基于参数应该显示不同的指标,但不能正常工作。

XHTML:

<h:commandLink value="Defects" 
action="#{loginbean.setCurrPage('metrics','defects.xhtml')}"
onclick="#{reportsBean.MetricPage('defect')}"
rendered="#{sub_selected =='defects'}" />

<h:commandLink value="Test Case" 
action="#{loginbean.setCurrPage('metrics','testcase.xhtml')}"
onclick="#{reportsBean.MetricPage('testcase')}"
rendered="#{sub_selected =='testcases'}" />

豆子:

public void MetricPage(String ipageid) {
metricssection = metricsProcess.getMetricsProcess().getUserMetrics(ipageid, SessionMgr.getProj());
metricsfeature = metricsProcess.getMetricsProcess().getMetricFeatures(ipageid, SessionMgr.getPro());
        }

我该如何解决这个问题?

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    onclick 是客户端事件。您只能从 onlcick 调用 Javascript 函数。不是来自 Managedbean 的方法。
    由于您将此问题标记为Primefaces,因此我假设您使用的是Primefaces。在这种情况下,您可以使用p:remoteCommand 使用方法见thisp:remotecommand

    【讨论】:

      猜你喜欢
      • 2015-08-12
      • 2013-11-04
      • 2013-05-29
      • 2019-06-15
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 1970-01-01
      • 2017-09-06
      相关资源
      最近更新 更多