JSF2.0 Composite Component not getting rendered in MYFaces - jsf-2

I developed a sample project to test composite components in JSF2.0.
Here is my sample code
My test file
<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:composite="http://java.sun.com/jsf/composite"
xmlns:tp="http://java.sun.com/jsf/composite/test"
>
<h:body>
<h:form>
<h:outputLabel value="Success"/>
<tp:loginComponent
usernameLabel="Enter User Name: "
usernameValue="#{login.name}" />
</h:form>
</h:body>
<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:composite="http://java.sun.com/jsf/composite"
>
<composite:interface>
<composite:attribute name="usernameLabel" />
<composite:attribute name="usernameValue" />
</composite:interface>
<composite:implementation>
<h:form>
#{cc.attrs.usernameLabel} :
<h:inputText id="username" value="#{cc.attrs.usernameValue}" />
</h:form>
</composite:implementation>
When I deploy it on Websphere 8.5 the composite component is not getting rendered.Please help me identify the issue
Thanks

You have to adjust the location and name of the file. Otherwise JSF won't find it.
The line
xmlns:tp="http://java.sun.com/jsf/composite/test"
Points JSF to the folder resources/test (relative to the root of your web pages). Assuming WebContent is the root for your webpages the resources folder should be inside that.
When JSF sees <tp:loginComponent .... /> it is going to look in the folder for a file called loginComponent.xhtml.
EDIT
Because there can be many kinds of resources in your resources folder it is best to create a subfolder for components. I usually call it comps. So that would give you the path
/WebContent/resources/comps place in this folder a file named loginComponent.xhtml with your component.
Change the namespace line to: xmlns:tp="http://java.sun.com/jsf/composite/comps" (that comps is in resources is implied but not specified in the URL).
See also the java ee tutorial.

Related

Using additional components as a parameter to `<ui:include>` [duplicate]

I have 2 basic templates - one with a side menu, and one without - that both ui:include a common page which contains ui:insert tags (templates are largish, so basic example below).
Using Mojarra everything worked ok, but now I have migrated to MyFaces the ui:insert tags are ignored and the content of the related ui:define does not get rendered (i.e. 'Here are my results' is not displayed).
Should I be specifying included-page.xhtml as a template somehow? I tried
<ui:composition template="included-page.xhtml" />
instead of
<ui:include src="included-page.xhtml" />
but lost the CSS.
Hoping someone can suggest a solution :)
Many thanks,
Neil
my-page.xhtml
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="/templates/default-template.xhtml">
<ui:param name="title" value="My Title" />
<ui:define name="results">
Here are my results
</ui:define>
</ui:composition>
default-template.xhtml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<title>#{title}</title>
</h:head>
<h:body>
<ui:include src="included-page.xhtml" />
</h:body>
</html>
included-page.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:insert name="results">
</ui:insert>
</ui:composition>
The <ui:include> should have been an <ui:decorate>.
<ui:decorate template="included-page.xhtml" />
But if the included-page.xhtml is by itself not reused elsewhere, I wonder why it isn't just been inlined in the master template instead.
See also:
Difference between ui:composition and ui:decorate in Facelets
What is the real conceptual difference between ui:decorate and ui:include?

PrimeFaces based application with PicketLink does not show style in login page

I developed a PrimeFaces based application that I now want to protect with PicketLink in a CDI way. I followed this example and created a login page with several PrimeFaces components including a layout). All styling and functionality is however lost. Even a simplified login.xhtml page (to match the example linked to above) does not have styling.
<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:head/>
<h:body>
<p:panel>
<h:form method="POST" prependId="false">
<p:inputText id="j_username" />
<p:password id="j_password"/>
<p:commandButton id="login" value="Login" action="#{identity.login()}" ajax="false"/>
</h:form>
</p:panel>
<p>Tip: you can login with a username/password of jane/abcd1234.</p>
</h:body>
</html>
The reason the css and js files are not loaded is because the security 'profile' in the original example has all resources protected besides a login.xhtml file. JSF by default loads resources from the 'virtual' javax.faces.resource folder. This needs to be excluded from authentication to. The HttpSecurityConfiguration in the original example should be adapted to exlude this virtual folder in the config.
public class HttpSecurityConfiguration {
public void onInit(#Observes SecurityConfigurationEvent event) {
SecurityConfigurationBuilder builder = event.getBuilder();
builder
.http()
.forPath("/javax.faces.resource/*")
.unprotected()
.forPath("/index.jsf")
.unprotected()
.allPaths()
.authenticateWith()
.form()
.authenticationUri("/login.jsf")
.loginPage("/login.jsf")
.errorPage("/error.jsf")
.restoreOriginalRequest()
.forPath("/logout")
.logout()
.redirectTo("/index.jsf");
}
}

