OK, so I am trying to set up a simple JSF application. I'm using NetBeans 6.8, Glassfishv3 and Maven2. I made a JSP document like so:
<?xml version="1.0" encoding="utf-8"?>
<html xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:view>
<head>
<title><h:outputText value="#{Welcome.title}"/></title>
</head>
<body>
<h:outputText value="Welcome"/>
</body>
</f:view>
</html>
Problem is, if I navigate to this page (http://myHost/myApp/faces/welcome.jspx), it is returned as an XML document, but with the ${Welcome.title} value populated:
<?xml version="1.0" encoding="UTF-8"?>
<html><head><title>Gymix - Welcome</title></head><body>Welcome</body></html>
In Internet Explorer this looks like I would have opened an XML document. In Google Chrome the title is printed next to the text Welcome and instead of the title the URL to the page is printed on the tab.
If I change the JSP document to a plain JSP page (taglibs instead of xmlns and so on) it works and I get a proper page returned. Any ideas on what's wrong? Thanks!
Edit: sadly none of the quick fixes fixed this, so I'll look into this more. BTW, my pom.xml has jsf-api and jsf-impl dependencies with the version for both set to 1.2_14
Aside from the fact that you need to set the proper doctype and content type so that the browser knows what to do with the page, you also should get rid of the old fashioned jspx format and use xhtml format to get the most benefit of Java EE 6-shipped JSF 2.0 and Facelets.
The given code should be changed to:
<?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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>#{welcome.title}</title>
</h:head>
<h:body>
Welcome
</h:body>
</html>
Note that the doctype is included and that JSF 2.0 / Facelets will automatically take care about the right content type with help of the <h:head> component. Also note the absence of the <f:view> tag, this isn't needed anymore in Facelets.
You probably also need to reconfigure your webapp to make use of the full powers of JSF 2.0 and Facelets. To learn more about JSF 2.0 and Facelets, I strongly recommend to go through the Java EE 6 tutorial part II chapters 4-9.
Good luck.
Update: as per the comment of bobince: I would add an important note; it is true that the XML declaration (the first line) would mess the rendering mode of some webbrowsers (also see the site behind the doctype link here above), but that's certainly not an issue here. Facelets removes the XML declaration during generating the HTML of the page. The XML declaration is simply there because Facelets needs to parse the page using a XML based tool first. We're talking about a component based MVC framework and XML based templating technology, not about a plain vanilla HTML page ;)
I think you need to put in a valid doctype.
This would go below your xml declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
You have to tell the browser what you're sending. I'm not exactly sure of how to do it inside a JSP though, so you'll have to figure out yourself or wait until someone more knowledgeable than me tells you.
You have to send the Content-Type HTTP header indicating your file is a text/html; charset=UTF-8.
Content-Type: text/html, charset=UTF-8
Related
Hello so i wanted to make a little projects, but i'm currently don't know the "keyword" to search for it. I wanted to make a job applying site, and how do i list all the job from job table in the so like "bootstrap card" but in Primefaces?
Fyi: The region is from Region table.
I don't know what to search the keyword for it...
PrimeFaces is an open-source user interface (UI) component library, the following components may help you to achieve your goal :
NAVBAR: https://www.primefaces.org/showcase/ui/menu/menubar.xhtml
SIDE MENU: https://www.primefaces.org/showcase/ui/menu/slideMenu.xhtml
CARD: https://www.primefaces.org/showcase/ui/data/datagrid/basic.xhtml
How to use Primefaces
You just need to download PrimeFaces, add the primefaces-{version}.jar to your classpath and import the namespace to get started.
PrimeFaces namespace is necessary to add PrimeFaces components to your pages.
xmlns:p="http://primefaces.org/ui"
For PrimeFaces Mobile, the namespace would be;
xmlns:p="http://primefaces.org/mobile"
That’s it 🙂
<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:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<p:spinner />
</h:body>
</html>
I have implemented a Java Applet.
I have exported the jar.
I signed the jar.
And it works if I put it on my server and use it with HTML.
But only in Firefox.
Here is the HTML:
<?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" xml:lang="en" lang="en">
<head>
<title>Upload Test</title>
</head>
<body>
<object archive="applet.jar" classid="java:uploader/FileUpload.class"
codetype="application/java-vm" width="800" height="600"> </object>
</body>
</html>
I also tried it with this:
<SCRIPT type="text/javascript">
if(browser.value.getIndex("chrome") {
chrome.browser.enableFeature(JApplet)
});
</SCRIPT>
But still Firefox only.
I would really like for this to work in Chrome & IE9.
But these two only leave a space where the Applet should be.
I can even highlight it.
Are there things I have to add in my xhtml? Or maybe something in the Applet?
I found enough online about why Applets might not work, but nothing about why Firefox only.
As Andrew Thompson said, I need to use deployJava.js.
You can find it in this Oracle tutorial.
This tutorial describes in detail every step neccessary.
Now my Applet works on all three browsers (FF, Chrome, IE9) like a charm.
Thanks!
In Eclipse Indigo (for Java EE Developers, JBoss Tools are installed) I
created new "Dynamic Web Project",
enabled the JSF v 2.0 from Project Facets and
added xhtml file whose content is below:
<!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">
<h:head></h:head>
<body>
<h:messages layout="table" />
</body>
</html>
Now I want to see validation warnings / errors when I change the JSF tag or its attribute to some invalid value like these:
Invalid tag <h:barfoo layout="table" />
Invalid attribute <h:messages barfoo="table" />
Invalid attribute val <h:messages layout="barfoo" />
Currently I cannot see any warnings for all 3 ones in Eclipse. How can I validate the page?
The autocompletion (Ctrl+Space) is just working fine for tags and attributes. JBoss AS 7.1.1 is registered to Eclipse.
I've also had this problem a couple of times. You need to understand that an xhtml page can contain anything, plain text, JavaScript, html tags as well as lots of other types of tags. now the h: prefix is meant to indicate jsf tags, but remember you can also create custom tags that extend the h: prefix. So even though the tags are not available at the default namespace. eclipse won't warn you, however it will fail at runtime. you will get validation warnings if your xml is not well formed, but that's about it. That's one of the downsides of xml being so malleable.
I have already provided GWT's i18n feature for java, UI Binder and trying to provide i18n with pure, none-hosted in java HTML file.
After reading "Declarative Layout with UiBinder" I implement some code, but it didn't work:
<html xmlns:ui="urn:ui:com.google.gwt.uibinder">
<ui:with field='i18n' type='//.exampleConstants'/>
<head>
<title>Title of none-hosted HTML file and i18n part: <ui:text from='{i18n.title}'/></title>
</head>
<body>
...
</body>
</html>
The solution with id's (described on same page: https://developers.google.com/web-toolkit/doc/latest/tutorial/i18n/) which will be pick-upped by RootPanel, smth like:
RootPanel.get("appTitle").add(new Label(constants.stockWatcher()));
Didn't work too, because my HTML file isn't bundled with Java.
How to do i18n in HTML files?
Well, you'd have a Catch-22 here: the HTML file couldn't know which text to use until the JavaScript compiled out of your Java code is loaded, which is done by the page, so after it's loaded.
You have to use standard Java web app techniques to internationalize your HTML page, e.g. make it a JSP, and detect the preferred language out of the Accept-Languages request header. If you do that, then generate the appropriate <meta name="gwt:property" content="locale=XX"> so the GWT app bootstrap (the .nocache.js file) won't have to guess it too, which could result in the GWT app running in a different locale than the one the HTML was generated with.
I have just started experimenting with JSPX and ICEfaces for a work project. I would like to know the best standards used to work with .JSPX and the best way to minimize code from pages.
I had worked with PHP, asp.NET, and Java before so you get an idea of my background.
I have some issues:
First of all, does JSPX use some kind of Master Page, if not I guess using "include" would be the best way to reduce repeated code. However I still cannot get rid of the whole header because I need the Title tag, unless this has a way around!?
The second issue is, that the html dumped by JSP is sometimes not valid. For example this is the html declaration: <html id="document:html" lang="en"> which is not valid, and there are other similar issues. I know there is another post about this on Stack Overflow, but that targets mainly self closing tags, doesn't mention the doctype issue.
I would appreciate if you can help me with my current issues, and if you have some good tutorials please share. What I would like is to create maintainable code and reduce code in pages as much as possible (for example include header and footer files, so you only have those in 1 file).
Update (BalusC Comment):
These are the first three lines I have in my .jspx file:
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ice="http://www.icesoft.com/icefaces/component">
<jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>