William Asher

+ Follow
since Jul 23, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by William Asher

It turns out that page 538 had only an interim solution. The real solution is on page 540, and it shows that you must initialize the row attribute value in doStartTag(). It says "you can't wait until doAfterBody(), because by the time you get to doAfterBody(), the body has already been processed once." Maybe I have learned that lesson now!
I skeptically tried initializing the tag attribute "interatorMovie" in the doStartTag() method, and then incrementing the array counter to 1.

That worked!

Here is what my tag handler class looks like now:

It certainly is not what the HFSJ authors intended, nor what they put on page 538 of their book, but it works. Now my debug code in doAfterBody() only runs twice (for array index 1 and 2), and the table looks as it should

In practice, I know that for something like this you would create a class that extends SimpleTagSupport rather than the classic TagSupport, as the Simple version doesn't require the hoop-jumping that the Classic one does.

Thanks for your help!
Thank you for your quick reply, and for suggesting that I look at the generated HTML. You were correct that some extraneous output appeared in the <table> element, as below:

However, note that in addition to the debug output that didn't belong in the table element, there is an extra <tr><td> element. I tried omitting my debug code and got the same result, as follows:

Something is triggering that extra row!
I'm running the Classic tag handler example on page 538 of Head First Servlets and JSP, and it is mostly working except I am getting a four row table, with the first row empty and the subsequent rows containing the three movie titles in my movies[] array. I have included System.out.println() invocations that show that my doAfterBody() method is only being executed three times. Why do I get four rows?

Here is my java class:

Here is an excerpt from my JSP:

Here is an excerpt from my TLD:

Here is the System.out.println() output:

My output is captured in the attached JPG file.

Any ideas?
I know this is an ancient thread and I hope I don't cause heartache by posting to it - however I just wanted to add that I just ran into this same issue (with the same AdvisorTagHandler class), and resolved it by adding jsp-api.jar to the classpath. That Jar file is present in my Tomcat 5.5.36 implementation in the common\lib directory.
I have a little more information about my problem. I tried running the Maven command with a -X option (as in mvn -X clean install) to get a ream of debug information. One of the things reported was the classpath, which was shown in the Maven output as follows:

The ELResolver abstract class resizes in the el-api-2.1.2-b05.jar file, which is the last element of the classpath. I looked at http://download.java.net/maven/2/javax/el/el-api/2.1.2-b05/el-api-2.1.2-b05-sources.jar to find the source code, and the invoke() method is present with the method parameters matching how the method is invoked in the sample loginPanel.java source code. If I understand it correctly, the repository folders listed in the classpath above are a local cache version of the downloaded jar files, all of which were refreshed as necessary by the Maven script.

I am pretty sure that none of the jar files above el-api-2.1.2-b05.jar have an ELResolver class, and I know that the D:\Documents and Settings\user\My Documents\Java\JSF\ch10\trainer-secondEdition\trainer\target\classes folder has no such class.

