JSTL xmlns namespace differences between JSF 1.2 and JSF 2.x? - jsf

I have a JSF 1.2 based webapp from which I copied the JSTL import
xmlns:c="http://java.sun.com/jstl/core"
You can also find this import in many places on the Internet. I can't remember whether the above worked in my former web project or not, in any case, it does not work in my current JSF 2.0 based webapp. I got a warning from the container saying:
Warning: This page calls for XML namespace http://java.sun.com/jstl/core declared with prefix c but no taglibrary exists for that namespace.
I then changed the import to
xmlns:c="http://java.sun.com/jsp/jstl/core"
... which removed all headaches using <c:forEach> in a JSF/RichFaces-based webapp.
What's the trick here? Have there been any changes to the JSTL import URL from JSF 1.2 to 2.x? Or is the former line generally wrong (in JSF)? What's the difference between the two?

Check our JSTL wiki page: https://stackoverflow.com/tags/jstl/info You can get this kind of page whenever you hover the jstl tag below your question until a black box pops up and then click the info link.
It is true that Facelets 1.x and 2.x uses different namespaces for the JSTL tag library. It was less or more a namespace bug in Facelets 1.x and has been fixed for Facelets 2.x.
The real JSTL 1.0 taglib uses the URI http://java.sun.com/jstl/core.
The real JSTL 1.1/1.2 taglib uses the URI http://java.sun.com/jsp/jstl/core.
Facelets 1.x uses the URI http://java.sun.com/jstl/core.
Facelets 2.x uses the URI http://java.sun.com/jsp/jstl/core.
Facelets 2.2+ uses the URI http://xmlns.jcp.org/jsp/jstl/core.
You can find all Facelets 2.x tags in the Facelets tag library documentation. Facelets don't ship with the full tag set as the real JSTL taglib. Only a few of the <c:xxx> and the full set of <fn:xxx> are copied into Facelets. The <fmt:xxx>, <sql:xxx> and <xml:xxx> tags are not taken over in Facelets.

JSTL is now part of EL.
It is not dependent on JSF implementation but depends on what servlet version your servelet container is compliant for.So these must be running of different servers or different versions of same server.
Short answer is from 2.4 upwards which jboss 7 is .
If you go through JSTL doc here you will find out any way.
Other wise here is good link.
And an other one here from BalusC.

Related

How do I determine in which JSF version a tag was added?

I am in the process of upgrading an old web application from MyFaces 1.1 to version 2.2. I am new to JSF and still have a lot to learn about it (struggling a lot along the way). Because of this I often don't understand why a specific tag was used from some 3rd party tag library instead of the core JSF libraries.
For example, the application uses the t:stylesheet tag from the Tomahawk component library in the head of the page even though there seems to be a h:outputStylesheet tag in the html library of JSF.
I was wondering if the outputStylesheet tag wasn't available in JSF 1.1 and was only added later or if there is another reason for choosing the Tomahawk tag over the JSF html tag.
Is there a way to determine which version of JSF added a specific tag to the core libraries? Apart from replacing the "2.1" in http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/h/outputStylesheet.html until I reach a the URL that isn't available?

Which XML namespace to use with JSF 2.2 and up

I have migrated my application from JSF 1.2 to 2.2.
It used XML namespaces on java.sun.com domain like xmlns:f="http://java.sun.com/jsf/core". However, Oracle's Java EE 7 tutorial is using XML namespaces on xmlns.jcp.org domain like
xmlns:f="http://xmlns.jcp.org/jsf/core".
Which one is recommended and why was this changed?
Which one is recommended?
Go ahead with XML namespaces on xmlns.jcp.org domain. This was newly introduced since Java EE 7 in 2013 (which covers a.o. JSF 2.2, Servlet 3.1, CDI 1.1, etc). Do note that this not only affects Facelets files, but also XML configuration files such as faces-config.xml, web.xml, beans.xml, etc.
The old XML namespaces on java.sun.com are still there for backwards compatibility, but the support will eventually disappear in a future Java EE version. You should migrate your code base as soon as you can. It should be a trivial task using "find and replace in all files" facility offered by the average IDE.
Only older Mojarra 2.2.0 / 2.2.1 versions have had bugs related to the XML namespace changes, but those should not manifest in newer versions. See also a.o.
Using new xmlns.jcp.org namespace on composites causes java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.putIfAbsent
f:viewParam doesn't pass required parameter when new xmlns.jcp.org namespace is used
The metadata component needs to be nested within a f:metadata tag. Suggestion: enclose the necessary components within <f:metadata>
and why was this changed?
Because Java is not from Sun anymore since 2010. Note that they were smart to not make it java.oracle.com or something tight coupled to the currently owning company. It's now nicely and independently tied to the JCP (Java Community Process), the one really responsible for managing the Java (EE) specifications.
I made a brief summary of all the new official oracle namespaces:
<!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://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<!-- Content here -->
</html>
I use this as template for all of my .xhtml files. Details can be found in the official facelet tag library: JavaServer Faces 2.2 Facelets Tag Library Documentation
Hope this helps :)
For future visitors having namespace confusion/issue:
I would like to highlight the general way to find out which namespace to use:
If you want to use tags from JSF HTML tag library or JSF core tag library then open the JSF implementation JAR (like Oracle Mojarra, Apache MyFaces- myfaces-impl-2.3.1.jar) and find the tag library's .tld or .xml file (you can find it under META-INF directory) and use the namespace mentioned over there.
If you want to use the RichFaces or PrimeFaces then open their implementation JAR (like richfaces-components-ui-4.0.0.Final.jar, or primefaces-6.2.jar) and do same thing as above.
If implementation has .tld (like rich.tld) then you can use the value of <uri> element for example <uri>http://richfaces.org/rich</uri>. And if implementation has .xml (like rich.taglib.xml) then you can use the value of <namespace> element for example <namespace>http://richfaces.org/rich</namespace>
What I have mentioned above is strictly related to JSF but holds good in general as well. Key thing is that if you use the namespace from the implementation JAR then you will never run into issues.

