Reputation: 381
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.
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/>
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.
Upvotes: 0
Views: 1753
Reputation: 3495
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>
--- UPDATE: ---
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.
Upvotes: 1