So what ELResolver class is Maven (and therefore javac.exe) using? The one it is using has no invoke() method (or if it does have such a method it doesn't have the expected method signature).

What am I missing and why can't I compile this application? Has anybody else successfully worked through chapter 10 of this book?

William Asher
10 years ago
I went on vacation for a week and took a rest from this problem. Am back now. I thought maybe that the system PATH variable might be the problem, and found that two different JDK folders (jdk1.6.0_10 and jdk1.6.0_17) were in the PATH, in that order. I removed the former, but that didn't help. It didn't matter, because jdk1.6.0_10 was no longer on my system anyway!

The following are the only java-related folders in my PATH, in the order in which they appear:

I checked my %JAVA_HOME% variable also just now, and its value is C:\Program Files\Java\jdk1.6.0_17.

Anybody have any idea why I'm getting the wrong version of ELResolver when compiling this program?
10 years ago
I give up! As I said, I did figure out that invoke() is a valid ELResolver method in Java EE 6. But I don't see what I need to do to get my compile to use the EE 6 version of ELResolver.

I did try downloading and installing Java EE 6 (java_ee_sdk-6-windows.exe) just now, thinking maybe I didn't already have it. All it appeared to do was reinstall my Glassfish V3 installation.

I am using Maven 2, as recommended by the book, and I'm using the pom.xml provided in the book example code. The pom.xml files have worked out of the box so far in all the previous chapters. I have no clue if the contents of pom.xml are relevant, but I have included it below.

If you have any idea what I'm doing wrong, I would appreciate finding that out! If you need any more code posted, let me know.

10 years ago
I think I have figured out part of the answer... It appears that invoke() is a valid method of ELResolver in Java EE 6, but not in Java EE 5. I must have version 5 on my work station. Investigating ...
10 years ago
I'm trying to compile the Virtual Trainer application that is described starting in chapter 10 of "JavaServer Faces 2.0: The Complete Reference", by Ed Burns, and get these errors when doing so:

The problem is that there is no invoke() method of the resolver object. That object is an instance of ELResolver. I have looked at the documentation for that abstract class and can't find an invoke() method. My java compiler couldn't find one either!

If you have succeeded in compiling this application, please let me know what to do! Thanks.

The code for the unit in error is reproduced below:

10 years ago
Nothing's "wrong" with it (in a cosmically ethical sense), but it doesn't appear to work, and isn't really in the spirit of the exercise.

When I substituted your code for the h:outputText component that I had, I got a NullPointerException when running the website. I was able to avoid the exception by commenting out the "outputText1.setValue(inputText1.getValue())" in the commandButton_action() method of the backing bean, so I suspect an attempt to set a property value not bound to a UI component may be the problem with your substitution.

I think when you use backing beans you have to bind the needed bean properties to components, using a "binding" parameter, and your suggestion omitted that parameter.

Anyway I believe the spirit of the exercise was to show how an action method bound to a UI button can update other components in the web site. I think we're using a backing bean rather than a managed bean because the data is completely transient and will not be saved.

One other minor issue with your suggestion is that the original code initialized the outputText component to "Hello!", and the suggested version omits the initialized string and immediately presents a null string.

But - thank you for your reply! Any other ideas?
10 years ago
I am trying to run an example in chapter 7 of JavaServer Faces 2.0: The Complete Reference by Ed Burns, and am running into trouble. It formats a little web page with an input field, a button, and an output field. When you type something in the input field and then click the button, the text entered is supposed to be echoed in the output field.

The example uses a backing bean to accomplish this. The bean has an action method (to which the button is bound) which not only updates the output field, it also makes the input field readonly. The odd thing is that the readonly attribute changing part works OK. The part that isn't working is the updating of the output field.

Here is the code.

First, the xhtml file, which I have called register.xhtml:

Then the backing bean source code, Hello.java:

And the web-xml:

And the faces-config.xml file:

I'm using Maven to compile this (with command mvn clean install). Here is the pom.xml file:

I think that's everything, but if you need any further code or information to help me resolve this, please post! Thanks.

William Asher
10 years ago
Thanks for your suggestion, but unfortunately I haven't had success finding the log file yet.

I had the two properties files (log4j.properties and commons-logging.properties) in the WEB-INF folder. I moved them as you suggested to a newly created classes folder under WEB-INF but got the same result - successful servlet execution with no exceptions, but I cannot find the log data anywhere.

I also tried removing the absolute path from the property value in log4j.properties, and got the same result.

Initially I tried all this without using any property files, under the assumption that the system would place the log in a default location (the Tomcat logs folder). Tomcat creates four logs in that folder (host-manager.yyyy-mm-dd.log, manager.yyyy-mm-dd.log, localhost.yyyy-mm-dd.log, and catalina.yyyy-mm-dd.log), but none of these logs contain my output. Is there a default location (and physical file name) where the log gets written?

Of course I scoured the commons-logging documentation before I posted, but I could not find any reference to a physical file where the logging data would be stored. Which is why I posted the question. Certainly somebody has used this logging facility and has then actually opened the log in a text editor to see what it contains.

Thanks in advance for any further help!

William Asher
10 years ago
I know there are no stupid questions, but this one feels stupid. I am trying to use the commons-logging API in a servlet, and can't figure out where the log is written.

Here is part of my code

Although I don't think this was really necessary, I created a commons-logging.properties file with a single keyword in it:

And I created a log4j.properties with a single keyword in it:

I have tried varying the "/" characters to "\" since I am running Tomcat 6.0 on my Windows XP system. I have looked for the log in d:\temp\mylog.log, and also in the C:\Program Files\Apache Software Foundation\Tomcat 6.0\logs folder. I can't find the log!

My program compiles with no problem and the servlet runs and displays results (it updates and displays data from a MySQL database; the code for that part is not shown above).

Any ideas as to where that pesky log is (or what it is called by default, in the absence of my attempt at overriding the default) would be appreciated.
10 years ago
I am trying to run exercise 8-1 (Test URL Encoding) in Murach's Java Servlets and JSP (2nd Edition), and am running into trouble. The chapter comes with a "cart" NetBeans web application in which the user can add selected items to a cart and then the application shows the items in a table. The premise of the exercise is that if cookies are enabled in the browser, the URL's will be encoded with the session ID once, because the URLs are processed with the encodeURL() method in the JSP files. In fact that works - the first time I add something to the cart, the session ID is evident in the URL, but after I add subsequent items the session ID disappears because cookies are taking care of session ID tracking.

The exercise suggests that I disable cookies in the browser and try running it again. The expected result is that the session ID will continue to be encoded into the URL with every page, again because encodeURL is invoked. However, when I try this using IE7, I get the same result as when cookies are enabled. I feel pretty confident I did disable cookies, because when I try to log in to www.amazon.com, it gives me an error message because cookies are disabled. They obviously need the cookies for session tracking, etc.

I tried this exercise with Firefox, and got the expected results (session ID displayed in the URL once when cookies were enabled, and they were displayed for every page when cookies were disabled).

The exercise also suggests altering the JSP's so that the URL's are not encoded. That should work fine if cookies are enabled, but should result in a "cart" that only contains one item if cookies are disabled. With IE7, the cart worked (displayed all selected items) the same, whether I had cookies enabled or disabled.

I am including below the code from one of the JSP files. Obviously it won't be terribly meaningful without the classes that are imported or the web.xml file or the servlet code. However, if somebody out there wants to attempt to answer my question (which is, "why doesn't this exercise work with IE7?") and feels they need to see all this code, let me know and I'll post it.


10 years ago