简体   繁体   English

JSF- <h:commandButton> 不从支持bean调用新窗口

[英]JSF- <h:commandButton> does not invoke new window from backing bean

MY issue is similar to this issue 我的问题与此问题相似
I am having an in XHTML and it calls the backing bean method for invoking a new window with an pre constructed URL.But my problem is its not opening the URL. 我在XHTML中有一个,它调用了backing bean方法来调用带有预构建URL的新窗口。但是我的问题是它没有打开URL。

My code in the XHTML is given below 我在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>


And my code given in the backing bean 而我的代码在后备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/>

My problem is clikcing the <h:commandbutton> does not open a new window instead the same page reopens in the current window when I click the <h:commandbutton> 我的问题是clikcing的<h:commandbutton>当我点击不会打开一个新的窗口,而不是在同一个页面重新打开当前窗口<h:commandbutton>
Please let me know your suggestions to resolve this issue. 请让我知道您对解决此问题的建议。

as @Alexandre say, <h:commandButton/> doesn't have taget attribute. 正如@Alexandre所说,<h:commandButton />没有标记属性。 use <h:commandLink/> 使用<h:commandLink />

<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>

--- UPDATE: --- -更新:-

if you want to trigger some javascript events you can use <f:ajax/>. 如果要触发一些javascript事件,可以使用<f:ajax />。 my sample below. 我的样本如下。

<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>

but I don't advise to use popup window. 但我不建议使用弹出窗口。 because all of browsers block them. 因为所有浏览器都将其阻止。 I think dialog framework or lightbox component can be more useful. 我认为对话框框架灯箱组件可能会更有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM