JSF 2.0 composite components not working - jsf

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.

Related

Primefaces p:calendar not working under ui:composition

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.

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

Tomcat JSF Error

I'm building a page in JSF and am running it on Tomcat in Eclipse. Everything was working quite well until I started getting these errors everytime I try to load the page. The page looks wrong and the eclipse console shows me around 12 of errors like this one:
Dec 19, 2013 9:23:26 PM com.sun.faces.context.ExternalContextImpl getMimeType
WARNING: JSF1091: No mime type could be found for file /img/sep.jsp.
To resolve this, add a mime-type mapping to the applications web.xml.
The funny thing is that the file in this particular error isnt sep.jsp but sep.PNG...
<?xml version='1.0' encoding='UTF-8' ?>
<!-- index.xhtml -->
<!-- JSF page that displays the current time on the web server -->
<!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">
<h:head>
<title>WebTime: A Simple Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<h1>Current time on the web server: #{webTimeBean.time}</h1>
<img src="img/sep.png" alt="sep.png" style="width:200px; height:200px;
float:right;" />
</h:body>
</html>
its recommended to use only jsf TAGS and not mixing standard html and jsf.
a valid xhtml for jsf use should be somthing like this:
you don't need to declare xml at the top of your page!!!!
<!DOCTYPE html>
<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"
>
<h:head>
<meta charset="UTF-8" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="stylesheet.css"/>
<title>Test</title>
</h:head>
<body>
<f:view>
<h:outputText value="hello"></h:outputText>
<h:graphicImage name="img/sep.png" class="LOGO" alt="Image not found!"></h:graphicImage>
</f:view>
</body>
</html>
in your web.xml, check the Faces Servlet Pattern. it seems to me that tomcat tries to compile every file under / as jsf. so change your faces pathern and
try it and let me know if you still have the same "warning".

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.

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