Why uploading file with tomahawk is not working? - jsf

I have an Icefaces 3.x + JSF 2.1 app where I tried to integrate upload file solution from here but I receive
14:31:24,506 WARN
[org.apache.myfaces.custom.fileupload.HtmlFileUploadRenderer]
(http-localhost-127.0.0.1-8080-3) t:inputFileUpload requires
ExtensionsFilter or TomahawkFacesContextFactory configured to handle
multipart file upload, and any of them has been detected. Please read
the instructions on
http://myfaces.apache.org/tomahawk/extensionsFilter.html for more
information about how to setup your environment correctly. Please be
sure ExtensionsFilter is the top most filter if you are using multiple
jsf libraries. 14:31:24,507 WARN
[org.apache.myfaces.custom.fileupload.HtmlFileUploadRenderer]
(http-localhost-127.0.0.1-8080-3) t:inputFileUpload requires the
current request be intercepted by the filter in order to handle forms
with multipart encode type. ExtensionsFilter was initialized but the
current request was not intercepted. Please add a filter-mapping entry
to intercept jsf page requests.
which is pretty strange because I added:
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
into my web.xml but still the uploaded file is null.
Any clue to what I do wrong?

Related

Liferay Vaadin bootstrap Content Encoding Error

I'm trying to convert our Vaadin porlets to serve the theme, widgetset etc from the portlets own web application rather that from the ROOT (Liferay) application but am hitting a content encoding problem.
I've added to the portlet.xml
<init-param>
<name>vaadin.resources.path</name>
<value>PORTLET_CONTEXT</value>
</init-param>
and to the web.xml
<servlet>
<servlet-name>VaadinServlet</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VaadinServlet</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
The portlets wont start as they can't load {WEB_APP}/VAADIN/vaadinBootstrap.js?v.7.7.7
If I try and load the js file manually in Firefox the error I get is
Content Encoding Error
The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.
Please contact the website owners to inform them of this problem.
If I use wget to load the URL it works perfectly and downloads the bootstrap.js file.
We have Liferay 6.2EE and Vaadin 7.7.7
I've managed to solve this. It appears that VaadinServlet checks for the gzip header, and if found returns the .gz version of the file. This was subsequently getting gzipped again by the HTTP server. The solution was to override the Servlet and disable the gzip code.
<servlet>
<servlet-name>VaadinServlet</servlet-name>
<servlet-class>com.foo.MyVaadinServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VaadinServlet</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
Then created a custom Servlet like this where I always return false for allowServePrecompressedResource.
package com.foo;
import javax.servlet.http.HttpServletRequest;
import com.vaadin.server.VaadinServlet;
public class MyVaadinServlet extends VaadinServlet {
#Override
protected boolean allowServePrecompressedResource(HttpServletRequest request, String url)
{
return false;
}
}

LazyInitializationException in jsf project

I am facing the LazyInitializationException in my jsf project.
and I also know that fetch = FetchType.EAGER is not the right way to solve my problem.
I got some idea from this post http://blog.gmorales.net/2012/03/how-to-solve-orghibernatelazyinitializa.html that there is a solution using OpenSessionInViewFilter:
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilterr</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
so in other word, I have to implement the Spring framework for my project?
I want to know is there a way that JSF provided to solve this problem?

Forwarding a request from a JSF managed bean to a Struts 2 action does not work

Within a JSF managed bean, I have the following code taken from this past question:
String uri = "/myAction";
FacesContext.getCurrentInstance().getExternalContext().dispatch(uri);
myAction is the name of a Struts action that is defined in my struts.xml.
However when I access the JSF bean, I am not forwarded to /myAction. Instead I'm getting a 404 http error: The requested resource (/MyApp/myAction) is not available.
Why doesn't it work??
When I try to access /myAction directly from a browser by going to http://localhost:8080/MyApp/myAction all works fine.
The clue is in the javadoc for the dispatchmethod:
"Parameters:
path - Context relative path to the specified resource, which must start with a slash ("/") character"
i.e it's dispatching to a url relative to your application context,not your webserver root folder
What you need is the redirect method which redirects to an absolute url.
Set the Struts 2 Filter in web.xml to accept forwards (and direct requests (or redirects)):
In your web.xml, change:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
To:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<!-- uncomment if you plan to include struts action output -->
<!--
<dispatcher>INCLUDE</dispatcher>
-->
</filter-mapping>
Credit:
http://www.coderanch.com/t/59584/Struts/request-dispatcher-struts-action
http://docs.oracle.com/cd/B32110_01/web.1013/b28959/filters.htm#BCFIEDGB

Dispatcher-servlet.xml - not mandatory?

I am working on an assignment that is already built to some extent. It is a Spring 3.0 project with Spring Integration and Spring MVC. I see that in web.xml, the is defined and the name is associated to the DispatcherServlet class. But in /web-inf/ I don't see the Dispatcher-servlet.xml
when I looked at the spring documentation, I read that the Dispatcher-servlet.xml is mandatory.
The app is working fine. The jsp is fetched and the flow is as expected.But without the Dispatcher-servlet.xml, how is it working? Any thoughts?
Thanks,
Jan.
Eg: here is my web.xml definition. Over here my dispatcherservlet name is springController-servlet.xml which is placed in the web-inf folder.
<servlet>
<servlet-name>springController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springController</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
Check yours and revert back. Spring requires a dispatcher servlet file.

How to upload files in JSF 1.1?

I want to upload files in a JSF 1.1 project. JSF 1.1 doesn't support RichFaces file upload. I looked at Tomahawk, but I don't know how to use Tomahawk. Can anybody explain for me?
Which JARs do I have to use?
And taglibs?
And web.xml configuration?
And faces-config.xml configuration?
Or are there alternatives to Tomahawk?
Which JARs do I have to use?
The following ones:
tomahawk
commons-fileupload
commons-io
commons-logging
commons-el
I assume that you already have the JSF 1.1 JARs jsf-api and jsf-impl.
And taglibs?
Just the Tomahawk one, next to the two usual core/html tags:
<%# taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
And web.xml configuration?
You need the ExtensionsFilter. This filter will take care that JSF gets the right parameters out of a multipart/form-data request body.
<filter>
<filter-name>Extensions Filter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Extensions Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
And faces-config.xml configuration?
Nothing special. Just create a managed bean the usual way with a UploadedFile property which you bind to the value attribute of <t:inputFileUpload>.
See also:
How to upload files in JSF? (yes, it's targeted on JSF 1.2, but should work equally good in JSF 1.1).

Resources