Primefaces p:calendar not working under ui:composition - jsf

Iam using primefaces in my project and everything works fine except p:calendar component of Primefaces.The following xhtml file doesn't show up the calendar component.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/Templates/Commons/MainContent.xhtml">
<ui:define name="main_content">
<h:body>
<h:form>
<p:calendar value="#{controller.data}" pattern="dd/MM/yyyy" />
</h:form>
</h:body>
</ui:define>
</ui:composition>
However if I remove ui:compisition ,as the following snippet shows,it works fine.
<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:p="http://primefaces.org/ui">
<h:body>
<h:form>
<p:calendar value="#{controller.data}" pattern="dd/MM/yyyy" />
</h:form>
</h:body>
</html>
Is there anything I should know about ui:compisition and p:calendar?

I think that if you use this template it may helps you
<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:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/WEB-INF/Templates/Commons/MainContent.xhtml">
<ui:define name="main_content">
<h:body>
<h:form>
<p:calendar value="#{controller.data}" pattern="dd/MM/yyyy" />
</h:form>
</h:body>
</ui:define>
</ui:composition>
</html>
follow this structure.

Related

jsf <f:metadata> tag not inserted on template

This works:
template.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html" encoding="UTF-8" locale="#{LanguageBean.localeLanguage}">
<f:metadata>
<f:viewParam name="token" value="#{changePasswordBean.token}"/>
<f:viewAction action="#{changePasswordBean.checkValidToken}" />
</f:metadata>
But this (based on this example) does not (token is always null):
template.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html" encoding="UTF-8" locale="#{LanguageBean.localeLanguage}">
<ui:insert name="metadata" />
page.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">
<ui:composition template="template.xhtml"
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"
>
<html>
<ui:define name="metadata">
<f:metadata>
<f:viewParam name="token" value="#{changePasswordBean.token}"/>
<f:viewAction action="#{changePasswordBean.checkValidToken}" />
</f:metadata>
</ui:define>
Why?
I've got the same example working in my project code (Mojarra 2.1.29), so it must be an implementation issue. Your current JSF implementation was released more than three years ago and lots of problems have been solved since then. I recommend you to go at least with the latest 2.1.x available or to switch to 2.2.x if it's a new project. Also, you're using f:viewAction, which is a JSF 2.2 specific feature and simply won't properly work with your JSF implementation version.
See also:
f:viewAction feature

JSF TinyMCE Composite Component not working?

I have created a TinyMCE Composite Component
Steps which i did
1- Added tinymce folder provided by TinyMCE in resource directory of the project.
2- Then created another folder editors in resource directory and created two file one is js file tinymce_init.js and code is
tinyMCE.init({
mode : "specific_textareas",
theme : "simple",
debug : true,
editor_selector : "tinymce"
});
and another file tinymce.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<ui:component 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:composite="http://java.sun.com/jsf/composite"
xmlns:pe="http://primefaces.org/ui/extensions">
<composite:interface>
<composite:attribute name="value" />
</composite:interface>
<composite:implementation>
<h:outputScript library="tinymce" name="tinymce.js" target="head" />
<h:outputScript library="editors" name="tinymce_init.js" target="head" />
<h:inputTextarea rows="5" cols="80" />
</composite:implementation>
</ui:component>
3- Now access this composite component into my xhtml file something like this
<?xml version="1.0" encoding="UTF-8"?>
<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:editors="http://java.sun.com/jsf/composite/editors">
<h:head>
<title>test</title>
</h:head>
<h:body>
<editors:tinymce />
</h:body>
</html>
But when i access this file i saw a input box without any toolbar , what i am doing wrong and JS is loaded properly without any error in browser console.

The metadata component needs to be nested within a f:metadata tag. Suggestion: enclose the necessary components within <f:metadata>

