I am trying to mimic the PrimeFaces Dialog example. For some reason that I am not able to find, my PrimeFaces button does not seem to call the required managed bean method:
<h:form>
<p:commandButton value="Open" icon="ui-icon-extlink" actionListener="#{myController.createDialog()}" />
</h:form>
Managed bean:
#Named(value = "myController")
#ViewScoped
public class MyController implements Serializable {
public void createDialog() {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%");
...
The print statement is never executed, like if the Listener was not working. When I click the button, no response is given. No backend error, no JS error, nothing. I only see that some request is done because I log when a user passes the authorization layer. So something happens but seems to fail silently.
What I have tried:
Move the button to other places in the page
Use an id:
<p:commandButton id="ex" value="Open" icon="ui-icon-extlink" actionListener="#{myController.createDialog()}" />
<h:message for="ex" />
Remove the ViewScoped
Require a javax.faces.event.ActionEvent in the method
public void createDialog(ActionEvent event) {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%");
Change the method signature
action="#{myController.createDialog(5)}"
and
public void createDialog(int s) {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%");
I even tried to create a WEB-INF/faces-config.xml (which I would prefer not to, and according to PrimeFaces documentation I do not need it) with:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<view-handler>org.primefaces.application.DialogViewHandler</view-handler>
</application>
<lifecycle>
<phase-listener>org.primefaces.component.lifecycle.LifecyclePhaseListener</phase-listener>
</lifecycle>
Other answers I have checked are: 1, 2, 3, 4, 5, 6
Apparently the use of actionListeners in PrimeFaces is not as correct as it should be... Is there another way to use PrimeFaces components?
This Dialog Framework code works for me:
index.xhtml
<p:commandButton id="openDialogButton" value="open dialog" action="#{myBean.openDialog('origin')}">
<!-- dialogReturn event: data could be passed, see page 587 in PF 6.1 manual. -->
<p:ajax event="dialogReturn" listener="#{myBean.doSthOnDialogReturn}"/>
</p:commandButton>
myDialogPage.xhtml
<p:commandButton id="closeButtonDialog" value="close dialog"
action="#{myBean.closeDialog('false')}"/>
<p:commandButton id="closeButtonDialog2" value="close dialog 2"
action="#{myBean.closeDialog('true')}"
ajax="false" validateClient="true"/>
Note: Example shows how to pass parameter from dialog. You can also notice, that the first button does just return while the second one does validation at first. I think these things can be useful.
myBean.java
public void openDialog(String origin) {
RequestContext.getCurrentInstance().openDialog("myDialogPage",
options, null);
}
public void closeDialog(Boolean param) {
RequestContext.getCurrentInstance().closeDialog(param);
}
public void doSthOnDialogReturn(SelectEvent event) {
if ((Boolean) event.getObject()) { // retrieve param value
doSth();
}
}
WEB-INF/faces-config.xml
<application>
<action-listener>
org.primefaces.application.DialogActionListener
</action-listener>
<navigation-handler>
org.primefaces.application.DialogNavigationHandler
</navigation-handler>
<view-handler>
org.primefaces.application.DialogViewHandler
</view-handler>
</application>
Finally I got to see some error:
SEVERE - /page.xhtml #159,146 actionListener="#{myController.createDialog()}": Target Unreachable, identifier 'myController' resolved to null
The trick to enable the display of error messages was to add the following in faces-config.xml:
<factory>
<exception-handler-factory>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory</exception-handler-factory>
</factory>
After checking this, I realised that my beans.xml file had been somehow deleted (??)
Related
I have a problem with faces message rendering in portlet, deployed on HCL portal 9.5, which is on top of Websphere Application Server 9.0.5.7. Portlet has two pages and when I made first page navigation, faces message stops rendering.
First page html:
<div xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:portlet="http://java.sun.com/portlet_2_0"
xmlns:p="http://primefaces.org/ui">
<f:view>
<f:metadata>
<f:event listener="#{pc_TestJSF22View.init}" type="preRenderView"></f:event>
</f:metadata>
<h:head>
<h:outputScript library="primefaces" name="jquery/jquery.js" />
</h:head>
<h:body>
<h:form id="formMain" styleClass="form">
<p:commandButton id="btnTest" value="Test"
action="#{pc_TestJSF22View.doBtnTest}" />
<p:commandButton id="btnSecondPage" value="Second page"
action="#{pc_TestJSF22View.doBtnSecondPage}" ajax="false" />
<p:messages id="msgGlobal" globalOnly="true" showIcon="false">
<p:autoUpdate />
</p:messages>
</h:form>
</h:body>
</f:view>
First page request bean:
public class TestJSF22View extends PageCodeBase {
private TestSess testSess;
public void init() {
if (PrimeFaces.current().isAjaxRequest()) {
return;
}
try {
System.out.println("INIT method");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
// button action
public String doBtnSecondPage() {
return "testView2";
}
public String doBtnTest() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("page 1 msg updated"));
return null;
}
protected TestSess getTestSess() {
if (testSess == null) {
testSess = (TestSess) getManagedBean("testSess");
}
return testSess;
}
}
Second page html:
<div xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:portlet="http://java.sun.com/portlet_2_0"
xmlns:p="http://primefaces.org/ui">
<f:view>
<f:metadata>
<f:event listener="#{pc_TestJSF22View2.init}" type="preRenderView"></f:event>
</f:metadata>
<h:head>
<h:outputScript library="primefaces" name="jquery/jquery.js" />
</h:head>
<h:body>
<h:form id="formMain" styleClass="form">
<p:commandButton id="btnFirstPage" value="First page"
action="#{pc_TestJSF22View2.doBtnFirstPage}" ajax="false" />
<p:commandButton id="btnMsg" value="Show message"
action="#{pc_TestJSF22View2.doBtnMsg}" />
<p:messages id="msgGlobal2" globalOnly="true" showIcon="false">
<p:autoUpdate />
</p:messages>
</h:form>
</h:body>
</f:view>
Second page request bean:
public class TestJSF22View2 extends PageCodeBase {
private TestSess2 testSess2;
public void init() {
if (PrimeFaces.current().isAjaxRequest()) {
return;
}
try {
System.out.println("INIT2 method");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
// button action
public String doBtnFirstPage() {
System.out.println("doBtnFirstPage method");
return "testView";
}
public String doBtnMsg() {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("page 2 msg updated"));
return null;
}
protected TestSess2 getTestSess2() {
if (testSess2 == null) {
testSess2 = (TestSess2) getManagedBean("testSess2");
}
return testSess2;
}
}
faces-config :
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<view-handler>com.ibm.faces20.portlet.FaceletPortletViewHandler</view-handler>
<el-resolver>com.ibm.faces20.portlet.PortletELResolver</el-resolver>
<resource-handler>com.ibm.faces20.portlet.httpbridge.PortletResourceHandler</resource-handler>
</application>
<factory>
<exception-handler-factory>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory</exception-handler-factory>
</factory>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletActionURL</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletActionURL</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletResourceURL</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletResourceURL</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletRenderURL</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletRenderURL</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletParam</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletParam</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletProperty</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletProperty</component-class>
</component>
<component>
<component-type>com.ibm.faces20.portlet.component.PortletNameSpace</component-type>
<component-class>com.ibm.faces20.portlet.component.PortletNameSpace</component-class>
</component>
<managed-bean>
<managed-bean-name>pc_TestJSF22View</managed-bean-name>
<managed-bean-class>pagecode.TestJSF22View</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>testSess</managed-bean-name>
<managed-bean-class>beans.TestSess</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>pc_TestJSF22View2</managed-bean-name>
<managed-bean-class>pagecode.TestJSF22View2</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>testSess2</managed-bean-name>
<managed-bean-class>beans.TestSess2</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>com.ibm.faces20.portlet.tag.render.ActionURLTagRender</renderer-type>
<renderer-class>com.ibm.faces20.portlet.tag.render.ActionURLTagRender</renderer-class>
</renderer>
</render-kit>
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>com.ibm.faces20.portlet.tag.render.ResourceURLTagRender</renderer-type>
<renderer-class>com.ibm.faces20.portlet.tag.render.ResourceURLTagRender</renderer-class>
</renderer>
</render-kit>
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>com.ibm.faces20.portlet.tag.render.RenderURLTagRender</renderer-type>
<renderer-class>com.ibm.faces20.portlet.tag.render.RenderURLTagRender</renderer-class>
</renderer>
</render-kit>
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>com.ibm.faces20.portlet.tag.render.PortletNameSpaceTagRender</renderer-type>
<renderer-class>com.ibm.faces20.portlet.tag.render.PortletNameSpaceTagRender</renderer-class>
</renderer>
</render-kit>
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>testView</from-outcome>
<to-view-id>/TestJSF22View.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>testView2</from-outcome>
<to-view-id>/TestJSF22View2.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
So, if I illustrate my problem: When I first open portlet and first page is displayed, I click "Test" button, that displays faces message. Next, I navigate to second page and I click "Show message" button, which should display another message on second page, but it doesn't. I get the following warning:
There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered.
These unhandled FacesMessages are:
- page 2 msg updated
Even if I go back to the first page again and hit "Test" button one more time, message is not displayed and the same warning is what I get.
I never had problems with faces messages when I deployed portlets on IBM Websphere Portal Server 7 with JSF 2.0, but now when I run it on HCL portal 9.5 (JSF 2.2), I noticed this strange behavior.
Did I miss something while migrating to HCL portal?
Primefaces version is 7.0, p:messages usage seems ok to me. Could HCL portlet bridge cause that problem? Does anyone have experience with deploying JSF portlets on HCL Portal?
EDIT1:
I've just tried to deploy web application with identical code on Websphere Application Server 9 and it works like a charm. Based on that I believe there's some problem with HCL Portal.
Primefaces 6.1 ajaxExceptionHandler is not working as expected in liferay 7 portlet.
Based on the Primefaces user guide, I tried to implement simple exception handling. When the commandButton is pressed, the backing bean throws a NullPointerException, which should be displayed in a dialog window. The problem is, when the dialog pops up, the exception information is not shown. It seems that the returned ajax response itself contains the exception info (as shown below), but the dialog component is not updated accordingly.
test.xhtml (snippet)
<h:body>
<h:form>
<h3 style="margin-top:0">AJAX 1410</h3>
<p:commandButton actionListener="#{policyAdminBean.throwNpe}"
ajax="true"
value="Throw NullPointerException!" />
<p:ajaxExceptionHandler type="javax.faces.application.ViewExpiredException"
update=":exceptionDialog"
onexception="PF('exceptionDialogVar').show();" />
<p:ajaxExceptionHandler type="java.lang.NullPointerException"
update=":exceptionDialog"
onexception="PF('exceptionDialogVar').show();" />
</h:form>
<p:dialog id="exceptionDialog" header="Exception '#{pfExceptionHandler.type}' occured!" widgetVar="exceptionDialogVar"
height="500px">
Message: #{pfExceptionHandler.message} <br/>
StackTrace: <h:outputText value="#{pfExceptionHandler.formattedStackTrace}" escape="false" /> <br />
<p:button onclick="document.location.href = document.location.href;"
value="Reload!"
rendered="#{pfExceptionHandler.type == 'javax.faces.application.ViewExpiredException'}" />
</p:dialog>
</h:body>
TestBean.java
#Named
#ViewScoped
public class TestBean implements Serializable {
private static final long serialVersionUID = -4856350663999482370L;
public void throwNpe(){
throw new NullPointerException("test exception");
}
}
faces-config.xml (snippet)
<application>
<message-bundle>Language</message-bundle>
<locale-config>
<default-locale>hu</default-locale>
</locale-config>
<el-resolver>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver
</el-resolver>
</application>
<lifecycle>
<phase-listener>com.liferay.faces.util.lifecycle.DebugPhaseListener</phase-listener>
</lifecycle>
<factory>
<exception-handler-factory>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
</exception-handler-factory>
</factory>
ajax response (snippet)
<partial-response id="_policyadmin_WAR_wfsadminportlets_">
<update id="_policyadmin_WAR_wfsadminportlets_:exceptionDialog"><![CDATA[
<div id="_policyadmin_WAR_wfsadminportlets_:exceptionDialog"
class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-shadow ui-hidden-container">
<div class="ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top"><span
id="_policyadmin_WAR_wfsadminportlets_:exceptionDialog_title" class="ui-dialog-title">Exception 'java.lang.NullPointerException' occured!</span><a
href="#" class="ui-dialog-titlebar-icon ui-dialog-titlebar-close ui-corner-all"
aria-label="Close"><span class="ui-icon ui-icon-closethick"></span></a></div>
<div class="ui-dialog-content ui-widget-content">
Message: test exception <br/>
StackTrace: java.lang.NullPointerException: test exception<br/> at
[removed for brevity...]
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)<br/> at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)<br/> at
java.lang.Thread.run(Thread.java:745)<br/> <br/></div>
</div>
<script id="_policyadmin_WAR_wfsadminportlets_:exceptionDialog_s" type="text/javascript">$(function () {
PrimeFaces.cw("Dialog", "exceptionDialogVar", {
id: "_policyadmin_WAR_wfsadminportlets_:exceptionDialog",
height: "500px"
});
});</script>
]]>
</update>
<eval><![CDATA[var
hf=function(type,message,timestampp){PF('exceptionDialogVar').show();};hf.call(this,"java.lang.NullPointerException","test
exception","2017-04-25 14:54:55");]]>
</eval>
</partial-response>
Good question!
This pattern of use for the PrimeFaces AJAX exception handler was working in PrimeFaces before version 6.0. So if you revert to say, PrimeFaces 5.3, you will see it working on Liferay 7. The commit that broke PrimeFaces was e22e40a, which was a complex commit, unknowingly affecting portlets by changing the way the PrimeFaces partial responses are constructed.
A pull request has been sent to the PrimeFaces integrators to fix this.
https://github.com/primefaces/primefaces/pull/2333
Once this pull request is merged, you can build PrimeFaces from the latest source, and you will see that this is fixed.
DETAILS:
Specifically, commit e22e40a changed the PrimePartialResponseWriter.startDocument() method, eliminating its call to encodeCallbackParams() which, in turn, was calling the startChangesIfNecessary() method in mojarra. Since these calls were eliminated, no "changes" element was introduced into the partial response. With no changes, no update occurs in the dialog's DOM. Here is a working stack showing the calls down into startChangesIfNecessary before the e22e40a commit.
i'm new in java & jsf framework. I have a situation and make me realy confused. I'm trying to create upload form in jsf, the backing bean is request scoped, user must login for using this form. when I test to submit form, the validation message its not appear, the form just refresh without any validation/required message. I try to find the answer in google or stackoverflow but it not works. However i can upload my files when i try create simple application like my form below, without login function.
My form is look like this:
<h:form id="frMember" enctype="multipart/form-data">
<h:inputText id="username" value="#{memberForm.email}" required="true" requiredMessage="username_required_message" pt:placeholder="username"/><br/><br/>
<h:inputFile value="#{memberForm.fileFoto}" required="true" requiredMessage="file_required_message"/><br/>
<h:commandButton value="upload" action="#{memberForm.upload()}" class="btn btn-danger"/>
</h:form>
I'm using glassfish 4, JSF 2.2.7, Netbeans 8 and i'm not used 3rd party like tomahawk fileupload. I also have try googling and searching through stackoverflow for solving my problem, but still i can't solved it.
updated
this is my controller
public class MemberFormView implements Serializable {
private Part fileFoto;
/**
* Creates a new instance of MemberFormView
*/
public MemberFormView() {
}
public void upload() throws IOException {
String fileName = FilenameUtils.getName(fileFoto.getName());
String contentType = fileFoto.getContentType();
try (InputStream input = fileFoto.getInputStream()) {
Files.copy(input, new File("/var/AppFile/tmp/", fileFoto.getName()).toPath());
}
}
}
and this is my faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<managed-bean>
<managed-bean-name>memberForm</managed-bean-name>
<managed-bean-class>controller.member.MemberFormView</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
I've been reading and searching among the many pages with similar questions, but I cannot find why my commandButton is not invoking the action (I have debugged it and that is the problem). My code looks simple but... doesn't work. Maybe it's a newbie problem, but I don't know where it is.
I'm writing a portlet for liferay using JSF2 and Liferay Faces Alloy.
I've also read the question commandLink/commandButton/ajax backing bean action/listener method not invoked, very educational for me, but none of the points have solved my problem.
Here is my mainView.xhtml file:
<?xml version="1.0"?>
<f:view
xmlns="http://www.w3.org/1999/xhtml"
xmlns:aui="http://liferay.com/faces/aui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head />
<h:body>
<h:form>
<h:messages globalOnly="true" layout="table" />
<h:outputText id="esteTexto" value="#{ramSession.texto}" />
<br />
<h:commandButton action="#{ramSession.add}" styleClass="btn btn-default" value="#{ramSession.texto}">
</h:commandButton>
</h:form>
</h:body>
</f:view>
And here is my SessionScoped ManagedBean file, RamSession.java:
#ManagedBean
#SessionScoped
public class RamSession extends AbstractBaseBean implements Serializable {
private static final long serialVersionUID = 919724848720360000L;
private String texto;
public void add() {
this.texto = new String("Entrando");
}
#PostConstruct
public void postConstruct() {
this.texto = new String("Jereje");
}
public String getTexto() {
logger.info("gettingTexto");
addGlobalSuccessInfoMessage();
return this.texto;
}
public void setTexto(String texto) {
this.texto = texto;
}
}
I have also tried returning a String (even not necessary), with an actionListener method and even with ajax but nothing. Can anybody help me? Thanks a lot.
Maybe your mojarra listner is not configured correctly.
Follow one of the two following sub-steps
a. Add the liferay-faces-init.jar dependency in each Liferay JSF project by adding the following code to each pom.xml :
<dependency>
<groupId>com.liferay.faces</groupId>
<artifactId>liferay-faces-init</artifactId>
<version>3.1.3-ga4</version>
</dependency>
b. Add the following code in each WEB-INF/web.xml of all your JSF projects :
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
Why not initialize texto in the declaration?
private String texto = "Jereje";
public void addGlobalSuccessInfoMessage(){
//faces message
}
//Getter Setter
Then you can remove the entire PostConstruct method.
Also if all you want to do is set a string and update without navigation just use f:setPropertyActionListener with a f:ajax for updating your messages. You can use action if you want by returning null or void, or actionListener and set the string inside of that, but I'm not seeing why you'd want to. This link may help with those options... Answer by Balus C.
May want to remove any extra logic from your getter method as well. This won't affect your problem but it's cleaner and creating a success message on a getter seems problematic.
<h:form id="myForm">
<h:messages globalOnly="true" layout="table" />
<h:outputText id="esteTexto" value="#{ramSession.texto}" />
<br />
<h:commandButton value="#{ramSession.texto}" actionListener="#{ramSession.addGlobalSuccessInfoMessage()}" styleClass="btn btn-default">
<f:setPropertyActionListener value="Entrando" target="#{ramSession.texto}" />
<f:ajax render="myForm" />
</h:commandButton>
</h:form>
I want when user in not logged-in, after clicking the Add To Card button, the Login dialog should appears.
Here is Book.xhtml:
<h:form>
<p:commandButton value="Add To Card"
actionListener="#{booksBean.orderBook()}"
class="QtyBtn">
<f:ajax execute="#form" rendered="#form"/>
</p:commandButton>
</h:form>
This is bean:
#Component
#Scope("session")
public class BooksBean implements Serializable {
...
public void orderBook() {
...
if (currentUser == null) { // show the login dialog
RequestContext.getCurrentInstance().openDialog("Login");
}
But Login.xhtml not opened.
First, what you want to do is to use PrimeFaces Dialog Framework(DF).
DF let's you open XHTML view in a dialog
Add this to your faces-config.xml
<application>
<action-listener>
org.primefaces.application.DialogActionListener
</action-listener>
<navigation-handler>
org.primefaces.application.DialogNavigationHandler
</navigation-handler>
<view-handler>
org.primefaces.application.DialogViewHandler
</view-handler>
</application>
Create your login.xhtml page as
any XHTML page.
Add the corresponding outcome to your faces-config.xml. For example,
<navigation-case>
<from-outcome>Login</from-outcome>
<to-view-id>/pages/login.xhtml</to-view-id>
<redirect />
</navigation-case>
Open the dialog with RequestContext.getCurrentInstance().openDialog("Login");
Note that the DF opens the new dialog inside a frame.