Christopher Sharp

Ranch Hand
+ Follow
since Dec 12, 2007
B.Sc. Physical Sciences, M.Sc. Astronomy, Ph.D. Theoretical Astrophysics, Fellow of the Royal Astromical Association. Dual US/UK citizenship.  Have worked in France, Germany and the USA as a scientist and scientific software consultant.
Lyon, France and Tucson, Arizona
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Christopher Sharp

JSF 2.3 only came out very recently, and I'm having problems getting it to work with Eclipse.  I have earlier versions of JSF installed correctly, and in Eclipse when I go to Dynamic Web Project [Project name] and select for Target runtime Glassfish, and select for also Glassfish for configuration, then click on Modify... a new window opens with various versions of Java, JavaServer Faces, etc. Java 1.8 is selected by default, which I want, but Java Server Faces only has selections for 2.2 and earlier versions, and I'm unable to get 2.3 shown as being available, so what do I do?

I downloaded javax.faces-2.3.0.jar from https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/2.3.0/, then on my Windows computer found that in the Eclipse workspace I have the folder JSF 2.2 (Mojarra 2.2.0)\mojarra-2.2.0-FCS\lib\javax.faces.jar, so I created a new lib folder with the same path as above, except the I replaced 2.2 by 2.3 in all cases, copied the jar file into the new lib folder, then renamed it javax.faces.jar.

After closing then restarting Eclipse, I'm unable to select any version of JSF higher than 2.2. I can link the jar file directly into the project and it works, but Eclipse will not recognize the h: and f: tags in the XHTML source code, so obviously JSF is not linked properly with Eclipse, and would most appreciate some advice on fixing this.

This has all been done with Eclipse Mars.2 Release (4.5.2).  I've now just installed Eclipse Neon and I'm still unable to get JSF 2.3 when I try to create a Dynamic Web Project.  In fact in the Neon workspace there is no libraries folder, and because I have not yet successfully created any projects, there are also no project folders.

How do I get Eclipse to recognize JSF 2.3, and will the next version of Eclipse, Oxygen, which is due to come out in June this year, have JSF 2.3 automatically included?
2 years ago
JSF
Well, I got no replies, but eventually after a lot of time messing around, I just discovered that Eclipse had not been configured properly with Glassfish.

I'm happy that now I've got Eclipse Mars working with Java 1.8 and Glassfish 4.1.1.

Christopher Sharp
3 years ago
JSF
Hello,

I've been using Eclipse Kepler with Java 1.7, Glassfish 4 and JSF 2.2 successfully for a while. I've just installed Eclipse Mars, the latest version, and installed Java 1.8_66, and got a simple "Hello World" test to run in the console mode. After downloading Glassfish 4.1.1, the latest version, I set up a simple "Hello World JSF" project, but I'm unable to associate it with the server. On right clicking on the Glassfish server in the server window and selecting "Add and Remove", I keep getting the message:

"There are no resources that can be added or removed from the server."

On right clicking on the project then selecting Properties > Project Facets, everything appears to be in order, and have the following selected:

Dynamic Web Module 3.1
Glassfish Web Extensions 4.0
Java 1.8
JavaScript 1.0
JavaServer Faces 2.2

which is identical to the setup I had with Eclipse Kepler, except for the version of Java, and as far as I know, there is no Glassfish Web Extensions 4.1. What is going wrong, and how to I associate the project with the server?

Glassfish is running normally, and get the greeting page at localhost:8080 when I start it manually using asadmin start-domain in the console. However, if I start it from Eclipse, I get the following text in the Eclipse console:

Starting preview server on port 8080

2015-12-25 19:01:41.539:INFO::main: Logging initialized @1285ms
2015-12-25 19:01:41.793:INFO:oejs.Server:main: jetty-9.2.13.v20150730
2015-12-25 19:01:42.173:INFO:oejs.ServerConnector:main: Started ServerConnector@3bcacab5{HTTP/1.1}{0.0.0.0:8080}
2015-12-25 19:01:42.177:INFO:oejs.Server:main: Started @1931ms

with the last four lines in red. When I go to localhost:8080 I get the message:

Error 404 - Not Found
No context on this server matched or handled this request.
Contexts known to this server are:

so the server is obviously running, but doesn't pick up the HTML in the default page. This is presumably related in some way to why I cannot get anything linked with Glassfish in Eclipse.

Some ideas on what is happening and how to fix this would be very welcomed indeed, as I really want to upgrade to the latest version of Eclipse, Java and Glassfish.
3 years ago
JSF
Hello,

I have a JSF application with this code in the xhtml page:


and the corresponding snippets of the Java code are:

Then when a button is clicked for initialization, an action is performed that calls the following method:

and when a button is clicked to submit a selected item, the following code is called:

This works and the menu is shown correctly. When an item is selected and a button clicked, its index is found from prodNum = productValues.indexOf(product);
in the last method above.

That is all well and good, and I've used similar code before. However, I 'm keeping two version of the data, one version in the ArrayList><String> productValues and productLabels, and a copy in SelectItem[] products, thus I'm using three collections instead of one. There must be a better way of doing this.

Accordingly, I replaced these three declarations by:

but left product as a String. The code for the getters and setters were changed to:

The initialization method is now:

Most of this works correctly using only ArrayList SelectItem products without the two ArrayList and the separate SelectItem[], and the values and labels are put directly into products here. The menu works and I can select an item. However, I am unable to find the correct method for finding the index in the submit method,
namely:

which has not been changed here. In spite of trying out various ideas, prodNum always returns with -1, which means it cannot find the index of the selected product, where product is a String. Everything else seems to work correctly, and products.get(prodNum).getLabel() works if I manually give prodNum a valid index, but because it's -1 it fails.

I've spent quite a lot of time trying to find out how to fix this problem, but so far without success, and would most appreciate some kind help with this. >
4 years ago
JSF
Hello,

Thanks you very much for your very useful tip. After a lot of messing around I managed to get the code to work as in tutorial #33, although I have not tried #34 yet. From the lower part of the page on the link you gave me I put in the following xml code:

after obviously commenting out the disable 2nd level cache, which I left but commented out for future reference.

However, I was not home and dry, because when the application started up, it could not find the slf4j api, which was not in any of the Hibernate jars. After googling around, I found on:

http://stackoverflow.com/questions/12926899/java-lang-noclassdeffounderror-org-slf4j-loggerfactory

that slf4j-api-1.7.2.jar and slf4j-jkd14-1.7.2jar needed to be downloaded from:

https://hub.jazz.net/project/morenoli/hangmangame/overview#https://hub.jazz.net/gerrit/plugins/gerritfs/list/morenoli%252Fhangmangame/refs%252Fheads%252Fmaster/WebContent/WEB-INF/lib

After downloading these two jar file and putting them in my Eclipse project, the application worked and generated only one SQL select statement, as stated in the tutorial.
Hello,

I'm new to Hibernate and have been going through the tutorials at http://www.youtube.com/watch?v=Yv2xctJxE-w&index=1&list=PL4AFF701184976B25. There are 34 tutorials and 36 video, as tutorial #3 is split into three videos. Unlike in the tutorials, I'm using the later version Hibernate 4, and a different database, MySQL, with Eclipse. Apart from a few minor changes for the configuration, and some minor differences with some of the annotations, I've got essentially all the examples to work so far up to and including tutorial #32.

However, I'm having problems with Tutorial #33, and I'm unable to get the second level cache to work, if I can fix this, then tutorial #34 should also work, then I'm home and dry with this set.

I'm using Eclipse with Java 1.7, and have hibernate-core-4.0.1.Final.jar, hibernate-commons-annotations-4.0.1.Final.jar and various other jar files in my Hibernate library, and before tutorial #33 they work correctly. However, on downloading hibernate-ehcache-4.0.1.Final.jar and putting it in my Hibernate library, configuring the hibernate.cfg.xml file, and annotating one of the classes, no matter what I do, the application fails.

Specifically, this is what I'm doing in following the tutorial #33. For the main class I have:

Note that I'm using slightly different code for the session factory, as the version in the tutorial is now deprecated.

The UserDetails class is as follows:

and when the hibernate.cfg.xml files is configured with:

the code works with the 2nd level cache disabled, which is the default, and two SQL query strings are created in the main method, one for each of the two session, as expected.

After putting hibernate-ehcache-4.0.1.Final.jar in the library and trying out various ideas in the xml file, such as:

together with the annotations:

placed immediately after @Entity in the UserDetails class, when the application is run, I get the error message:

Exception in thread "main" org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]

Based on the link http://howtodoinjava.com/2013/07/04/hibernate-ehcache-configuration-tutorial/, I tried out the xml for Hibernate 3.3 and above, but this generated an error because it did not understand "key". The example in the tutorial presumably will not work as it is used with an earlier version of Hibernate.

