[英]Opening a new window by clicking <p:commandButton> in JSF
我试图通过单击JSF中的按钮<p:commandButton>
打开一个新的弹出窗口。
这是我的代码,
<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>
我在叫他方法findPhoneSearch,就像上面在命令按钮中的actionlistener中给出的那样,
这是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;
}
我的问题是窗口没有打开我在wpurl中分配的我正在构建的网址,空白打开了。
请帮助我解决此问题。
当第一次显示带有按钮的页面时(而不是在按下按钮之后),将评估PrimeFaces组件的oncomplete
属性中的EL #{...}
。 因此,基本上,您是在处理呈现页面时的值,而不是在action方法中更改的值。
您最好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>
不要忘记从按钮中删除async="false"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.