JSF 2.0, "preRenderView" event handler called twice - jsf-2

I have the following snippet:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:metadata>
<f:event type="preRenderView" listener="#{workflowController.test}"/>
</f:metadata>
<h:head>
<title>Simple JSF Facelets page</title>
</h:head>
<h:body>
Hello, Place your content here
</h:body>
</html>
When I open the page, the WorkflowController.test() method is called twice (it's just a simple method which makes a log entry). Do you know why it's being called twice?
Thanks.

Try to put the <f:event/> tag outside of the <f:metadata>, it worked for me (mojarra 2.1.0).

Related

"Component Not Found for identifier <id>.getParent()" in facelets composite component

I migrated some of my facelets custom components into proper composite components, but encounters the following error while rendering a view that contains the composite component:
javax.faces.view.facelets.TagException: /WEB-INF/taglib/cctest.xhtml #15,26 <composite:interface> Component Not Found for identifier: bodyId.getParent().
at com.sun.faces.facelets.tag.composite.InterfaceHandler.validateComponent(InterfaceHandler.java:135)
at com.sun.faces.facelets.tag.composite.InterfaceHandler.apply(InterfaceHandler.java:125)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:320)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:379)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:326)
at com.sun.faces.facelets.tag.UserTagHandler.apply(UserTagHandler.java:142)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:187)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:188)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:164)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:906)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.jav
In the error message, the name bodyId refers to the id of <h:body> in the file below, and getParent() is hardcoded during the creation of the exception message. #15,26 refers to the end of <composite:interface> in cctest.xhtml below.
Here is the page that contains the composite component:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
xmlns:bam="http://bam.mycompany.com/jsftaglib"
>
<f:view locale="en" id="viewId">
<h:head id="headId">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Title</title>
</h:head>
<h:body id="bodyId">
<bam:cctest value="hello world."/>
</h:body>
</f:view>
</html>
Here is the file named cctest.xhtml that declares the composite component cctest:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html"
>
<h:head>
<title>not used</title>
</h:head>
<h:body>
<composite:interface>
<composite:attribute name="value" required="true"/>
</composite:interface>
<composite:implementation>
<h:outputText id="text_#{cc.attrs.value}" value="#{cc.attrs.value}"/>
</composite:implementation>
</h:body>
</html>
The composite component is declared in a file named bam.taglib.xml located in /WEB-INF/taglib/, next to cctext.xhtml. Here is the file:
<facelet-taglib 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-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://bam.mycompany.com/jsftaglib</namespace>
<tag>
<tag-name>cctest</tag-name>
<source>cctest.xhtml</source>
</tag>
</facelet-taglib>
I'm using mojarra 2.1.21 into tomcat 7.0.41. My faces-config.xml file is empty, there's no managed beans or other custom-defined components (validator, etc.). Web.xml only declares a few context param, plus the faces servlet mapped on *.xhtml; here are those context parameters:
javax.faces.FACELETS_REFRESH_PERIOD = 1
javax.faces.FACELETS_SKIP_COMMENTS = false
javax.faces.FACELETS_LIBRARIES = /WEB-INF/taglib/bam.taglib.xml
javax.faces.PROJECT_STAGE = Development
javax.faces.VALIDATE_EMPTY_FIELDS = false
javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL = true
Looking at the component tree that is displayed in the facelets error page, there's no element named bodyId, which might be a hint for my issue. A copy of which is displayed below:
<UIViewRoot id="j_id1" inView="true" locale="en" renderKitId="HTML_BASIC" rendered="true" transient="false" viewId="/pages/composite_component_test.xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<UIOutput id="headId" inView="true" rendered="true" transient="false">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Title</title>
</UIOutput>
</UIViewRoot>
Many thanks in advance for looking at this issue.
I have seen this type of error occur in Development mode when referencing a component from another component via an include e.g.
<composite:implementation>
<ui:include src="/resources/mycomponents/component1.xhtml" />
</composite:implementation>
Instead one should use appropriate JSF Component referencing syntax
e.g.
<mycomponents:component1/>
Strangely this error doesn't happen if one switches to Production mode and all works fine.

Dialog framework doesn't work

i am trying to apply the basic sample for rendering a page inside a dialog as in the showcase
http://www.primefaces.org/showcase/ui/dialogFrameworkBasic.jsf
my web pages are under webapp/pages/general
i am running PrimeFaces-4.0-SNAPSHOT on Mojarra-2.1.20
i have two pages:
1- home.xhtml
2- viewreport.xhtml
1- home.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:p="http://primefaces.org/ui"
xmlns:pretty="http://ocpsoft.com/prettyfaces"
xmlns:sec="http://www.springframework.org/security/tags"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>Welcome</title>
<h:outputStylesheet library="css" name="style.css" />
</h:head>
<h:body dir="rtl">
<h:form>
<p:commandButton value="View" icon="ui-icon-extlink"
action="dialog:viewreport" />
</h:form>
</h:body>
</html>
2- viewreport.xhtml:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:panelGroup id="report_details_new" layout="block" style="width:500px;height:500px;">
HELLO WORLD
</h:panelGroup>
</h:body>
</html>
when clicking on the button, nothing happens, i don't get any errors in eclipse console or in browser console.
please advise why the dialog framework is not working.
Solved by adding the following configuration to the faces-config.xml:
<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<view-handler>org.primefaces.application.DialogViewHandler</view-handler>
tested on IE9,Chrome,Firefox for primefaces 4.0-SNAPSHOT