Does anybody know how the xml file should be configured, and is this the main problem? As far as I can see the UserDetails class is correctly annotated. In this tutorial when the application is working correctly, only one SQL query is generated as the 2nd level cache is used to store the string after the 1st session is closed, but I never get as far as that because it is unable to use the 2nd level cache.

I would be very grateful if someone could kindly help me find where I have gone wrong.
Hello,

I'm writing this on behalf of a colleague who is using Eclipse for the first time and is having some problems. I sent here a war file of a JSF 2.2 application that I created with Eclipse on my computer, which uses Windows. She has a Mac, and unfortunately I am not at all familiar with Mac computers. Her message is as follows:

I am compiling with Eclipse a web application which uses JDK7 on a Mac OS 10.9 MacBookPro.
Everything works fine, but Eclipse validation fails with this strange message:

I've read on the web that I should change the Java preferences. but in Preference System/Java/ I only find onglets for General,Upgrade,Java,Security,
and Advance and not Web like on PC. So I do not know how to change the Java preferences not to complain about this type of variables.

Ignoring those errors, I can try to run my application, but I run into another problem:
"The server does not support version 3.1 of the J2EE Web module specification."

Here too I found on the web some indications how to go around this which do not work:
right click on my project name/properties/ and change the version of the Dynamic Web Module to a lower version.
Here I get an error message: "Cannot change version of project facet Dynamic Web Module to 2.5."
And it displays the same error message no matter which version I choses other than the latest 3.1 version.

So alternatively I have Run New_Configuration instead. But then here I get this error:

Exception occurred executing command line.
Cannot run program "/Users/fallard/Documents/workspace/simulator-jsf22-25/simulator-jsf22-25/.project" (in directory "/Users/fallard/Documents/workspace/simulator-jsf22-25/simulator-jsf22-25/build"): error=13, Permission denied

And it did not help to change the permissions of the directory tree.

So I am stucked. Some help?

She attached an image file containing error messages from Eclipse which just goes "String method(String), String method(String), String method(String)....." and so on for many lines. These errors seem to be produced in the xhtml file when an action is invoked with an argument, such as <h:commandButton id="continue" value="Continue" action="#{login.nextPage('option')}" /> This work perfectly correctly on my system.

Does anybody have any ideas?
Sorry for the typo in the title. How do I correct that?
5 years ago
JSF
Hello,

I'm having some problems styling the PrimeFaces upload tag <p:fileUpload /> in my application.

In my xhtml code I have the following:

This all works correctly, both the AJAX update and on the server, but I'm unable to get the button or buttons displayed in the way I need.

By including the following in my CSS:

the first sets the width of the button bar, and by looking at the HTML code generated by PrimeFaces, I discovered that the second hides the "+" to the left of the "Choose" button, which here has been replaced by the text "Choose the File to Upload". However, this text is displayed on two lines, with the word "Upload" on the second. I want the whole text to be on one line, but no matter what I do, I cannot get this to work properly. The third line of my CSS code does indeed reduce the height of the button, but the width does not work at all, and the last part of the text is simply lost. How do I put all the text on one line and adjust the width of the button?

Another question is that when I remove the auto="true" attribute from the tag, which I had originally, the "Upload" button is displayed to the right of the "Choose" button, and when a file is chosen but not yet uploaded, it is displayed below the button. This is a capability that I might still want, however, I am unable to style the display, and in particular the progress window to the right of the file name and size. All the files I want to upload are relatively small text files, and I want to adjust this window or even hide it completely. How is this done?

Incidentally, because the files are all quite small, I have disabled the display of the "Cancel" button, so either only the "Choose" button is shown, or the "Choose" and "upload" buttons.

I would most appreciate in getting these questions resolved, in particular the first one.
5 years ago
JSF
Hi Tim,

For your interest, it looks as if I resolved this problem and got an application working with the PrimeFaces p:fileUpload tag. I did the following:

1) Go to http://repo1.maven.org/maven2/org/glassfish/javax.faces/2.2.5/ and download the file javax.faces-2.2.5.jar.

2) Go to my folder glassfish-4.0\glassfish4\glassfish\modules and rename the original JSF2.2 file javax.faces.jar to a backup name.

3) Copy javax.faces-2.2.5.jar from (1) into the folder in (2), then rename it javax.faces.jar.

4) Add encType="multipart/form-data" to my h:form tags in my code where files are uploaded.

