javascript 通过单击 JSF 中的 <p:commandButton> 打开一个新窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21313830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening a new window by clicking <p:commandButton> in JSF
提问by techy360
I am trying to open a new pop up window by clicking a button <p:commandButton>
in JSF.
我试图通过单击<p:commandButton>
JSF 中的按钮打开一个新的弹出窗口。
Here is my code,
这是我的代码,
<h:inputText style="width:42%"value="#{xxbean.values}" rendered="#{xxBean.yy == true}"
onblur="cc;" maxlength="6">
</h:inputText>
<p:commandButton value="FindPhone" id="xxne" actionListener="#{xx.findPhoneSearch}"
oncomplete="window.open('#{xx.wpUrl}', '_blank')"
rendered="#{xx.editCmdActionflg == true }" async="false">
<f:param name="pmid" value="#{xx.Details.uid}"/>
</p:commandButton>
I am calling he method findPhoneSearch like the one given above in actionlistener inside the command button ,
我正在调用 findPhoneSearch 方法,就像上面在命令按钮内的 actionlistener 中给出的方法一样,
Here is the findPhoneSearch method ,
这是 findPhoneSearch 方法,
public void FindphoneSearch(ActionEvent event) {
String param = "";
Map<String, String> params = FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap();
String expression = "^[a-z0-9]+$";
Pattern pattern = Pattern.compile(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.com" + param;
wpUrl = findphoneUrl;
}
My problem is the window is open blank without passing the url that I am framing which is assigned in wpurl.
我的问题是窗口打开空白,没有传递我在 wpurl 中分配的框架的 url。
Please help me to resolve this issue.
请帮我解决这个问题。
回答by BalusC
The EL #{...}
in oncomplete
attribute of a PrimeFaces component 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.
PrimeFaces 组件的 EL #{...}
inoncomplete
属性在第一次显示带有按钮的页面时进行评估,而不是在按下按钮后进行评估。所以基本上,您是在处理页面呈现时的值,而不是在 action 方法中更改的值。
You'd better ajax-update an inline script instead of performing oncomplete
.
你最好 ajax-update 一个内联脚本而不是执行oncomplete
.
<p:commandButton ... 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.
不要忘记async="false"
从按钮中删除。