我的问题与此问题类似
我在XHTML中有一个,它调用backingbean方法,用预先构建的URL调用一个新窗口。但我的问题是它没有打开URL。
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>
我的代码在backingbean中给出
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/>
我的问题是点击<h:commandbutton>
不会打开新窗口,而是当我点击<h:commandbutton>
时,同一页面会在当前窗口中重新打开
请告诉我你解决这个问题的建议。
正如@Alexandre所说,<h: 命令按钮/>不具有taget属性。使用<h: 命令链接/>
<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>
---更新:---
如果您想触发一些javascript事件,可以使用<f: ajax/>。下面是我的样品。
<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>
但我不建议使用弹出窗口。因为所有的浏览器都会阻止它们。我认为对话框框架或灯箱组件可能更有用。