I went through different sources like:
Error saying I need to use f:metadata even though I do
http://docs.oracle.com/javaee/7/javaserverfaces/2.2/vdldocs/facelets/f/metadata.html
and it seems to be issue has been fixed in jsf 2.2.1, where as When I tried to use, I am facing issue, below are my configurations:
template.xhtml:
<!DOCTYPE html>
<html lang="#{languageBean.language}"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<!-- Enables CTRL+SHIFT+D for activating Facelets debug window -->
<ui:debug />
<f:view locale="#{languageBean.language}" encoding="UTF-8" contentType="text/html">
<!-- Client templates can insert f:metadata here, and this will NOT show up in the showcase page source code -->
<ui:insert name="meta" />
<c:set var="contextPath" value="${pageContext.request.contextPath}"
scope="application" />
<f:loadBundle var="messageResource" basename="MessageResource" />
<h:head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible"
content="EmulateIE8,IE=edge,chrome=1" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Connect" />
<meta name="keywords"
content="timeline, 3d, css, css3, css-only, transitions, responsive, fluid" />
<meta name="author" content="FriendsMirror" />
<link rel="shortcut icon"
href="#{request.contextPath}/Friendsmirror.ico" />
<ui:insert name="js"/>
<h:outputStylesheet library="css" name="common.css" />
<h:outputStylesheet library="css" name="main.css" />
<ui:insert name="css"/>
<ui:insert name="onloadScript"/>
<title><ui:insert name="title">#{messageResource['connect.main.title.main.title']}</ui:insert></title>
</h:head>
<h:body>
<ui:insert name="content" />
</h:body>
</f:view>
</html>
Page:
<ui:composition template="/WEB-INF/templates/discussion_layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<ui:define name="meta">
<f:metadata>
<f:viewParam name="sessionKey" value="#{discussionWrapperBean.sessionKey}" />
<f:viewParam name="ref" value="#{discussionWrapperBean.ref}" />
<f:viewParam name="pId" value="#{discussionWrapperBean.pId}" />
<f:viewParam name="dId" value="#{discussionWrapperBean.discussionId}" />
<f:viewParam name="dName" value="#{discussionWrapperBean.discussionName}" />
<f:viewAction action="#{discussionWrapperBean.loadInitDiscussion}" onPostback="false" />
</f:metadata>
</ui:define>
<ui:define name="title">
<ui:fragment rendered="#{discussionWrapperBean.profileId != null}">
#{discussionWrapperBean.userBean.firstName} #{discussionWrapperBean.userBean.lastName != null ? discussionWrapperBean.userBean.lastName: ''}#{discussionWrapperBean.pageTitleNotifications != null ? '(' : ''}#{discussionWrapperBean.pageTitleNotifications != null ? discussionWrapperBean.pageTitleNotifications : ''}#{discussionWrapperBean.pageTitleNotifications != null ? ')' : ''}
</ui:fragment>
<ui:fragment rendered="#{discussionWrapperBean.profileId == null}">
#{messageResource['connect.discussion.title']}
</ui:fragment>
</ui:define>
<ui:define name="content">
</ui:define>
</ui:composition>
Maven:
<jsf.version>2.2.1</jsf.version>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf.version}</version>
<scope>provided</scope>
</dependency>
In Ui I am getting issue like:The metadata component needs to be nested within a f:metadata tag. Suggestion: enclose the necessary components within <f:metadata>
even its not calling the <f:viewAction>
Any Suggestion or help will be appreciated.
One thing I noticed during deployment:
INFO: Initializing Mojarra 2.2.0 ( 20130502-2118 https://svn.java.net/svn/mojarra~svn/tags/2.2.0#11930) for context /connectWAR
I am not sure why this is telling Mojarra 2.2.0, even though I have upgraded to 2.2.1
As to the false UI warning, this is caused by Mojarra issue 2868 and already fixed since 2.2.1.
As to the <f:viewAction> still not working on 2.2.1, another Mojarra bug with the since Java EE 7 introduced xmlns.jcp.org XML namespace domain is causing this trouble. In specifically Mojarra versions 2.2.0 and 2.2.1 the new XML namespace domain is not properly registered for all new JSF 2.2 specific tags which didn't exist in JSF 2.0/2.1, such as <f:viewAction>. In effects, the xmlns.jcp.org will give you in Mojarra 2.2.0/2.2.1 only the JSF 2.1 compatible tags back. This totally explains why the new JSF 2.2 <f:viewAction> didn't work for you.
You have 2 options:
Use the "old" java.sun.com XML namespace domain instead. The new JSF 2.2 specific tags are properly registered there.
Upgrade to at least Mojarra 2.2.2. This peculiar bug is fixed since that version. Mojarra is currently already at 2.2.4.

JSF 2.0 composite components not working

I wanted to introduce CCs in my project. I am running Java EE 6 on JBoss 7.1.1.
/myProj/src/main/webapp/composites/scheda.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="prod" />
</composite:interface>
<composite:implementation>
Hello!
</composite:implementation>
</html>
/myProj/src/main/webapp/someDir/page.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:composites="http://java.sun.com/jsf/composite/composites"
template="/templates/default.xhtml">
<ui:define name="content">
<p:dialog
header="Scheda"
widgetVar="schedaDialog"
id="schedaDialogId">
<composites:scheda prod="test" />
</p:dialog>
</ui:define>
</ui:composition>
This results in:
javax.servlet.ServletException: /.../page.xhtml
Tag Library supports namespace:
http://java.sun.com/jsf/composite/composites, but no tag was defined
for name: scheda
Some bug?
You didn't put your xhtml of composite component in the right place. As I can see you are using Maven so proper path to your composite component should be:
/myProj/src/main/webapp/resources/composites/scheda.xhtml
resources is the folder where JSF looks for composite components.

PrimeFaces components are not recognized and don't render

I just added PrimeFaces 3.0 to a JSF project:
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.0</version>
</dependency>
And I created this test page:
<!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.prime.com.tr/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</h:head>
<h:body>
<h:form>
<p:panel header="F.C. Barcelona" footer="Visca el Barca!">
<h:outputText value="FC Barcelona " />
</p:panel>
<h:outputText id="name" value="#{facesBean.name}" /> <h:commandButton value="Submit" action="#{facesBean.callService()}" />
</h:form>
</h:body>
</html>
But the <p:panel> component is not rendered. Only the <h:xxx> components are properly rendered.
I have PrimeFaces jar in Maven dependecies and in the target folder. I'm using Tomcat 7. PrimeFaces doesn't need any additional configuration, right?
xmlns:p="http://primefaces.prime.com.tr/ui"
This XML namespace is for PrimeFaces 2.x only. Since PrimeFaces 3.0, the new XML namespace is
xmlns:p="http://primefaces.org/ui"
Make sure that you're reading documentation/tutorials concerning PrimeFaces 3.0, not 2.x.

Resources