JSF 2.0 and Primefaces with Facelets

I'm trying to incorporate primefaces into my JSF 2.0 web project.
I've recently updated from facelets 1.x to 2.0 and Added primefaces jar to my library folder. Everything is fine except, the way I have my templates structured has a conflict with the primefaces.
my template.xhtml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title><ui:insert name="title">MILO</ui:insert></title>
//Css
//js
</h:head>
<h:body class="milo">
<h:form styleClass="miloForm" enctype="multipart/form-data">
<div id="container">
<ui:insert name="header">
<ui:include src="/WEB-INF/templates/header.xhtml"/>
</ui:insert>
<ui:insert name="content">
<!-- include your content file or uncomment the include below and create content.xhtml in this directory -->
</ui:insert>
<ui:insert name="footer">
<ui:include src="/WEB-INF/templates/footer.xhtml"/>
</ui:insert> </div>
</h:form>
</h:body>
And my index.xhtml looked like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/WEB-INF/templates/base.xhtml">
<ui:define name="content">
<p:editor/>
</ui:define>
Once I have this, the p:editor won't show up. any ideas why? the console won't show me any warnings/errors.
EDIT>>> Found JS Error
In your template.xhtml, you need to replace <head> by <h:head> and <body> by <h:body>. You shouldn't add another ones, that would only result in invalid HTML.
Particularly the <h:head> is mandatory as it allows component libraries like PrimeFaces to auto-include the necessary CSS/JS files by resource dependency injection. The <h:body> is only mandatory whenever you have <h:outputScript> elements with a target="body" so that they will be auto-relocated to the very bottom of the generated HTML <body> element.
Update your concrete problem is caused by a conflict in the manually loaded jQuery library and the one which is auto-included by PrimeFaces. PrimeFaces uses jQuery and jQuery UI under the covers. If you stick to using PrimeFaces, I'd recommend to drop the manually loaded jQuery and use the PrimeFaces-bundled one instead. To cover pages where you don't use PrimeFaces components as well, you can explicitly load PrimeFaces-bundled jQuery for every page by adding the following line to the <h:head>:
<h:outputScript library="primefaces" name="jquery/jquery.js" />

why does a4j:poll just work one time when I use it in my jsf page which is ui:defined with a template .xhtml

I create a template xhtml file which is like richfaces-showcase main.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j">
<f:view contentType="text/html">
<h:head>
<!-- Mimic Internet Explorer 8 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>My title</title>
</h:head>
<h:body>
<div id="page">
<ui:insert name="body">
Body content missed
</ui:insert>
</div>
</h:body>
</f:view>
</html>
And in sub page, I defined the "template body", and add an a4j:poll in my sub page, which I want to use to refresh the data every 5 seconds:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:composition template="/templates/main.xhtml">
<ui:define name="body">
<h:form>
<a4j:poll id="poll" interval="5000" enabled="true" action="..." render="poll,grid" />
</h:form>
<h:form>
<h:panelGrid columns="2" width="80%" id="grid">
sorry, details forgot ...
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</html>
But the question is, when I open my sub page with IE8 in the localhost computer, the a4j:poll can refresh data once, and then it never get data again. when I open the sub page with IE6 or IE8 in other computer, it works fine! Can anybody find the reason out? Thanks in advance!!
I change the
<h:head>
<!-- Mimic Internet Explorer 8 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>My title</title>
</h:head>
to
<h:head>
<!-- Mimic Internet Explorer 7 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>My title</title>
</h:head>
and, it works now... but why?
I got it working with EmulateIE8. But probably when using it in an intranet way IE can be doing things differently.
Check your Browser mode and Document mode (press F12).
I got: IE9 / IE8 standards.

JSF .xcss styles not getting rendered

I'm using JSF2 and Richfaces 4.
I've added the following to my web.xml:
<mime-mapping>
<extension>xcss</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
I have an test.xcss file:
<?xml version="1.0" encoding="UTF-8"?>
<f:template xmlns:f="http:/jsf.exadel.com/template"
xmlns:u="http:/jsf.exadel.com/template/util"
xmlns="http://www.w3.org/1999/xhtml" >
<f:verbatim><![CDATA[
#content a:link[disabled]{ cursor: default;}
]]>
</f:verbatim>
<u:selector name="body">
<u:style name="background-color" skin="generalBackgroundColor" />
<u:style name="font-size" skin="generalSizeFont" />
<u:style name="font-family" skin="generalFamilyFont" />
</u:selector>
</f:template>
I load this test.xcss via my template.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
<f:view contentType="text/html">
<h:head>
<title>TEST</title>
<h:outputStylesheet library="css" name="test.xcss" />
</h:head>
<h:body>
</h:body>
</f:view>
</html>
Using firebug to view the content, the test.xcss is empty. Any ideas why it is not rendering the file correctly?
I suspect .xcss files are not supported in Richfaces 4, that ecss files are now used.
http://docs.jboss.org/richfaces/latest_4_0_X/Developer_Guide/en-US/html_single/#sect-Developer_Guide-Skinning_and_theming-What_are_skins
Found my answer:
http://community.jboss.org/wiki/RichFacesMigrationGuide33x-4xMigration-Skinning
.xcss not supported anymore, quite a bit of code migration to do now :(

Resources