【问题标题】:JSF- <h:commandButton> does not invoke new window from backing beanJSF- <h:commandButton> 不从支持 bean 调用新窗口
【发布时间】:2014-04-22 11:28:39
【问题描述】:

我的问题类似于issue
我有一个在 XHTML 中,它调用支持 bean 方法来调用具有预先构造的 URL 的新窗口。但我的问题是它没有打开 URL。

我的 XHTML 代码如下


 <h:commandButton  style="margin-left:1em;width: auto; height: 20px;font-size:85%"
value="WebPhone" id="lwebpne"rendered="#{Bean.editCmdActionflg == true and (Bean.selectedSearchSysDetRow.isfeed != '1'  or Bean.selectedOverviewDetails.webPheFlg == false)}"actionListener="#{Bean.webPhoneSearch}"   >
<f:param name="lpid" value="lpid" />
</h:commandButton>


而我在支持 bean 中给出的代码

public void webPhoneSearch(ActionEvent event) {
        logger.info("webPhoneSearch Method Enter ..");

        String param = "";

        Map<String, String> params = FacesContext.getCurrentInstance()
                .getExternalContext().getRequestParameterMap();

    if (params.get("lpid") != null) {
            System.out.println("coming inside>>>>>");
            // String t_lpid = params.get("lpid");
            String t_lpid = selectedOverviewDetails.getLeadPrgMgrUid();
            Matcher matcher = pattern.matcher(t_lpid);
            if (matcher.matches()) {
                param = "this values comes from UI ";
            }
        }
// below is a  URL where the window will launch to show the details of a person which we are search for
    Url = "http:// URL for searching a person in webphone" +param;
        RequestContext.getCurrentInstance().execute(
                "window.open('" + Url + "')");

        logger.info("webPhoneSearch Method Exit ..");

}<br/>

我的问题是点击&lt;h:commandbutton&gt; 不会打开新窗口,而是在我点击&lt;h:commandbutton&gt; 时在当前窗口中重新打开同一页面
请让我知道您对解决此问题的建议。

【问题讨论】:

  • h:commandButton 没有属性 target 在您的 h:form 上尝试,如另一个问题中的回答。

标签: java jsf jsf-2 primefaces


【解决方案1】:

正如@Alexandre 所说, 没有taget 属性。 使用

<h:commandLink target="_blank"
                 style="margin-left:1em;width: auto; height: 20px;font-size:85%"
                 value="WebPhone" id="lwebpne"
                 rendered="#{Bean.editCmdActionflg == true and (Bean.selectedSearchSysDetRow.isfeed != '1'  or Bean.selectedOverviewDetails.webPheFlg == false)}"
                 actionListener="#{Bean.webPhoneSearch}">
    <f:param name="lpid" value="lpid"/>
</h:commandLink>

--- 更新:---

如果你想触发一些javascript事件你可以使用。我的示例如下。

<h:commandButton style="margin-left:1em;width: auto; height: 20px;font-size:85%"
                 value="WebPhone" id="lwebpne" rendered="#{Bean.editCmdActionflg == true and (Bean.selectedSearchSysDetRow.isfeed != '1'  or Bean.selectedOverviewDetails.webPheFlg == false)}">
    <f:ajax execute="@form" render="@form" listener="#{Bean.webPhoneSearch()}" onevent="eventListener"/>
</h:commandButton>
<h:outputScript>
    function eventListener(data) {
        if (data.status == "complete") {
            <!-- YOUR WINDOW ADDRESS HERE -->
            window.open('http://google.com', '_blank');
        }
    }
</h:outputScript>

但我不建议使用弹出窗口。因为所有浏览器都阻止了它们。我认为dialog frameworklightbox 组件会更有用。

【讨论】:

  • @ bhdrk。感谢您的建议。我想使用 而不是 。我的问题是 在这里给出stackoverflow.com/questions/21255092/…,所以呢我所做的是将 替换为 .Coz' 如果我在上面的 URL 中给出了 ,则会出现设计问题。 工作正常打开一个新窗口,但 没有打开一个新窗口。请告诉我您的建议。
猜你喜欢
  • 2014-02-25
  • 2015-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-24
  • 2011-04-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多