Nested composite component broken in JBoss 7.1.1 - jsf-2

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>

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?

<ui:composition template="/template.xhtml"> Invalid path : /template.xhtml

Resource Library Contracts is not working on Weblogic 12.1.1. Wondering is it the version issue? Encounter the below error when try to access c1/index.xhtml
javax.faces.view.facelets.TagAttributeException: //seamnt/prd101/weblogic12_projects/testdomain/servers/testserver/stage/JavaWeb/JavaWeb/c1/index.xhtml #8,48 Invalid path : /template.xhtml
This is the war structure:
WEB-INF/faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.1"
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">
<application>
<resource-library-contracts>
<contract-mapping>
<url-pattern>/c1/*</url-pattern>
<contracts>c1</contracts>
</contract-mapping>
<contract-mapping>
<url-pattern>/c2/*</url-pattern>
<contracts>c2</contracts>
</contract-mapping>
</resource-library-contracts>
</application>
</faces-config>
contracts/c1/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 lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<h:outputStylesheet name="default.css"/>
<title><ui:insert name="title">c1 Template</ui:insert></title>
</h:head>
<h:body styleClass="body">
<h1><ui:insert name="h1">template.xhtml</ui:insert></h1>
<h:graphicImage url="#{resource['duke.handsOnHips.gif']}"
alt="Duke with hands on hips"/>
<ui:insert name="content"/>
</h:body>
</html>
c1/index.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 lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="/template.xhtml">
<ui:define name="title">c1 Index</ui:define>
<ui:define name="h1">index.xhtml</ui:define>
<ui:define name="content">
<h:form>
<div>Name: #{requestScopedBean.name}</div>
<label>Name:
<h:inputText id="username"
title="Name: "
value="#{requestScopedBean.name}"
required="true"
requiredMessage="Error: A name is required."
maxlength="25" />
</label>
<br/>
<h:commandButton id="submit" value="Submit"
action="index" />
<h:commandButton id="reset" value="Reset" type="reset" />
</h:form>
<div class="messagecolor">
<h:messages showSummary="true"
showDetail="false"
errorStyle="color: #d20005"
infoStyle="color: blue"/>
</div>
</ui:define>
</ui:composition>
</html>
Resource library contracts was introduced in JSF 2.2.
You're using only JSF 2.1. This is not only indicated by the fact that you're using version="2.1" in faces-config.xml, but also the fact that WebLogic 12.1.x has JSF 2.1 built-in.
Logically, you've 2 options:
Upgrade to JSF 2.2 (this means, upgrade to WebLogic 12.2.x).
Drop the idea of using resource library contracts. It's a rather useless feature anyway.
Last but not least, make sure your versions match the learning resources and that you catch up the currently available versions. Make sure you learn JSF the right way. Start here.

Updating p:graphicImage every n seconds

I was wondering if someone could either explain or point me to a good resource that will help me understand how to update a p:graphicImage in Primefaces 5.0. What I'm trying to do is pretty simple.
<p:graphicImage value="myImage.png"/>
The filename never changes, but it will be updated every n seconds. I'm trying to figure out the easiest way to update that image every n seconds. In this case we'll say every 5.
tyia
Update:
I've tried the suggestions below but poll isn't updating. I've tested this in IE, FF, and Chrome. I'm using the sample code on the prime faces. Here's my bean:
#ManagedBean
#ViewScoped
public class CounterView implements Serializable {
private int number;
public int getNumber() {
return number;
}
public void increment() {
System.out.println("test");
number++;
}
}
I'm outputting to the console to see if increment() is ever executed, which it isn't.
Here's my 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:p="http://primefaces.org/ui">
<h:head>
<title></title>
</h:head>
<h:body>
<h:form>
<p>Welcome, #{loginBean.uname}</p>
<p:commandButton action="#{loginBean.logout}" value="Logout" ajax="false"></p:commandButton>
<br/>
<h:form>
<h:outputText id="txt_count" value="#{counterView.number}" />
<p:poll interval="3" listener="#{counterView.increment}" update="txt_count" />
</h:form>
</h:form>
</h:body>
</html>
The above is the page that I'm redirecting to after a successful login. All output is correct except for txt_count....it stays at 0. I took the image out to get this working before applying it to the image update.
Update 2:
Got the int counter working
<?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:p="http://primefaces.org/ui">
<h:head>
<title></title>
</h:head>
<h:body>
<h:form>
<p>Welcome, #{loginBean.uname}</p>
<p:commandButton action="#{loginBean.logout}" value="Logout" ajax="false"></p:commandButton>
<br/>
<h:outputText id="txt_count" value="#{counterView.number}" />
<p:poll interval="3" listener="#{counterView.increment}" update="txt_count" />
</h:form>
</h:body>
</html>
You might use a poll component with a listener method that changes the image.
<p:poll interval="3" listener="#{your_method_to_change_the_image()}" update="myImage" />
<p:graphicImage id="myImage" value="myImage.png"/>
Disclaimer : Not tested.
According to Primefaces user guide p. 247 you can use a p:imageSwitch for a slideshow. For example:
p:imageSwitch effect="FlyIn">
<p:graphicImage value="/images/nature1.jpg" />
<p:graphicImage value="/images/nature2.jpg" />
<p:graphicImage value="/images/nature3.jpg" />
<p:graphicImage value="/images/nature4.jpg" />
</p:imageSwitch>
You can also set the speed. If I understand you correctly and you change the image serverside I guess you can just alternate between 2 images with the same url. If the browser reads the cached image instead of the updated one I think you can append the current date to the url.

PrimeFaces: commandButton's validateClient attribute's behaviour

In the following simple faces page, I am trying to instruct JSF to NOT to validate the input fields.
<?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:body>
<h:form id="createPatientForm_id">
<p:panelGrid columns="3">
<p:outputLabel value="First Name" />
<p:inputText id="firstNameInput_id" label="First Name" required="true" requiredMessage="First Name is required"/>
<p:message for="firstNameInput_id"/>
</p:panelGrid>
<p:commandButton value="Submit" ajax="false" validateClient="false" />
</h:form>
</h:body>
</html>
When I click on the 'Submit' button, validation does occur. Screen shot below:
I know I have configured required="true". But, shouldn't the validation be skipped as I have also specified validateClient="false"?
What am I missing here?
You need to use immediate="true", perhaps in addition to the Primefaces specific validateClient. Odds are you have disabled client side validation, but not the server side.

org.apache.jasper.JasperException: /JSP/BillingPayment.jsp(15,3) No tag "ajax" defined in tag library imported with prefix "f"

Have some doubt with JSF 2, I would like to use the ajax functionality of JSF 2 only, not going to use any of its implementations.
Have taken the JSF libraries from http://download.java.net/maven/2/com/sun/faces/jsf-api/2.1.1-b03/
But still none of these are supporting the ajax tag that I am using to implement the functionality.
I get the error
org.apache.jasper.JasperException: /JSP/BillingPayment.jsp(15,3) No tag "ajax" defined in tag library imported with prefix "f"
for the following request.
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
<body>
<h:form>
<h:panelGrid>
<h:inputText value="#{dataTableBean.sponsorID}">
<f:ajax event="keyup" />
</h:inputText>
<h:outputText id="text" value="#{dataTableBean.sponsorID}" />
</h:panelGrid>
</h:form>
</body>
</html>
For this I presume, I am not having the proper library, please can you give me the correct JSF2 library that supports ajax.
You have to use Facelets Technology. Your sth.xhtml will have this form
<?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">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<link rel="stylesheet" type="text/css" href="my.css" />
</h:head>
<h:body>
</h:body>
</html>
If you are using netbeans ide 7.1 when you are creating a jsf page check the faceletes option.
I had a similar question
h:outputScript not defined in library h.
Your link points to the jsf-api.jar. You need jsf-impl.jar as well which you can find in this directory.
If you have both in your classpath, you should be able to access the TLDs. I think there's no way to use jsf without a jsf-impl.jar.
Furthermore, you have to include all components tags on your page with the f:view tag. So your page should have the following structure:
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:view>
<html>
<body>
<h:form>
<h:panelGrid>
<h:inputText value="#{dataTableBean.sponsorID}">
<f:ajax event="keyup" />
</h:inputText>
<h:outputText id="text" value="#{dataTableBean.sponsorID}" />
</h:panelGrid>
</h:form>
</body>
</html>
</f:view>

Resources