JSF-< h:commandButton>不会从支持Bean调用新窗口 [英] JSF- <h:commandButton> does not invoke new window from backing bean
问题描述
我的问题类似于此问题
我在XHTML中有一个,它调用backing bean方法来调用带有预构建URL的新窗口.但是我的问题是它没有打开URL.
MY issue is similar to this issue
I am having an in XHTML and it calls the backing bean method for invoking a new window with an pre constructed URL.But my problem is its not opening the URL.
我在XHTML中的代码在下面给出
My code in the XHTML is given below
<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>
而我的代码在后备豆
And my code given in the backing bean
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>
时在当前窗口中重新打开同一页面
请让我知道您提出的解决此问题的建议.
My problem is clikcing the <h:commandbutton>
does not open a new window instead the same page reopens in the current window when I click the <h:commandbutton>
Please let me know your suggestions to resolve this issue.
推荐答案
如@Alexandre所说,< h:commandButton/>没有标记属性. 使用< h:commandLink/>
as @Alexandre say, <h:commandButton/> doesn't have taget attribute. use <h:commandLink/>
<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/>.我的样本如下.
if you want to trigger some javascript events you can use <f:ajax/>. my sample below.
<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>
但是我不建议使用弹出窗口.因为所有浏览器都将其阻止.我认为对话框框架或
but I don't advise to use popup window. because all of browsers block them. I think dialog framework or lightbox component can be more useful.
这篇关于JSF-< h:commandButton>不会从支持Bean调用新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!