[英]Opening a new window by clicking <p:commandButton> in JSF
I am trying to open a new pop up window by clicking a button <p:commandButton>
in JSF. 我试图通过单击JSF中的按钮
<p:commandButton>
打开一个新的弹出窗口。
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中分配的我正在构建的网址,空白打开了。
Please help me to resolve this issue. 请帮助我解决此问题。
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. 当第一次显示带有按钮的页面时(而不是在按下按钮之后),将评估PrimeFaces组件的
oncomplete
属性中的EL #{...}
。 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. 因此,基本上,您是在处理呈现页面时的值,而不是在action方法中更改的值。
You'd better ajax-update an inline script instead of performing oncomplete
. 您最好ajax更新内联脚本,而不要执行
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"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.