No warning or error on missing bean in tomcat - jsf

I have a very simple "dynamic web application" which results in a war-file. I (deliberately) used the name of a non-existing bean (for experimentation and learning purpose). When deployed to tomcat I can see the page in firefox, but I get no error or warning neither in catalina.out nor in catalina*.log.
What is wrong, where can I see such warnings?
I'm using java 8, tomcat 8, eclipse 4.5.1 (mars), jsf-api.2.2.8.jar and jsf-impl.2.2.8.jar.
I don't have any java code of my own (yet), especially no beans.
The index.xhtml that is used (and, aside of the missing bean value) displayed correctly is:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<ins>This is some other xhtml</ins>
<h:commandButton value="A#{missingBean.name}Z" action="#{missingBean.doAction}"></h:commandButton>
<h:messages></h:messages>
</body>
</html>
EDIT:
thanks to #Kukeltje I added
<context-param>
<param-name>javax.faces.DEVELOPMENT_STAGE
</param-name>
<param-value>Development</param-value>
</context-param>
to my web.xml file.
This results in an
HTTP Status 500 - javax.el.PropertyNotFoundException: /index.xhtml #13,81 action="#{missingBean.doAction}": Target Unreachable, identifier 'missingBean' resolved to null.
This solved the original problem that I didn't get errors nor even warnings on an obvious (and deliberate) coding error.
Background information: I try to learn jsf and did some experiments based on a tutorials-point tutorial. Having messed that up by trying far too many things in one go, I resolved to start a new eclipse project from scratch, going very tiny step by step, to see not only the result (as would be by blindly doing copy&paste), but also what errors I'll see if I neglect something on the way.

Related

Primefaces components not showing at all [duplicate]

This question already has an answer here:
One or more resources has the target of 'head' but not 'head' component has been defined within the view
(1 answer)
Closed 7 years ago.
I recently started a new project and want to use primefaces components again. I used them for an other project before but now i dont know what I am missing.
My primefaces components are not rendering correctly.
I cant even get a simple Spinner to work.
I installed primefaces just like the last time adding the .jar to the namespace -> putting it in web-inf/lib
Here is what i tried so far:
Different Glassfish (4.0/3.1)
Different Primefaces Versions (4.0/3.5)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
version="3.0">
<display-name>SocialMapS</display-name>
<welcome-file-list>
<welcome-file>test.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
version="2.1">
</faces-config>
faces-config.xml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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:p="http://primefaces.org/ui">
<head>
<title>SocialMap</title>
</head>
<h:body>
<p:spinner />
</h:body>
</html>
login.xhtml
Webpage I created to test if its working.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SocialMap</title>
</head><body><span id="j_idt4" class="ui-spinner ui-widget ui-corner-all"><input id="j_idt4_input" name="j_idt4_input" type="text" class="ui-spinner-input ui-inputfield ui-state-default ui-corner-all" autocomplete="off" /><a class="ui-spinner-button ui-spinner-up ui-corner-tr ui-button ui-widget ui-state-default ui-button-text-only"><span class="ui-button-text"><span class="ui-icon ui-icon-triangle-1-n"></span></span></a><a class="ui-spinner-button ui-spinner-down ui-corner-br ui-button ui-widget ui-state-default ui-button-text-only"><span class="ui-button-text"><span class="ui-icon ui-icon-triangle-1-s"></span></span></a></span><script id="j_idt4_s" type="text/javascript">PrimeFaces.cw('Spinner','widget_j_idt4',{id:'j_idt4'});</script></body>
</html>
Sourcecode in Firefox. Its just showing a textinput but not the spinner.
EDIT
WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=null[severity=(ERROR 2), summary=(One or more resources have the target of 'head', but no 'head' component has been defined within the view.), detail=(One or more resources have the target of 'head', but no 'head' component has been defined within the view.)]
The error I get
I even tried different webbrowser. No success.
I bet its a very simple mistake or I m missing something, but I didnt find it in the last 5 hours. ;-)
Pls help me.
EDIT
got the problem.... was as trivial as it can get.
Should have used
<h:head>
instead of
<head>
....
-_-
This is a bug for the version < 3.5. If you use the version 4.0.x it will run well.
If you are using eclipse, remind to do this steps to add the libraries in your WEB-INF/lib:
go to Project Properties / Project Facets / Java Server Faces
in type, select "User Library"
click in "Manage Library" icon,
than click in New,
put a name, click in OK
click in your recent created library
click in Add external JARs
select the javax.faces.jar and pramefaces-4.0jar in your User Library, "OK"
Click in "Apply" next in "OK"
in menu bar go to Project/Clean...
Now just run your server and have fun.
Simply replace <head> by <h:head> and </head> by </h:head>

