1

Having an issue rendering jstl tags from within a facelets ui:composition

My current xmlns imports are:

xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"

When I deploy it renders the text as

 <c:forEach> ... 

within the html output.

Am I missing a dependency? Is the import incorrect? Is using jstl tags within facelets even possible?

Thanks a bunch!

dardo
  • 4,870
  • 4
  • 35
  • 52

1 Answers1

2

The given XML namespaces (note: that are not "xmlns imports") are correct for JSF 2.x. However, in Facelets 1.x, which is to be used standalone in JSF 1.x projects, the XML namespace for JSTL is different, it should not contain the /jsp path.

xmlns:c="http://java.sun.com/jstl/core"

But if you're actually already using JSF 2.x (in future JSF 2.x questions please mention and tag accordingly), then you're probably using a servletcontainer which doesn't ship with JSTL included, such as Apache Tomcat. You'd need to download JSTL separately and drop it in /WEB-INF/lib folder. In that case the xmlns:c="http://java.sun.com/jsp/jstl/core" should work.

See also:


Unrelated to the concrete question, using JSTL in Facelets is definitely possible. You should only make sure that you really understand the lifecycle of tag handlers like JSTL in JSF. See also JSTL in JSF2 Facelets... makes sense? You could alternatively also just use Facelets' own <ui:repeat> tag instead of the <c:forEach>.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I tried the ui:repeat and I believe I run into scoping issues with the way information is being passed to the view. Since JSF usually uses managed beans for binding data, and I'm using a Spring MVC Controller, it's not rendering correctly. Shame on me for mixing technologies =( – dardo Feb 22 '12 at 19:33
  • JSF and Spring MVC are indeed not supposed to be mixed. For Spring MVC you should use plain HTML instead. But how about the namespace issue? Did my answer help? Are you using JSF 1.x or 2.x? – BalusC Feb 22 '12 at 19:34
  • It's JSF 1.x, still having issues, could be lots of different things. Probably just going to attempt a pure JSF approach, and use the spring controller for ajax calls to dump in as pure HTML. – dardo Feb 22 '12 at 19:53
  • Okay, did fixing the XML namespace as mentioned in the answer help in solving the problem of the `` not being parsed? For those other issues you can always ask a question. But in general it's indeed not smart to mix different competing MVC frameworks together in a single webapp. You've to make a choice. For Ajax capabilities in JSF, rather look for a real JSF component library like RichFaces which offers `` tags for that. – BalusC Feb 22 '12 at 19:58
  • Yeah, sort of confined into what I can and cannot use. The namespace change didn't work, neither did adding jstl as a dependency. I believe your answer is correct, but due to the way this app is put together, it's not going to mesh well. Going to need to fashion a workaround. – dardo Feb 22 '12 at 20:04