JSF 2 template itself shows style, but template client shows plain text without style - netbeans

I am trying to use JSF Facelet template/Facelet template client first time. I am creating template and template client with Netbeans 7.2.1. When I run that created JSF project and call http://localhost:8080/jpaweb/template.xhtml I can see template style, but when I call client template http://localhost:8080/jpaweb/client.xhtml I see plain text without style. Both files are in the same directory and created by Netbeans wizard. Please, help me with this issue.
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 xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
<link href="./resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
<title>Facelets Template</title>
</h:head>
<h:body>
<div id="top" class="top">
<ui:insert name="top">Top</ui:insert>
</div>
<div>
<div id="left">
<ui:insert name="left">Left</ui:insert>
</div>
<div id="content" class="left_content">
<ui:insert name="content">Content</ui:insert>
</div>
</div>
</h:body>
</html>
client.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:ui="http://java.sun.com/jsf/facelets">
<body>
<ui:composition template="./template.xhtml">
<ui:define name="top">
Welcome, to my website
</ui:define>
<ui:define name="left">
My links
</ui:define>
<ui:define name="content">
This page is created for testing
</ui:define>
</ui:composition>
</body>
</html>
If you have Netbeans creating JSF project and JSF template and template client will get you this result. I tried in Netbeans 1.7.0 also. Same problem.
Edit: I run page not like http://localhost:8080/jpaweb/client.xhtml but likehttp://localhost:8080/jpaweb/faces/client.xhtml it worked. There is no "faces" directory in my project. Do we have to add "faces" to all JSF links?
Edit 2: I think netbeans auto-configures that all jsf files are kept in faces directory even there is no such directory in my project. And in Project properties -> Frameworks -> JavaServer Faces -> Configuration there is field JSF Servlet URL Pattern with value assigned /faces/*. I think that means one must call jsf files as if it is in faces directory. Trying to force it work as it appears in my project was a mistake :)

Solved. Changed value of Project properties -> Frameworks -> JavaServer Faces -> Configuration -> JSF Servlet URL Pattern from /faces/* to *.xhtml, and that worked OK.

Your client.xhtml content file is not properly composed. Don't include html tags, as JSF doesn't parse anything out from ui:composition tags here.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="./template.xhtml">
<ui:define name="top">
Welcome, to my website
</ui:define>
<ui:define name="left">
My links
</ui:define>
<ui:define name="content">
This page is created for testing
</ui:define>
</ui:composition>
I tested with your template and it works.

Related

Eclipse not rendering jsf?

only tomcat server will display the .jsf pages correctly. When I try to add project through eclipse and view and test it doesn't render the .jsf code but instead displays it as source code. I have eclipse configured for tomcat and that works fine but can't get the .jsf pages to render it just displays the source code when added to the server through eclipse but if I export the .war file and run it on tomcat/webapps then it works fine.
source code example from eclipse:
<?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>PCC Accounts Login</title>
</h:head>
<h:body>
<h:outputStylesheet name="style.css"></h:outputStylesheet>
<h:outputText>testing output text tag WITHOUT using value attributeHELLo ????</h:outputText>
<h:outputText value="testing outputText WITH using the value attribute" />
<h:form>
<h:inputText id="user_id" title="User Name" value="User Name" action="#{loginBean.setUsername}">User Name</h:inputText>
<h:inputText id="password" title="Password" value="Password" action="#{loginBean.setPassword}">Password</h:inputText>
<!-- <h:commandButton id="login" value="Login" action="accounts.jsf">Login Now</h:commandButton> -->
<h:commandButton id="login" value="Login" action="accounts.jsf" />
</h:form>
</h:body>
</html>
source code example exported from eclipse and ran on tomcat:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<title>PCC Accounts Login</title>
<link type="text/css" rel="stylesheet" href="/assign05_test/javax.faces.resource/style.css.jsf" />
</head>
<body>
<input type="hidden" name="j_idt9" value="j_idt9" />
<input id="j_idt9:user_id" type="text" name="j_idt9:user_id" value="User Name" title="User Name" />
<input id="j_idt9:password" type="text" name="j_idt9:password" value="Password" title="Password" />
<input id="j_idt9:login" type="submit" name="j_idt9:login" value="Login" />
</form>
</body>
</html>
SO, Eclipse is obviously not rendering the JSF pages but I added the correct file to the Preferences/Java/BuildPath/UserLibraries. So I'm not sure why it's not working but for now I'm testing by exporting the .war then running it on tomcat server which is very tedious process. Anybody else run into this problem? Any help would be greatly appreciated, thanks in advance.
Respectfully,
Martin Hand
Had this for servlet-mapping in web.xml:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Changed it to this and it's fixed:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Funny though that it only affected it when trying to run through Eclipse but if exported .war then added to /webapps in tomcat it was fine but that's a very tedious and annoying process when trying to develope an application. Also read this helpful article if your having trouble - JSF tags not being rendered as HTML

On the eclipse welcome page, is it possible to link to resources located in a different plugin?

I am working on an eclipse RCP application. In the main (app) plugin I have defined a welcome or intro page. This is an XHTML file containing links to interesting resources.
There is a separate help plugin which contains the help in html and also as a PDF.
Is it possible to link from the welcome page in the app plugin to the PDF in the help plugin? I was thinking of something like this (but it didn't work)
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome</title>
<link rel="stylesheet" href="shared.css" type="text/css" />
<link rel="stylesheet" href="root.css" type="text/css" />
</head>
<body>
<h1>Welcome to the Test Framework</h1>
<div class="page-style">
<div id="content">
<!-- app plugin -->
<a href="presentation.pdf">
<img border="0" src="file_powerpoint.png" alt="Presentation" />Präsentation</a>
<!-- help plugin -->
<a href="platform:/com.acme.atf.help/pdf/handbook_de.pdf">
<img border="0" src="file_pdf.png" alt="Handbuch" />Handbuch</a>
</div>
</div>
</body>
You need to register your XHTML page as a config extension at your plugin.
Add the extension at the plugin.xml:
<extension point="org.eclipse.ui.intro.configExtension">
<configExtension
configId="org.eclipse.ui.intro.universalConfig"
content="path/yourFile.xhtml" />
</extension>
Then, add it to the welcome page (via editing configuration, or using the Help/Welcome/Customize menu).
Link: A short tutorial on this topic
You can also use command to open some resource (you will implement opening of the resource in handler):
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="yourHandler"
id="openResource">
</command>
</extension>
and then execute the command in xml file where you have welcome page content:
<introContent>
<extensionContent id="openPdf" style="css/welcome.css"
name="SomeName" path="overview/#">
<group style-id="content-group" id="overview-default-group">
<link label="Open PDF"
url='http://org.eclipse.ui.intro/execute?command=openResource'
id="introLink" style-id="content-link">
<text>Open PDF resource</text>
</link>
</group>
</extensionContent>

JSP strange error in eclipse

I am a newbie in JSP and this is my first JSP.
<%#page import="java.util.Date"%>
<%# page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Hello</title>
</head>
<body>
<h2>Hi There!</h2>
<br/>
<h3>Date=<%= new Date() %>
</h3>
</body>
</html>
On the line where I am creating Date object, Eclipse is giving error as
Syntax error on token ")", delete this token
My Eclipse version is:
Eclipse Java EE IDE for Web Developers.
Version: Kepler Release
Build id: 20130614-0229
problem got solved when I added jsp-api.jar into build path of the project.

JSP:include is not rendering the included file

I just created a new IceFaces application and I'm trying to include a navigation bar in all of the pages. When I use the jsp:directive.include tag the file is included, but when I use jsp:include it does not seem to be loaded. In fact, when I check the HTML source code in my browser, it's like the included file was completely empty. I do not want to use jsp:directive.include because it will not automatically show any updates to the included file.
My environment: Eclipse 3.5, Tomcat 6, JSF 1.2, IceFaces 1.8.
Steps to reproduce the problem and pieces of code:
create a new Dynamic Web Project with the following options:
Target runtime: Apache tomcat v6.0
Dynamic web module version: 2.5
Configuration: ICEfaces project
create a new ICEFaces JSPX file -- the home file. Some code:
<jsp:directive.page contentType="text/html;charset=ISO-8859-1" />
<f:view >
<ice:outputDeclaration doctypeRoot="HTML"
doctypePublic="-//W3C//DTD HTML 4.01 Transitional//EN"
doctypeSystem="http://www.w3.org/TR/html4/loose.dtd" />
<html>
<head>
<title>test file</title>
<link rel="stylesheet" type="text/css"
href="./xmlhttp/css/rime/rime.css" />
</head>
<body>
<jsp:directive.include file="./vertical_navigation.jsp" /> <!-- working -->
<jsp:include page="./vertical_navigation.jsp" /> <!-- not working, no error though -->
</body>
</html>
</f:view>
create the file to be included, also as a new ICEFaces JSPX file. Simplified code:
<ice:form>
<ice:panelGrid columns="1" width="152">
<ice:graphicImage url="./img/image.jpg"></ice:graphicImage>
<ice:panelCollapsible expanded="true">
<f:facet name="header">
<ice:panelGroup>
<ice:outputText value="Customer"/>
</ice:panelGroup>
</f:facet>
<ice:panelGrid columns="1">
<ice:commandLink action="customer"><ice:outputText value="Customer name" /></ice:commandLink>
</ice:panelGrid>
</ice:panelCollapsible>
</ice:panelGrid>
</ice:form>
</body>
</html>
</f:view>
Some remarks:
I'm completely new to JSF, so forgive me for any obvious mistake.
In the home file (the first one) I'm not using both tags at the same time. I pasted both here just to show that I am trying both options.
I created both files as "ICEFaces JSPX file", but the second one was assigned the .jsp extension.
When I use the directive.include tag, the included file is loaded. But if I change it, it's not automatically republished.
To start, you have to separate and distinguish several technologies:
JSP is a Java based view technology which allows you to write HTML/CSS/JS in and use taglibs to call backend Java code and/or control the output flow.
JSPX is the same as JSP, but forces you to write code in XML format. JSP-specific tags are replaced by tags in XML format. JSPX is also called "JSP Document". Here is a basic tutorial which outlines the differences in tags.
JSF is a component based MVC framework which provides components in flavor of taglibs which outputs HTML/CSS/JS.
You cannot use <jsp:include> in a JSPX page. You have to transform the JSPX page into a JSP page. You need to rename the file .jspx to .jsp and replace JSPX specific tags by JSP tags. Here's a kickoff example for JSP with JSF/IceFaces:
<%# page pageEncoding="ISO-8859-1" %>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%# taglib uri="http://www.icesoft.com/icefaces/component" prefix="ice"%>
<!DOCTYPE html>
<f:view>
<html lang="en">
<head>
<title>Title</title>
</head>
<body>
<jsp:include page="include.jsp" />
</body>
</html>
</f:view>

Validation problem with JSP and Eclipse

I have this simple JSP page in Eclipse and the first line in the file is:
Eclipse however, puts a yellow warning icon before this line with the following tooltip message:
Multiple annotations found at this
line:
- Line breakpoint:index.jsp [line: 1]
- Tag (jsp:directive.page) should be an empty-element tag.
Does anyone know why this is?
UPDATE:
This is my full source script. This is basically the template that Eclipse generates for me when I create a new JSP file based on the XHTML template. I only slightly modified the content to make it do something 'use full'.
I'm using Eclipse 3.4 (eclipse-jee-ganymede-SR1-linux-gtk.tar.gz) on Ubuntu 8.10 with the Geronimo 2.1 plug-in (I don't think that matters though). I had this same problem with every version of Eclipse I've used so far (3.0 and up)
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<jsp:useBean id="datetime" class="java.util.Date" />
<html>
<head>
<title>Hello Geronimo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div>
<h1>Hello Apache Geronimo!!!</h1>on ${datetime}
</div>
</body>
</html>
It's an oddity of the DOM validation that happens in the editor even for JSP files, reported in bug 248963 for another situation.
It's expected to be resolved in WTP 3.0.4 & Ganymede SR2.
So what eclipse and WTP version are you using ?
Can you check if this is still the case when you add the following line just beneath the initial jsp declaration:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
as mentioned in bug 257258 (also fixed in WTP 3.0.4 & Ganymede SR2): before WTP3.0.4, this doctype was enough to not show your warning:
(source: eclipsetotale.com)