5) Restart Glassfish.

The files now appear to be uploaded correctly, and AJAX works. Also other data are written correctly as well.

Before I upgraded to JSF 2.2 the file uploads and AJAX worked correctly without specifying an encoding type, but until performing the steps above with JSF 2.2, either I left out the encoding in the forms and AJAX worked but file uploads did not, or with encType="multipart/form-data" the files uploaded correctly but AJAX failed to work.

However, these steps do not appear to fix the problems when using the new JSF 2.2 file uploads, so there is perhaps more to deal with. As my application currently uses the PrimeFaces file uploads, as it was written before JSF 2.2 was available, for now that is probably good enough.
5 years ago
JSF
This is only a simple example to show that AJAX is not working when enctype="multipart/form-data", and indeed I could separate out the form into two parts, and in fact I tried that and it works. The problem is that in my real application the form has some included components from some other xhtml files, and one of these files has an upload component, so re-arranging the code will be a bit tricky.

Another option is to have the form tag with enctype="#{myBean.enctype}", where in my bean I have a string holding the encoding type, then have a getter and a setter to specify whether the private String enctype holds "multipart/form-data" or "application/x-www-form-urlencoded", then have an action to switch between the two types, but that will get a bit messy.
5 years ago
JSF
I'm using exactly what the link provided, namely:

before the class declaration, and as I said, the file upload works correctly when I have enctype="multipart/form-data" in the h:form tag, but in doing this, apparently I have to sacrifice AJAX functionality.
5 years ago
JSF
OK, thanks, the original code was copied from http://www.javatutorials.co.in/jsf-2-2-file-upload-example-using-hinputfile/ , which has an xhtml file and two Java source files, which I copied exactly before making a few changes.

I changed the xhtml file so that it is as follows:

Apart from a few layout changes, the only changes of consequence are the code between the beginning and end of the AJAX test.

The two Java classes are InputBean.java and FileUploadValidator.java. The only changes I made to the former are to include the following:

I.e. the boolean check and its getter and setter for the AJAX action. The other Java class I didn't change at all.

In the xhtml file, when the encoding type is omitted, the AJAX action fires correctly, and the text "Some text appears here" is displayed or not displayed according to whether the check box is checked or not. This is exactly what is supposed to happen, but the application crashes with the message:

The request content-type is not a multipart/form-data

when attempting to upload a file, which makes sense. However, if I put in enctype="multipart/form-data" in the form, the file upload works without an error, but on clicking the check box, it disappears and no text is rendered. If I refresh the browser (Firefox), the check box reappears as checked, but it does not do anything.
5 years ago
JSF
That is exactly the problem. If I include multipart/form-data encoding type in my JSF 2.2 file, then the upload works correctly, however, AJAX does not work properly or not at all in that case. It only works if the encoding type is left out, but then the upload will not work.

I tested this out with a simple example. I put in the form a check box and some text that is displayed when the check box is checked using a boolean variable in the bean. When the encoding type is set to multipart/form-data, as it has to be for file uploads, the test AJAX example does not work, but it works correctly when the encoding type is not specified, i.e. the default.

No other changes at all are made, so there is obviously a problem.

Something similar happens with the PrimeFaces upload using JSF 2.2, the file uploads throw an exception, but not with JSF 2.0 for exactly the same code. In the case of PrimeFaces the encoding type is generated. If I specifically set the encoding type to multipart/form-data, AJAX will not work. This was all OK with JSF 2.0 but not JSF 2.2. Of course JSF 2.0 didn't have its own file upload capability so had to use PrimeFaces. I never tried out JSF 2.1
5 years ago
JSF
Hello,

I'm having problems with using the h:inputFile tag with JSF 2.2 and Glassfish 4.0 on Eclipse. The file uploads work when the enctype is set to "multipart/form-data" in the h:form tag, but AJAX will not work. When I leave out the encType (defaults to "application/x-www-form-urlencoded") AJAX works but the uploads do not work, and in fact Glassfish crashes and generates the message:

The request content-type is not a multipart/form-data

Likewise I'm having the same problems with the PrimeFaces file upload tag p:fileUpload. In a JSF 2.0 it works correctly, but with JSF 2.2 it's giving the same problems and generates the message above.

When I start up Eclipse it tells me that Mojarra 2.2.0 is installed. Is this the source of the problem, and if so, how do I install a later version of Mojarra?
5 years ago
JSF