PrimeFaces tags not recognised

I am new to JSF and Primefaces and have created a project with JSF2.0, Glassfish v3.0 and Jdk 6.0.Now want to use Primefaces tags instead of JSF tags.
I have downloaded primefaces-3.5.jar and added it into WEB-INF/lib folder and it well recognized into my *.xhtml pages.
But when I try to run the application it does not recognizes the PrimeFaces tags.
for Example:
if I insert:
<p:inputText id="username" validator="#{regBean.username}" required="true" requiredMessage="Please enter Username"/>
instead of:
<h:inputText id="username" value="#{regBean.username}" required="true" requiredMessage="Please enter Username!"/>
it does not show the input box in the Web Application.
Do I need to include any configuration details in web.xml file?
please suggest!!
Try something like
<?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:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:editor></p:editor>
</h:form>
</h:body>
</html>
Also make sure you have primefaces.jar in your path.

Nested composite component broken in JBoss 7.1.1

We use composite components inside other components in our project. Everything works just fine on JBoss 7.1.0, but on JBoss 7.1.1 we get errors like this:
No handlers found for exception javax.faces.view.facelets.TagException:
/resources/components/my/bigComponent.xhtml #21,47 <my:nestedComponent>
Tag Library supports namespace: http://java.sun.com/jsf/composite/components/my,
but no tag was defined for name: nestedComponent
We tried the solution suggested in this JBoss community thread, but it changed nothing to our problem (seams we're not the only one in this case, and the solution may not work because we're also in a ui:define tag from a template file).
Here our two components:
The nesting:
<!DOCTYPE html PUBLIC ...>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:my="http://java.sun.com/jsf/composite/components/my" >
<cc:interface componentType="...">
<h:panelGroup>
<cc:attribute name="someAttribute" />
</h:panelGroup>
</cc:interface>
<cc:implementation>
<my:nestedComponent content="a text" />
</cc:implementation>
</html>
The nested:
<!DOCTYPE html PUBLIC ...>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface>
<cc:attribute name="content" />
</cc:interface>
<cc:implementation>
<h:outputText value="#{cc.attrs.content}" />
</cc:implementation>
</html>
Is it a regression? Are we doing something wrong ? In the 1st link, the suggested solution implies in the nesting component something like this:
<composite:interface>
<composite:facet name="greet1"/>
<composite:facet name="greet2"/>
</composite:interface>
<composite:implementation>
<lib:greet1 name="Stan" />
<lib:greet2 name="Silvert" />
</composite:implementation>
What are this composite:facet without any composite:renderFacet for?
Valentinx in this thread found a workaround.
The idea is to put the faulty namespace declarations on the <composite:implementation> itself, so
<!DOCTYPE html PUBLIC ...>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:my="http://java.sun.com/jsf/composite/components/my" >
<cc:interface />
<cc:implementation>
<my:nestedComponent content="a text" />
</cc:implementation>
</html>
becomes
<!DOCTYPE html PUBLIC ...>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite" >
<cc:interface />
<cc:implementation xmlns:my="http://java.sun.com/jsf/composite/components/my">
<my:nestedComponent content="a text" />
</cc:implementation>
</html>
(notice the <cc:implementation xmlns:my="http://java.sun.com/jsf/composite/components/my"> tag)
This works like a charm!
Thanks to Xavier for the answer: that is right on! I wanted to add comment, but don't have rep. to do that.
In my case, the problem is a little difference, with error on template (not in composite:implementation), and I found a solution that does not include <cc:implementation> ...
Instead, moved xmlns:layoutComp in template from <html> to a container (both 'div' and 'span' worked):
<span xmlns:layoutComp="http://java.sun.com/jsf/composite/layoutComp">
<layoutComp:navigation />
</span>

ui:include src attribute's EL is resolved to null in composite component

I have composite component as below:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core">
<cc:interface>
<cc:attribute name="path" shortDescription="Page Title" type="String"/>
</cc:interface>
<cc:implementation>
<ui:include src="#{cc.attrs.path}"/>
</cc:implementation>
</html>
Problem with above code is #{cc.attrs.path} is resolved to null. If src is hardcoded then ui:include works fine.
Tried checking #{cc.attrs.path} with h:outputText and path is displayed correctly, that means only in case of ui:include EL is not resolved. Any help?
This code works just fine on my computer. The EL is resolved in any case, but I think the include failed because the file you try to include is malformed, or does not exist.
Maybe you could tell us what kind of file you try to include, and then give us a portion of this file ?

Resources