While JBoss uses Tomcat as its web container internally, installation of a web application and configuring simple authentication differ from how it’s done for a stand-alone Tomcat (which is what the book describes). In addition, JBoss bundles the MyFaces JSF implementation libraries, casuing a conflict with the JSF RI libraries included with the book example application. So, how do I resolve these differences so I can run the JSF book examples with JBoss. |
Answer: Pete Bennett at JBoss/Red Hat has been kind enough to provide an answer to this question, available here: http://wiki.jboss.org/wiki/Wiki.jsp?page=OReillyJSFExamplesInJBoss |
Category Archives: FAQ
Does the JSF book cover the JSF 1.1 spec?
The JavaServer Faces specification version 1.1 was released May 28, 2004. Does this mean that the JavaServer Faces book is now obsolete, since it’s written for the 1.0 version of the specification? |
Answer: The 1.1 version of the specification is what’s formally called a “maintenance release”, but between you and me, “bug fix release” would be a more appropriate label in this case. Most of the changes are corrections of things that were clearly wrong in the 1.0 spec, such as copy/paste errors in JavaDocs method descriptions, descriptions of behavior that didn’t match the Reference Implementation (RI), and descriptions of behavior that resulted in invalid HTML (such as multiple HTML elements with the same id attribute value). The rest are clarifications of details that were underspecified in the 1.0 specification, which are important for JSF implementors but not so important for JSF application developers (the target group for the book).I discovered and reported many of these errors while writing the book, and therefore described the features as they should be rather than how the 1.0 specification incorrectly described them. The book therefore already covers most of the JSF 1.1 changes.
There are, however, a few details (primarily in the Appendices) that are affected by JSF 1.1 and a few things about the JSF 1.1 RI that you should be aware of. They are described below. Default error messagesThe JSF 1.1 RI includes the component client ID in the default error messages, so the message shown in Figure 7-1 looks slightly different. This is a change that isn’t described in the specification so other implementations may not support the message text parameter needed for this to work (which arguably means that the RI isn’t spec-compliant). Including a component identifier in the error messages is a good idea, but the client ID is a very poor identifier, because it can’t be localized and it’s typically a string that the end user doesn’t understand (such as “_id1:_id2”). A future version of the JSF specification will likely address the need for localizable, user friendly component identifiers in the standard messages in a much better way. New
|
Why isn’t my EL expression evaluated?
In a JSP 2.0 container, such as Tomcat 5, my EL expressions in template text and action element attributes are not evaluated, they are used as-is instead. For instance:
${now.time} is rendered as: ${now.time} What have I missed? |
Answer: The EL evaluation is disabled for a web application with a Servlet 2.3/JSP 1.2 deployment descriptor (web.xml file) for backwards compatibility reasons. You need to update the <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd" version="2.4"> ... </web-app> As an alternative, you can enable EL evaluation of a page-by-page basis with the |
What’s new in the 3rd edition?
I already have an earlier edition of your book. What am I missing if I don’t buy the new, third edition? |
Answer: If you have the 1st edition of the book, the 3rd edition is almost like a brand new book on the subject. So much has changed between JSP 1.1 (covered by the 1st edition) and JSP 2.0 with JSTL 1.1 (covered by the 3rd edition), making it a lot easier to develop maintainable web applications in less time.Even compared to the 2nd edition, the 3rd edition is significantly different. Here’s how the changes are described in the Preface: If you’ve read the second edition of JavaServer Pages, you’ll notice that, in this edition, even more of the custom components used in previous edition have been replaced in favor of the equivalent standard components from JSTL–a specification I’ve been lucky enough to contribute to and help shape the standard based on many of the ideas explored in the first and second editions. You’ll also notice that all the chapters have been modified (some more than others) to cover the new features in the latest versions of the JSP and JSTL specifications. A brand new chapter has been added to describe how to develop custom tag libraries using the new tag file format, and the chapters about custom library development using Java has been substantially expanded to cover the new, simplified tag handler API as well as the new mechanism for including Expression Language functions in a tag library. All chapters have also been updated to cover the features and clarifications added in the Servlet 2.4 specification on which JSP 2.0 is based on. Here’s a brief summary of the primary changes in all the specifications covered in this book:
|
Why doesn’t Tomcat find my tag library or JSTL?
When I’m running the JSP examples (or some other JSP page that uses a tag library), I receive this error:
But the tag library JAR files are installed in WEB-INF/lib as the should. What’s wrong? |
Answer: In most cases, you get this error because of one of these issues:
For very old versions of Tomcat (e.g., Tomcat 4.0.4) , another reason for this can be that the CATALINA_HOME/temp directory is missing, see http://issues.apache.org/bugzilla/show_bug.cgi?id=11489 for details Create this directory if it’s missing, restart Tomcat and try again. |
What’s new in the second edition?
I already have the first edition of your book. What am I missing if I don’t buy the new, second edition? |
Answer: The second edition is a major update of pretty much all chapters and also includes some new chapters. Here’s what one reader says about the second edition on Amazon.com:
And here’s an excerpt from the Preface that describes the differences compared to the first edition:
|
Can I run the examples from the first edition with Tomcat 4.0?
I know that the JSP 1.2 specification is now final, and that Tomcat 4.0 implements the new specification. Is there anything special I need to do to run your JSP 1.1 example application from the first edition of the book with Tomcat 4.0? |
Answer: JSP 1.2 is backwards compatible with the JSP 1.1 specification, so any JSP 1.1 application should run unchanged with a JSP 1.2 compliant container. Besides Tomcat 4.0, other containers also implement the new Servlet 2.3 and JSP 1.2 specifications.You install Tomcat 4.0 pretty much the same way as described for Tomcat 3.2 in the book. The only difference is that you should set the CATALINA_HOME environment variable instead of the TOMCAT_HOME variable. This name change refects the fact that the servlet container part is actually called Catalina, while the JSP part is called Jasper: combined they are called Tomcat.You start and shut down Tomcat 4.0 just as Tomcat 3.2, using the startup and shutdown scripts in the bin directory. Tomcat 4.0 uses a slightly different directory structure than Tomcat 3.2, but the web application directory is still named webapps. This means that you can install the example application exactly as described in the book: copy the ora directory from the jspbook.zip file to webapps/ora. That’s all there’s to it. If you like to use the example custom tag library in another application, you can take advantage of the new auto-discover feature for tag libraries introduced in JSP 1.2. This way you don’t have to mess around with tag library declarations in the web.xml file. See my JSP 1.2 article for details. That said, I recommend that you migrate to the JSP Standard Tag Library (JSTL) instead of using the custom tag library from the first edition of the book. The second edition of the book covers all you need to know to use the JSTL actions. |
The toaster and the wolf: the cover story
My copy of the first edition of your book has a toaster on the cover, but your site, Amazon.com and others show a cover with a wolf. What’s going on? |
Answer: For the first edition, the first printing came out with the toaster cover. And even though it was released in December 2000, the printing history incorrectly says January 2001. I guess the publisher was not sure it would make it out in December. O’Reilly has now decided to use animal covers for all their books, including the Java series. So the latest printing has the wolf cover instead. Similar changes will be done to all O’Reilly Java books, and some of them are already out. You can read more about this change at the O’Reilly site, and also let them know what you think about it. The second edition of the book will have the wolf cover in all printings, unless O’Reilly change their mind again 🙂 |
How can I prevent IE from caching responses?
I’m using the <ora:noCache> action described in Chapter 12 in your book, but Internet Explorer caches the responses anyway.What can I do to prevent caching? |
Answer: Unfortunately, IE is infamous for ignoring cache headers and it seems like different versions of IE have different bugs in this area. Using the <ora:noCache/> custom action from Chapter 12 in the main JSP file shouldwork, but I can’t guarantee that since some browsers are buggy. One thing you can try is to use the value 0 or -1 instead of 1 for Expires. Before changing the code for <ora:noCache>, you can test with a scriptlet: <% response.addHeader("Pragma", "No-cache"); response.addHeader("Cache-Control", "no-cache"); response.addDateHeader("Expires", -1"); %> Another trick is to use the corresponding meta tags both at the top and at the bottomof the JSP page: <HTML> <HEAD> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1"> </HEAD> <BODY> The content ... </BODY> <HEAD> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1"> </HEAD> </HTML> This is, of course, invalid HTML but it’s a solution MS provides for this bug, see http://support.microsoft.com/support/kb/articles/Q222/0/64.ASP On the server side, to make sure that changes to the JSP file take effect immediately, you should always use the include action, i.e. <jsp:include>. This has nothing to do with browser caching, though. See the book and my Top Ten Tips article for more on the different ways to include page fragments and what happens when the included fragment is changed. Finally, if everything else fails, you can make sure each request is done with a unique URL by adding a dummy query string parameter, e.g. a timestamp like “?ts=123456”. A browser can not use a cached result if the query string is different from the one for the cached result. |
Why doesn’t an empty field reset my bean property?
As you explained in When can a parameter value be null?, an empty text form field value is typically sent to a JSP (or servlet) page as an empty string parameter value.But a String property in my bean corresponding to a text field does not get set to an empty string when I use the setProperty action. What’s going on? |
Answer: I describe this in Chapter 15 in the book, in the section Unexpected <jsp:setProperty> Behavior.To match the behavior for properties corresponding to checkboxes, radio buttons and selection lists, the JSP specification says that if a parameter value is an empty string, the corresponding property setter method should notbe called. So when you use <jsp:setProperty name="foo" property="*" /> for a bean with properties corresponding to various types of form elements, an empty text field has the same effect as a checkbox that is not checked; the property is not set at all. If you use a bean to capture form input and you want to reset a property when the user clears the corresponding form field, you can use this work-around. First create a method in the bean that resets all properties: public void setReset(String ignored) { myFirstProperty = null; mySecondProperty = null; ... } Now you can invoke this method before you set the properties based on the current form field values in your JSP page: <jsp:setProperty name="foo" property="reset" value="dummy"/> <jsp:setProperty name="foo" property="*" /> |