JSF Primefaces navigation rules - jsf

I copied someone elses JSF project since I could not get the IntelliJ maven archetypes to download. Anyways that projects was functioning but did not contain a faces-config so I added it manually into the project folder:
+
+-WebContent
+--WEB-INF
+---faces-config.xml
+---web.xml
The faces config looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-action>#{loginBean.performLogin}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/home.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
That is the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Primefaces-Dashboard-Sample</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
And this is the button within the form:
<p:commandButton id="loginButton" action="#{loginBean.performLogin}"
value="send" ajax="true" style="float: right;">
</p:commandButton>
However I get the weird behavior that the page is not redirect rather the form content gets replaced by the content of home.xhtml. Using the standard commandButton however everything works as expected.
Is there any way to get this to work with primefaces?

Related

WARNING: JSF1074: Managed bean named 'bean' has already been registered

I'm using mojarra JSF 2.2.
The beans that we have defined are anotation based eg.
#ManagedBean(name = "codeBean")
#ViewScoped
public class CodeRuleBean implements Serializable
I am using tomcat 7.0.53 to deploy the same. However, I am getting a warning that says
WARNING: JSF1074: Managed bean named 'codeBean' has already been registered. Replacing existing managed bean class type com.myclass.rule.ui.CodeRuleBean with com.myclass.rule.ui.CodeRuleBean.
There is none in faces-config.xml. I am using faces-config.xml only to define the navigation rules.
<?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>
<navigation-handler>com.configurator.application.navigator.MyNavigator</navigation-handler>
</application>
<navigation-rule>
<navigation-case>
<from-outcome>codeRulePage</from-outcome>
<to-view-id>/pages/rule/shortCodeMain.xhtml
</to-view-id>
<redirect />
<to-flow-document-id />
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/pages/rule/shortCodeMain.xhtml</from-view-id>
<navigation-case>
<from-outcome>successPage</from-outcome>
<to-view-id>/pages/rule/successCodeRule.xhtml
</to-view-id>
</navigation-case>
</navigation-rule>
</<faces-config>
Here is the web.xml, it does not contain any web listeners.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>MyWeb</display-name>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<filter-mapping>
<filter-name>cachePreventionFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
How is this caused and how can I solve it?
I think you have registered multiple listener for jsf space. Check it out. If you have com.sun.faces.config.ConfigureListener in your web.xml remove it.
Because com.sun.faces.config.FacesInitializer registers com.sun.faces.config.ConfigureListener on onStartup method.

Redirect from index.jsp welcome file to map.xhtml JSF page

I am try to make a my first jsf2 project run on jboss7.1
I want to redirect from the index.jsp to map.xhtml
that's what I try in my index.jsp and all of them didn't work please help
<%=response.sendRedirect("map.html") %>
<%=response.sendRedirect("/map.html") %>
<%=response.sendRedirect("map.xhtml") %>
<%=response.sendRedirect("/map.xhtml") %>
<%=response.sendRedirect("map.jsf") %>
<%=response.sendRedirect("/map.jsf") %>
and this is my faces-config.xml
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns /javaee /web-facesconfig_2_1.xsd"
version="2.1">
</faces-config>
this is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee /web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com /xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>myproject</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Don't do it the hard way.
Change
<url-pattern>*.jsf</url-pattern>
to
<url-pattern>*.xhtml</url-pattern>
and change
<welcome-file>index.jsp</welcome-file>
to
<welcome-file>map.xhtml</welcome-file>
This way map.xhtml becomes the welcome file and you can now stop fiddling with virtual URLs like .jsf and as a bonus, you can get rid of the legacy JSP file altogether.

JSF 2.0 FileNotFoundException

getting the below exception when accessing http://localhost:8081/ReportGeneratorJSF/
com.sun.faces.context.FacesFileNotFoundException: /login.xhtml Not Found in ExternalContext as a Resource
I am using JSF 2.0
i have created a login.xhtml inside WEB-INF folder which is using templates of header.xhtml and footer.xhtml using basictemplate.xhtml
// login.xhtml
<ui:composition template="/WEB-INF/template/basictemplate.xhtml">
...
textboxs and submit button
...
</ui:composition>
// web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ReportGeneratorJSF</display-name>
<welcome-file-list>
<welcome-file>faces/login.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Can you please provide solution for it.
You have a problem in your files, you need to place them like this :
WEB-INF
- faces-config.xml
- web.xml
login.xhtml
header.xhtml
footer.xhtml
...

Error with namespaces trying to configure JSF

I am getting the following error when trying to publish to my server. I have downloaded apache myfaces 2.0. I have also added these as a library in eclipse and added the project facet for JSF 2.0.
Caused by: org.apache.xmlbeans.XmlException: Invalid deployment
descriptor: errors:
jar:file:/C:/DOCUME~1/shawt/LOCALS~1/Temp/geronimo-deployer7810915779003395233.tmpdir/Scout.war!/WEB-INF/faces-config.xml:2:1:
error: cvc-enumeration-valid: string value '2.0' is not a valid
enumeration value for faces-config-versionType in namespace
http://java.sun.com/xml/ns/javaee
Here is my faces-config:
<?xml version="1.0"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<navigation-rule>
<from-view-id>menu.jsp</from-view-id>
<navigation-case>
<from-action>#{pageController.processPage1}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>test.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Scout</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>

JSF - First steps into this framework. What is wrong on this configuration?

Im making an easy application just to test the JSF framework.
This is actually web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
and faces.config.xml :
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config>
<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>avanti</from-outcome>
<to-view-id>/pagina1.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>utente</managed-bean-name>
<managed-bean-class>myPack.user</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
but unfortunatly it doesnt work :
Error 404
description The requested resource (/JSFTutorial/) is not available.
and of course my pages are :
Source Package/myPack/user.java
Web Pages/index.jsp and Web Pages/pagina1.jsp
Any idea? What im wrong? Bye
Here,
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
you've configured the FacesServlet to hook on requests matching the url-pattern of *.faces. So, to open for example index.jsp, you have to open it by http://example.com/context/index.faces.
And here,
<welcome-file-list>
<welcome-file>faces/index.jsp</welcome-file>
</welcome-file-list>
you've configured the welcome-page to listen on the wrong URL. Make it /index.faces.
By the way, *.jsf is a more common URL pattern. I'd also suggest to lookup for bit more recent tutorials/books targeting JSF 2.0. JSF 1.1 is already over 6 years old and things have changed a lot.

Resources