Can we include angularjs component in Facelets page

I am new to angularjs, and was trying to create a sample angularjs in a Facelets file. But I am getting an error in the line <html ng-app> in Eclipse IDE. The error specifies that the ng-app attribute should be followed by an = character. Is it not possible to include angularjs code in a Facelets XHTML file?
<?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:ng="http://angularjs.org" ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</body>
</html>
Take a look at following:
Try angular faces: https://github.com/stephanrauh/AngularFaces
And there is also a project: https://github.com/pankajtandon/PointyPatient
Prime faces refer to: http://angularprime.appspot.com/#/main
The best way is to go with HTML & JS as Client, and JAX-RS on Server Side.
I had similar problems, with Primefaces and Bootstrap, and became convinced, that JS & HTML at the moment is better for client side development.
Give the attribute the ng-app.
The value of the attribute would be the same as the name of variable that contains the return value of angular.module().
for ex:
ng-app="SampleApp"
in the html page
var SampleApp = angular.module("SampleApp", ["ngResource"]).
config(
//your code
);
in the app.js file
I think this should work for you.
The logic is that, when you define the ng-app it gives the reference to the particular module of app.js that would call the relevant controllers.
There is an app.js file in angularjs. This contains all the controllers define. These controllers act as connecters and data pipeliners between the html(our view) and the .cs(mvc controller) files.
These controllers are defined in a module (as i have defined one in the above answer).
There can be numerous modules in app.js. and hence they wil have numerous controllers.
ng-app is a directive that contains the name of the module you want to use as attribute.
ng-app defined will be active till the closing tag of the tag defined. That means if you have defined ng-app in html tag, it will work till the html tag closes, if in a div, it will work for that division.
If you dont get anything, google it, or refer the angularjs documentation, or shoot me a question.!!
I hope you got something out of it.:-)
Stumbled on this while searching myself.
XHTML does not allow an attribute without a value. While you can ignore this in Eclipse, the latest JSF libraries blow up and you'll get an exception.
Specify a value, which corresponds to your module name. For example, if you initialize your angular module with:
var myAppModule = angular.module('myApp', []);
Then you need to specify:
<html ng-app="myApp">
And all should be good minus some warnings in eclipse for not recognizing "ng-app". Works for me. Also, you probably want the HTML 5 doc type instead of the strict you have. Try:
<!DOCTYPE html>
<html ng-app="myApp">

How to make a meta tag the first one in the <head> section?

