Hi again,

So far I've been unable to fix the problem from my previous posting below, but 
that can wait until I've sorted out a more serious and important issue which 
involves using JavaServer Faces to upload files.? I'm well aware that the form 
enctype has to be set to "multipart/form-data", and as JSF does not support 
file uploads directly, code has to be modified and extra jar files included.

I used the instructions and code downloaded from 
http://www.onjava.com/pub/a/onjava/2005/07/13/jsfupload.html in? an attempt to 
get this to work, after making a number of changes.? I took the code for 
"MyBean.java" and? the only change I made was to change the first line to 
"package com.onjava;" then put it in the path? "<my-root>/src/java/com/onjava" 
rather than in the path given in the example to simpify things a bit. Likewise 
I put the jsp files as provided in the in the path "<my-root>/web" omitting 
"/jsfupload" and added a plain "index.html" file which loads first then 
immideately redirects to "index.jsp".

So far so good,? in "<my-root>/web/WEB-INF" I modified the xml files for JSF 
1.2 and have the following code for "web.xml":

<?xml version="1.0"?>
<web-app 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-app_2_5.xsd";
??????? version="2.5">
??? <context-param>
??????? <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
??????? <param-value>client</param-value>
??? </context-param>
??? <servlet>
??????? <servlet-name>FacesServlet</servlet-name>
??????? <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
??????? <load-on-startup>1</load-on-startup>
??? </servlet>
??? <servlet-mapping>
??????? <servlet-name>FacesServlet</servlet-name>
??????? <url-pattern>/faces/*</url-pattern>
??? </servlet-mapping>
??? <servlet-mapping>
??????? <servlet-name>FacesServlet</servlet-name>
??????? <url-pattern>*.faces</url-pattern>
??? </servlet-mapping>
??? <filter>
??????? <filter-name>ExtensionsFilter</filter-name>
??????? 
<filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
??????? <init-param>
??????????? <param-name>uploadMaxFileSize</param-name>
??????????? <param-value>10m</param-value>
??????? </init-param>
??????? <init-param>
??????????? <param-name>uploadThresholdSize</param-name>
??????????? <param-value>100k</param-value>
??????? </init-param>
??? </filter>
??? <filter-mapping>
??????? <filter-name>ExtensionsFilter</filter-name>
??????? <servlet-name>FacesServlet</servlet-name>
??? </filter-mapping>
??? <welcome-file-list>
??????? <welcome-file>/index.html</welcome-file>
??? </welcome-file-list>
</web-app>

and for "faces.config.xml" have the following code:

<?xml version="1.0"?>
<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_1_2.xsd";
??????? version="1.2">
??? <managed-bean>
??????? <managed-bean-name>myBean</managed-bean-name>
??????? <managed-bean-class>com.onjava.MyBean</managed-bean-class>
??????? <managed-bean-scope>request</managed-bean-scope>
??? </managed-bean>
??? <navigation-rule>
??????? <from-view-id>/MyForm.jsp</from-view-id>
??????? <navigation-case>
??????????? <from-outcome>OK</from-outcome>
??????????? <to-view-id>/MyResult.jsp</to-view-id>
??????? </navigation-case>
??? </navigation-rule>
</faces-config>

Then in order to compile "MyBean" I had to include in 
"<my-root>/web/WEB-INF/lib" the following jar files:
commons-fileupload-1.1.jar
commons-io-1.2.jar
jsf-api.jar
jsf-impl.jar
tomahawk-1.1.6.jar

The last one I had a bit of difficulty finding, but it seems to have the 
correct code.? Anyway, I managed to compile the code successfully and the 
compiler created a class file in "<my-root>/web/WEB-INF/classes/com/onjava".? 
However, on creating a war file and deploying it I get in my browser the error 
message "HTTP Status 503 - ... The requested service () is not currently 
available", and in the log I get the message:

 

Exception sending context initialized event to listener instance of class 
com.sun.faces.config.ConfigureListener
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at 
org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.<clinit>(ExtensionsPhaseListener.java:49)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    blah blah blah..... etc.

I would most appreciate some kind help in getting this sorted out.? There must 
be some people around who know how to write a simple file upload utility with 
JSF.? Incidentally, I wish I could go to that conference in Phoenix, but I'm 
here working on my own in isolation in France until I return to Tucson at the 
end of September.

Christopher Sharp


?
 

-----Original Message-----
From: Christopher Sharp <[EMAIL PROTECTED]>
To: jug-discussion@tucson-jug.org
Sent: Tue, 17 Jun 2008 4:11 pm
Subject: [jug-discussion] Using "message" with JSF









Hi All,



I got back to France over two weeks ago, and I'm getting back into Java Server 
Faces.



Before leaving Tucson I got the book "A Complete Reference: JavaServer Faces" 
by C.Schalk and E.Burns in addition to some other books I brought with me, and 
I'm having trouble understanding the correct use of the tag <h:message for 
"myName"/> where id="myName" refers to something like

<h:inputText value="#{UserBean.someName}" required="true"? id="myName"/> in a 
form.? In the example in the book if the input field is left blank, the message 
to the right of the input field "Validation Error: Validation is required." is 
displayed, but when I actually try the example I get to the left the error 
message the default id provided by JSF followed by a ":" followed by say 
"myName" printed as a literal.? If I give the form an id such as "myForm" then 
the message "myForm:myName" appears to the left of the validation error 
message.? That is an improvement but I still want to know why it appears, 
rather than not as given in the book, or alternatively provide a better 
message.? Likewise with the example at 
http://exadel.com/tutorial/jsf/jsftags-guide.html where the? id is not 
displayed in the error message.



I checked that I had jsf-impl.jar and jsf-api.jar in the classpath, and in fact 
looking at the contents of the former I found in "Message.properties" the entry 
"javax.faces.component.UIInput.REQUIRED={0}: Validation Error: Value is 
required.", but for some reason it's displaying the id as a literal.



Some advice on this would be most appreciated.? I will be back in Tucson at the 
very end of September, and hope by then that I will learn much more about JSF, 
as I'm putting them to use here.



Christopher Sharp






Get the Moviefone Toolbar. Showtimes, theaters, movie news, & more! 



 

Reply via email to