最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Opening a new window by clicking <p:commandButton> in JSF - Stack Overflow

programmeradmin0浏览0评论

I am trying to open a new pop up window by clicking a button <p:mandButton> in JSF.

Here is my code,

<h:inputText style="width:42%"value="#{xxbean.values}" rendered="#{xxBean.yy == true}" 
     onblur="cc;" maxlength="6">
</h:inputText> 
<p:mandButton value="FindPhone" id="xxne" actionListener="#{xx.findPhoneSearch}"
    onplete="window.open('#{xx.wpUrl}', '_blank')" 
    rendered="#{xx.editCmdActionflg == true }"  async="false">
    <f:param name="pmid" value="#{xx.Details.uid}"/>                                   
</p:mandButton>

I am calling he method findPhoneSearch like the one given above in actionlistener inside the mand button ,

Here is the findPhoneSearch method ,

public void FindphoneSearch(ActionEvent event) {



        String param = "";

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

        String expression = "^[a-z0-9]+$";
        Pattern pattern = Patternpile(expression);

        if (params.get("pmid") != null) {
            String t_pmid = params.get("pmid");
            Matcher matcher = pattern.matcher(t_pmid);
            if (matcher.matches()) {
                param = "/cgi-bin/Findphones.pl?id=" + t_pmid.trim();
            }
        }

        if (params.get("lpid") != null) {
            String t_lpid = params.get("lpid");
            Matcher matcher = pattern.matcher(t_lpid);
            if (matcher.matches()) {
                param = "/cgi-bin/Findphones.pl?id=" + t_lpid.trim();
            }
        }

        String findphoneUrl= "" + param;
        wpUrl = findphoneUrl;


    }

My problem is the window is open blank without passing the url that I am framing which is assigned in wpurl.

Please help me to resolve this issue.

I am trying to open a new pop up window by clicking a button <p:mandButton> in JSF.

Here is my code,

<h:inputText style="width:42%"value="#{xxbean.values}" rendered="#{xxBean.yy == true}" 
     onblur="cc;" maxlength="6">
</h:inputText> 
<p:mandButton value="FindPhone" id="xxne" actionListener="#{xx.findPhoneSearch}"
    onplete="window.open('#{xx.wpUrl}', '_blank')" 
    rendered="#{xx.editCmdActionflg == true }"  async="false">
    <f:param name="pmid" value="#{xx.Details.uid}"/>                                   
</p:mandButton>

I am calling he method findPhoneSearch like the one given above in actionlistener inside the mand button ,

Here is the findPhoneSearch method ,

public void FindphoneSearch(ActionEvent event) {



        String param = "";

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

        String expression = "^[a-z0-9]+$";
        Pattern pattern = Pattern.pile(expression);

        if (params.get("pmid") != null) {
            String t_pmid = params.get("pmid");
            Matcher matcher = pattern.matcher(t_pmid);
            if (matcher.matches()) {
                param = "/cgi-bin/Findphones.pl?id=" + t_pmid.trim();
            }
        }

        if (params.get("lpid") != null) {
            String t_lpid = params.get("lpid");
            Matcher matcher = pattern.matcher(t_lpid);
            if (matcher.matches()) {
                param = "/cgi-bin/Findphones.pl?id=" + t_lpid.trim();
            }
        }

        String findphoneUrl= "http://Findphone." + param;
        wpUrl = findphoneUrl;


    }

My problem is the window is open blank without passing the url that I am framing which is assigned in wpurl.

Please help me to resolve this issue.

Share Improve this question edited Jan 24, 2014 at 8:57 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked Jan 23, 2014 at 16:24 KarthikKarthik 3813 gold badges7 silver badges33 bronze badges 3
  • Try adding the attribute update="@all" to your mandButton. I believe your problem is that you are trying to use ajax calls without updating your view with the answer, so the value of wpUrl is old (empty). – Yamada Commented Jan 23, 2014 at 17:55
  • @yamada: I tried that too but its not helping.I am trying to pass the parameters to backing bean using this code <f:param name="pmid" value="#{xx.Details.uid}"/> when i click the mand button, but I could not able to get the value. – Karthik Commented Jan 24, 2014 at 7:33
  • You can use onclick="target='_blank'" stackoverflow./a/54010074/5626568 – ℛɑƒæĿᴿᴹᴿ Commented Jan 2, 2019 at 16:49
Add a ment  | 

1 Answer 1

Reset to default 4

The EL #{...} in onplete attribute of a PrimeFaces ponent is evaluated when the page with the button is displayed for the first time, not after the button is pressed. So basically, you're dealing with the value as it was while the page is rendered, not with the value which is changed in action method.

You'd better ajax-update an inline script instead of performing onplete.

<p:mandButton ... update="openWindow" />
<h:panelGroup id="openWindow">
    <h:outputScript rendered="#{not empty xx.wpUrl}">
        window.open('#{xx.wpUrl}', '_blank')
    </h:outputScript>
</h:panelGroup>

Don't forget to remove async="false" from the button.

发布评论

评论列表(0)

  1. 暂无评论