Image display using jsp XHTML template .. JSF - jsf

i have written a simple code to display an image using Jsp XHTML template but it is not working
but same is working when i am using Jsp HTML template ....
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Car Details</title>
</head>
<body>
<f:view>
<h:graphicImage id="root" value="http://www.allbestwallpapers.com/tagwallpaper/convertible%20car-wallpapers.jpg"></h:graphicImage>
</f:view>
</body>
</html>
please Help....

You're mixing JSP (foo.jsp) with Facelets (foo.xhtml).
JSP is the ancient view technology which was the default in JSF 1.x. It is not XML based. Facelets is the successor of JSP and is the default view technology since JSF 2.0 (and JSP became deprecated). Facelets is XML based. Those xmlns XML namespace declarations don't work in JSP, but in Facelets only.
Rename the filename from the .jsp extension to .xhtml extension and get rid of that JSP specific #page declaration and it'll work.

Related

Cannot redirect using c:redirect in JSF using JSTL

My adminPanel.xhtml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:c="http://java.sun.com/jsp/jstl/core">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Insert title here</title>
</head>
<body>
<c:redirect url="http://www.google.com"></c:redirect>
</body>
</html>
When I run above code, I get:
HTTP Status 500 - /loggedIn.xhtml #12,44 Tag Library
supports namespace: http://java.sun.com/jsp/jstl/core, but no tag was
defined for name: redirect
<c:redirect> tag is not available in the Facets 2.0 . For list of available or supported tags . see Tag Library Documentation Generator. You can make use of jsf page navigation to redirect.
Similar thread :
Explicit url redirect in JSF 2.0
Also tutorials:
jsf page-forward Vs page-redirect
jsf-2 Redirect

Can the new Facelet Tag Libraries URI's be used in older JSF versions?

I read somewhere that the Facelet Tag Libraries URI's changed from http://java.sun.com/jsf/* to http://xmlns.jcp.org/jsf/*, so that means the new namespaces applies only for the new specification(JSF 2.2) or they can or should be used in older versions like 2.0, 2.1 or 1.x?
for example:
Library Old URI New URI
Composite Components http://java.sun.com/jsf/composite http://xmlns.jcp.org/jsf/composite
Faces Core http://java.sun.com/jsf/core http://xmlns.jcp.org/jsf/core
HTML_BASIC http://java.sun.com/jsf/html http://xmlns.jcp.org/jsf/html
JSTL Core http://java.sun.com/jsp/jstl/core http://xmlns.jcp.org/jsp/jstl/core
Facelets Templating http://java.sun.com/jsf/facelets http://xmlns.jcp.org/jsf/facelets
EDIT
To make the question more understandable nothing like a snippet of code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>test</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<link rel="stylesheet" type="text/css" title="Style" href="theme/stylesheet.css" />
</h:head>
<h:body>
<h:form id="form1" styleClass="form">
<h:inputText id="text1" styleClass="inputText"></h:inputText>
</h:form>
</h:body>
</html>
The previous code would be valid for JSF 2.0? notice the taglibs:
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
Thanks.
From what I've seen here : http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/index.html, the canonical names for the large majority of taglibs stays http://java.sun.com/
However, as stated, you can use the new URIs since they created an alias.

metadata tag not working in jsf

I am trying to set a variable with viewparam but I can't seem to get the code to compile in eclipse. It seems like it's not finding the tags.
I have the mojarra 2.2 used and I am inlcuding jsf-api-2.2.4 and impl also.
<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" version="2.0">
<jsp:directive.page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
<jsp:text>
<![CDATA[ <?xml version="1.0" encoding="UTF-8" ?> ]]>
</jsp:text>
<jsp:text>
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
</jsp:text>
<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:c="http://java.sun.com/jsp/jstl/core">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<f:view>
test
<f:metadata>
<f:viewParam name="id" value="#{bowlingEvent.ID}" />
</f:metadata>
<h:form>
<h:inputText id="id" />
<h:commandButton id="button" value="Spara event" action="update">
</h:commandButton>
</h:form>
</f:view>
</body>
</html>
</jsp:root>
org.apache.jasper.JasperException: /update.jsp (line: 25, column: 13) No tag "metadata"
defined in tag library associated with uri "http://java.sun.com/jsf/core"
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
Your major mistake is that JSP is a deprecated view technology and is clearly a wrong tool for new projects. It has been succeeded by facelets, which is the default view technology for JSF 2.0+ projects.
Some tags, namely the ones used by you like <f:metadata> and <f:viewParam> are not available in JSPs (see sections 10.4.1.3 and 2.5.5 of JSF 2.2 specification (JSR-344) respectively).
The solution is straightforward: switch to facelets as the view technology.
It is also requested to switch to using the new namespaces that have been proposed since JSF 2.2, namely http://java.sun.com should now become http://xmlns.jcp.org (see Preface, page 8 of JSF 2.2 specification (JSR-344)), though both namespaces will work. Also see BalusC's comment to this answer and BalusC's answer to a similar question.

Unknown jsf tag in xhtml page in jsf application

This is my first application with eclipse and jsf and i having some problems.
Here is my project structure:
eclipse project structure
I have downloaded and used JSF 2.1 (Mojarra 2.1.6-FCS) jar file and there is only a single jar file in that and i have used that jar file as a user library.
Now the problem i am facing is that when i use h:head in my index.xhtml file it shows that h:head is an unkown tag.Of course i am using anugular brackets. besides h:head , i am not able to type that in here.
here is my index.xhtml file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</h:head>
<body>
</body>
</html>
What is wrong here? IS there only one jar file file to be included?
also there are some white packages marks in the jar file i included...here they are:
while package in jar
what does it mean?
The problem is that you haven't defined the h prefix anywhere in your file. If you follow a JSF 2 tutorial, you will note this in the <html> tag definition (this one is taken from StackOverflow JSF wiki):
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
Where
h for JSF HTML tags like <h:head>, <h:body>, <h:inputText>, etc.
f is the prefix for JSF core like <f:view>, <f:selectItems>, <f:ajax>, etc.

How to make facelets conform to XHTML 1.0 Transitional?

Why can't facelets XHTML files be valid XHTML 1.0 Transitional files?
If I submit a facelet file in an xml validator (e.g. w3c validator) it shows an error on the first tag defined in one of the taglibs.
Example 1:
If I submit the following file to the validator, it shows no error, validation goes fine because no taglib tags appear in the document (one jsf taglib is defined though).
<?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">
<head>
<title></title>
</head>
<body>
</body>
</html>
Example 2:
Now I just inserted the h:head and h:body tags from the xmlns:h namespace but this causes errors in the validation.
<?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">
<h:head>
<title></title>
</h:head>
<h:body>
</h:body>
</html>
Certainly I'm missing something fundamental here, but I still can't figure out what.
This is my first question here at S.O. so please point out any errors, thank you!
If you check the Lifecycle of a Facelets Application you can see that your view is rendered to the client. This will transform tags like <h:head> replacing them with their xhtml equivalent e.g. <head>. If you want templates that are XHTML valid you may want to try with the jsfc attribute but it has its drawbacks.

Resources