I'm using JSF2, GlassFish 3.1, PrimeFaces 2.x.
I'm having strange rendering problems on IE9. I'm supposed to be able to force IE9 to render as IE9 by inserting the following:
<html>
<head>
<!-- Enable IE9 Standards mode -->
<meta http-equiv="X-UA-Compatible" content="IE=9" />
...
But the thing is, it's not working because (I'm told) the meta tag MUST be the first tag in the section.
When I do this in my XHTML file ...
<html ...>
<f:view contentType="text/html" locale="#{loginHandler.currentLocale}">
<h:head>
<!-- Enable IE9 Standards mode -->
<meta http-equiv="X-UA-Compatible" content="IE=9" />
The resulting HTML looks like this, where JSF/PrimeFaces has inserted a bunch of "link" and "script" tags before my new meta tag.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link type="text/css" rel="stylesheet" href="/orcf-webui/javax.faces.resource/jquery/ui/jquery-ui.css.jsf?ln=primefaces&v=2.2" />
<link type="text/css" rel="stylesheet" href="/orcf-webui/javax.faces.resource/wijmo/wijmo.css.jsf?ln=primefaces&v=2.2" />
<script type="text/javascript" src="/orcf-webui/javax.faces.resource/jquery/jquery.js.jsf?ln=primefaces&v=2.2"></script>
<script type="text/javascript" src="/orcf-webui/javax.faces.resource/jquery/ui/jquery-ui.js.jsf?ln=primefaces&v=2.2"></script>
<!-- Enable IE9 Standards mode -->
<meta http-equiv="X-UA-Compatible" content="IE=9" />
Is there any way to get my meta tag in the right place so it will work? (Or an alternative way to make this IE9 problem go away?
The meta tag must go before all PrimeFaces stuff:
http://blogs.msdn.com/b/cjacks/archive/2012/02/29/using-x-ua-compatible-to-create-durable-enterprise-web-applications.aspx
HTTP Header and HTML HEAD are completly different things.
In PrimeFaces 3.0 the new facet was added to h:head:
http://blog.primefaces.org/?p=1433
So the solution would be:
<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
</f:facet>
</h:head>
I think best solution is to create JSF PhaseListener which adds X-UA-Compatible header to HTTP response
public class UACompatibleHeaderPhaseListener implements PhaseListener {
private static final long serialVersionUID = 1L;
#Override
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
#Override
public void beforePhase(PhaseEvent event) {
final FacesContext facesContext = event.getFacesContext();
final HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.addHeader("X-UA-Compatible", "IE=edge");
}
#Override
public void afterPhase(PhaseEvent event) {
}
}
and register it in faces-config.xml
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" version="2.0">
<lifecycle>
<phase-listener>com.example.UACompatibleHeaderPhaseListener</phase-listener>
</lifecycle>
</faces-config>
Another option would be to create servlet Filter and register it in web.xml.
Why is this needed?
Imagine your web application is deployed on a domain (or sub-domain) which is on IE compatibility list here: http://ie9cvlist.ie.microsoft.com/ie9CompatViewList.xml so you need to use X-UA-Compatible header to switch IE back to latest mode.
Imagine your web application is deployed on WebLogic server (which uses mojarra 2.0.4) so you cannot change JSF implementation.
mojarra
You can create Filter which adds header:
X-UA-Compatible: IE=9
to response object.
Source
Just to comment on your answer and previous comments:
HTTP Header and HTML Head are not completly different things (effectively) if you view page on IE8 as shown by diagram here. If you set HTTP header, but not HTML Head, the directive from HTTP header is still taken into account.
I don't know how IE9 behaves, but I guess that in a similar way.
You might want to switch from Mojarra to MyFaces. Looking at the source code of MyFaces' HEAD renderer - first gets rendered the content of the element and then other resources. Mojarra is doing this probably other way around. If you don't want to switch JSF implementations you can just implement your own HEAD element renderer.
However I would suggest just to find out why IE9 is not working without the X-UA-Compatible meta tag. It is supposed to make newer versions to behave like older versions.

Making JSF website multilingual

Trying to make JSF web application multilingual. For that purpose cover all the HTML code with <f:view> tags:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns= ... >
<f:view locale="#{actionsContainer.languageDetails.locale}">
<head>
<meta charset="utf-8" />
<f:loadBundle basename="messages.Messages" var="key" />
</head>
<body>
<h:outputText value="#{key.myText}" />
</body>
</f:view>
</html>
Than in resources I have several 'Messages.properties' files with a translations to some languages:
Messages_en.properties
Messages_es.properties
Messages.properties // default
The sample content of this files 'Messages_es.properties' is:
myText=España
Let's take, my locale is "es", and than Spanish translation file loads it's value and renders to the screen. However, the special characters (eg 'ñ') doesn't display properly in a browser output. Instead of special Spanish letters I am getting something like this "ó".
I have tried to save .properties file with UTF-8 encoding, without BOM. And the output has been changed to something like this "".
And so the question is how do I get this special any language letters in an output?!
Properties files are by default read using the ISO-8859-1 encoding. You need the JDK native2ascii tool to convert UTF-8 properties files to ISO-8859-1 properties files and then use those instead.
In JSF you can however also specify a custom ResourceBundle with a Control wherein you overridde the reading of properties files to use UTF-8 instead. See also this article.
when working with resource bundles, consider using ResourceBundle Editor plugin for eclipse (http://sourceforge.net/projects/eclipse-rbe/).

Cant find appropriate doctype, only seems to work in quirks mode

For some reason my web page seems to work fine without a doctype, but doesnt if I specify any in full.
I have gone through various different templates without any success, i.e. code validators then dont like my code and/or it doesnt work.
The only thing "I get away with" is the top line below, but even then I cant specify any details, i.e. its just the beginning of the usual doctype declaration.
The page is the result of Drop down Stackoverflow question.
Also (and the reason why I want to specify type since this may be causing the problems) the page only fully works in IE. It only loads the first drop down in Chrome and doesnt load any in firefox.
I appreciate that above isnt overly clear, but the code is very short, so am hoping if pointed in the right direction I can complete it myself and/or describe other issues better.
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>User Interface</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="dropdown.js"></script>
<html>
<body onload="show_results('','Type1')">
<form name="MainForm">
League:
<span id="FirstList"><b>First List.</b></span>
Team: <span id="SecondList"><b>Loading second list, please wait.</b></span>
<input type="button" value="Button1" onclick="show_results(form.select_second.value,'Type3');" />
<input type="button" value="Button2" onclick="show_results(form.select_first.value,'Type4');" />
Output: <span id="OutputTable"><b>Output table space holder.</b></span>
</form>
</body>
</html>
Managed to solve it myself, even with strict type
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
was perfectly fine after tidying up everything.

Resources