Tag Library supports namespace: https://ajax4jsf.dev.java.net/ajax, but no tag was defined for name: support

When I tried to add <a4j:support> tag to JSF 2.0, I got the following error
Tag Library supports namespace: https://ajax4jsf.dev.java.net/ajax, but no tag was defined for name: support
How is this caused and how can I solve it?
The namespace URI https://ajax4jsf.dev.java.net/ajax is recognizable as the one from Ajax4jsf 1.x which existed in the prehistory, long before Ajax4jsf was acquired by RichFaces 3.x at 2006. Ajax4jsf 1.x is an ancient tag library which was targeted at JSF 1.1 on JSP, long before JSF 2.0 was introduced with builtin ajax functionality.
Even more, currently with JSF 2.0, JSP is deprecated and succeeded by Facelets (which a lot of starters overgeneralize as "XHTML"). JSP targeted tag libraries like Ajax4jsf 1.x are not compatible with Facelets. You basically need a JSF 2.0 compatible tag library instead. If you're looking for Ajax4jsf functionality, then you should be looking for RichFaces 4.x. Note that <a4j:support> has since RichFaces 4.x been renamed to <a4j:ajax> to be in line with JSF 2.0 standard <f:ajax>.
However, as said, JSF 2.0 thus already offers builtin ajax functionality in flavor of <f:ajax>. Given that you're attempting to use Ajax4jsf 1.x on JSF 2.0, you were perhaps reading a hopelessly outdated JSF book/tutorial/resource. I strongly recommend to put that aside and look for a more recent one, preferably not older than 2010 if you want a JSF 2.0 targeted one. You can find several sane tutorials linked somewhere in the bottom of our JSF wiki page.
Good luck.

How get Tomahawk functionality with JSF 2.0 (Glassfish V3)

I've started to upgrade an existing application written with JSF 1.1 and MyFaces Tomahawk 1.1 to JSF 2.0 to get facelets etc.
I've now run into the snag that apparently Tomahawk is not JSF 2.0 compatible as it expects the stand-alone version of Facelets instead of the built-in to JSF 2.0 with the following error:
org.apache.catalina.LifecycleException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! com.sun.facelets.tag.jsf.ComponentHandler
(it appears to be placed in javax.faces.view.facelets now).
I have looked around and there doesn't seem to be a JSF 2.0 facelet compatible version of Tomahawk. I only believe I need t:updateActionListener (inside t:dataTable) and the rowSpan facility of t:panelGroup. Is all this functionality available in JSF 2.0 directly, or must I locate a new library giving this?
Any suggestions?
The t:updateActionListener is covered by the JSF 1.2 f:setPropertyActionListener.
For rowspans (and colspans) there's unfortunately still no functionality in the standard JSF implementation. However, since JSF 1.2 you're allowed to write down "plain vanilla" HTML in the view without any pains (no hassle with f:verbatim and so on). You can make use of the Facelets' ui:repeat to iterate "plain" over a collection. Since JSF 2.0 you can even create composite components (templatebased components). This must enable you to make use of the HTML rowspans/colspans.

Explain to me the different JSF component libraries relate

Even though i spend whole days developing a JSF application, i've never had any training on the matter and I have to admin I am a still confused how the whole JSF puzzle fits together. JSF just looks a bit thrown together to me.
jsf-api
jslt
facelets
myfaces
trinidad
tobago
jsp api
I'd be very grateful if anyone could give me a quick description of these components, which ones are standard, which ones can be left out, which ones can/need to be used together
JSP and JSTL
JSP has undergone many iterations, but this is the core Java EE dynamic page technology. This is a servicable API, but working with JSPs often means more manual management of code/resources.
JSTL is the JSP Standard Template Library. This is a set of standard JSP tags. Do not mix these tags with JSF tags; they belong to a different programming model.
JSF API
The JSF specification. This is the core of the JSF Model-View-Presenter framework. This specifies a simple set of core components and the core lifecycle artefacts. There are two widely known implementations: Mojarra (the open sourced Sun API) and Apache MyFaces. Part of Java EE 5 and above.
Facelets
A view technology designed for JSF. Use this instead of JSPs. You cannot use JSP tags in Facelets views. This is not standard in Java EE 5, but is standardized in JSF2 (and therefore the upcoming Java EE 6). The better templating provided by Facelets often means you can rely less on 3rd party libraries.
Facelets provides some tags that look like JSP JSTL tags, but don't share any code. These tags should generally be avoided too (see Facelets doc for advice).
Apache Trinidad and Tobago
These are JSF libraries that provide components and other facilities. Because the core set of controls is rather basic, it is common to use such libraries, especially if Facelets is not used. These are not part of the Java EE standard. Library compatibility varies. See also jsfmatrix.net.
jsf-api are the interfaces and classes in javax.faces
jstl is a standard set of tags (used primarily in JSP) - most of them are replaced with JSF-tags, btw
facelets is a presentation and templating framework (like jsp)
myfaces is an implementation of the JSF standard. The other possibility if JSF RI (reference implementation)
trinidad and tobago are component libraries - some goodies that aren't included in the default set of jsf components
jsp is the alternative to facelets (or vice versa), which is as well a presentation framework.
UEL - (you didn't ask, but it's important) - Unified Expression Language - the set of rules for your #{..} expressions

Resources