Pretty faces + primefaces upload doesn't work - java

I have a jsf web application. I use primefaces ver. 5.3 and pretty-faces ver. 3.3.3
I have a page, catalogue.xhtml, where there is a file uploader in primefaces:
<p:fileUpload onstart="start()" oncomplete="stop()" id="image" styleClass="#{!catalogueBean.form.headerInsert ? '' : 'hidden'}" auto="true"
fileUploadListener="#{catalogueBean.imageLoad}" mode="advanced" skinSimple="true" sizeLimit="10000000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
update="imageOnline" />
My CatalogueBean:
#ManagedBean
#SessionScoped
#BeanPage(name = "/admin/catalogue")
public class CatalogueBean {
....
}
My pretty-config:
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
....
<url-mapping id="adminCatalogue">
<pattern value="/admin/catalogue" />
<view-id value="/page/admin/catalogue.xhtml" />
</url-mapping>
....
</pretty-config>
When I upload the file, I got no error, and the image is not uploaded.
I saw already other discussion, but them didn't solve my problem.
In particular I tried to add in my web.xml
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
where I declare PrimeFaces FileUpload Filter:
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
EDIT:
If I change the annotation in class CatalogueBean :
#BeanPage(name = "/page/admin/catalogue.xhtml")
in the console, after the upload, I see admin/catalog and I don't understand why...
Please let me know what I wrong, and if it's possible to map, for id = adminCatalogue, only calls in GET
Thanks

Related

How to include JSPs into others that have servlet mapping to change the URL?

I have a main file (main.jsp) which includes multiple other JSPs.
I've added some servlet mapping to main.jsp to change the url from:
folder/appname/main.jsp
to:
appname/
Here is my web.xml:
<servlet>
<servlet-name>Main</servlet-name>
<jsp-file>/folder/appname/main.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Main</servlet-name>
<url-pattern>/appname/</url-pattern>
</servlet-mapping>
The problem however, is that when I load this page i get the following error
java.io.FileNotFoundException: /page_modules/included_file.jsp
The file above is included in the main.jsp like so:
<jsp:include page="page_modules/included_file.jsp" />
Folder structure as requested:
Dynamic Web Project
>Java Resources
>src
>com.project
>servlet
>WebContent
>forms
>folder
main.jsp
>page_modules
included_file.jsp
Try using code like
<jsp:include page="/page_modules/included_file.jsp" />
Or
<jsp:include page="/forms/folder/page_modules/included_file.jsp" />

How can I secure Orbeon Form Runner with an IP filter?

The documentation here describes how to secure Form Runner with an IP Filter. I followed those instructions as follows:
Put urlrewrite-3.2.0.jar in the Orbeon Forms WEB-INF/lib folder
Configure the filter in Orbeon Forms WEB-INF/web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Put the urlrewrite.xml configuration in the Orbeon WEB-INF folder
<?xml version="1.0" encoding="utf-8"?>
<urlrewrite>
<rule>
<condition type="remote-addr" operator="notequal">0:0:0:0:0:0:0:1%0</condition>
<condition type="remote-addr" operator="notequal">127.0.0.1</condition>
<set type="status">403</set>
<to type="temporary-redirect" last="true">/unauthorized</to>
</rule>
</urlrewrite>
If I access this URL from localhost it works fine as expected:
http://myserver.mydomain.com/orbeon/fr/
If I access it from anywhere else I am not able to access Form Runner, which is good, but the redirect does not work correctly. I end up getting redirected to the following URL which does not include the application context, so I get a 404.
http://myserver.mydomain.com/unauthorized
I tried changing the value for temporary-redirect to /%{context-path}/unauthorized but then I get redirected to http://orbeon/unauthorized. I also tried %{context-path}/unauthorized but then I get a "too many redirects" error.
Any idea how I can resolve this?
I was able to get the IP Filter to simply return a 403 without redirecting the URL. In my case, this is more desirable.
<?xml version="1.0" encoding="utf-8"?>
<urlrewrite>
<rule>
<condition type="remote-addr" operator="notequal">0:0:0:0:0:0:0:1%0</condition>
<condition type="remote-addr" operator="notequal">127.0.0.1</condition>
<set type="status" last="true">403</set>
<to>null</to>
</rule>
</urlrewrite>
I found to>null</to> on a list of examples here: http://tuckey.org/urlrewrite/manual/4.0/guide.html

Primefaces 4 fileUpload handler not called [duplicate]

This question already has answers here:
How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null / throws an error / not usable
(11 answers)
Closed 7 years ago.
First of all, I have to say, that I've read all (at least a lot :)) questions here and on primefaces forums about fileuploader issues.
My configuration:
Primefaces 4
JSF 2.2
Spring
Apache Tomcat 7
Maven
I am converting a richfaces project to primefaces, and I'm stuck with a fileUpload component that is not calling the handler method.
I have tried (altough I know that from Primefaces 4 it is not necessary) putting filters in the web.xml. I've also tried without filters. I have spring security filters and a language filter among some others, but the PF was first. I've also tried setting the dispatcher to FORWARD.
I have all the needed dependecies in Maven (commons - I know that from version 4 it is not required, but nevertheless I tried)
The xhtml part:
<h:form enctype="multipart/form-data">
... /* not relevant code here */ ...
<p:graphicImage value="#{systemParamsController.image}"
id="logo" />
<p:fileUpload
fileUploadListener="#{systemParamsController.listener}"
fileLimit="1" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
uploadLabel="#{msg['button.upload.jpg']}"
cancelLabel="#{msg['button.cancel']}"
invalidFileMessage="alert('#{msg['upload.invalidtype']}');"
update="logo" mode="advanced">
</p:fileUpload>
<p:growl id="messages" showDetail="true" />
</h:panelGrid>
</h:panelGroup>
<p:commandButton value="#{msg['button.save']}" onclick="this.disabled=true" oncomplete="this.disabled=false"
action="#{systemParamsController.save}" styleClass="qs-button"
ajax="false" />
</h:panelGrid>
</p:panel>
</center>
</h:form>
The backing bean:
public synchronized void listener(FileUploadEvent event) throws Exception {
logger.debug("uploadListener!");
UploadedFile item = event.getFile();
getModel().getCustomer().setLogo(imageResizer.doResize(item.getContents(), 30, Side.HEIGHT));
}
If I click on choose, I can select a file, but after that nothing happens. The handler is not called, because there is no log message, the upload file button is inactive. I have used this component before for more complex issues without problem, so I'm sure I'm missing something obvious.
Thanks in advance for any kind of help!
Make sure you have the PrimeFaces FileUpload Filter as the first filter in your web.xml:
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
If you're having trouble with the default primefaces uploader you can try the commons fileupload:
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
We're using this Maven dependency:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
Also, try putting the file upload in its own form.

The requested resource is not available in struts2 when action class is configured in struts.xml

I've tried to create a new action class and add it to struts.xml, the action class successfully get compiled but when I run tomcat it shows The requested resource is not available 404 error on index page itself.
CreateUser.jsp
<s:form action = "CreateUserAction" >
<s:textfield name = "name" label = "Name" />
<s:textfield name = "userName" label = "User Name" />
<s:submit value = "Register" />
</s:form>
CreateUserAction.java
public String execute() {
setMessage("Hello " + getUserName());
return "SUCCESS";
}
Struts.xml
<package name="default" extends="struts-default">
<action name="CreateUserAction" class="com.ecommerce.action.CreateUserAction">
<result name="SUCCESS">/success.jsp</result>
</action>
</package>
Actions in Struts2 are mapped to the URLs that are built from the configuration. When the url of the request match the action name and namespace then it is executed, otherwise error code 404 is returned by the dispatcher. Struts2 is implemented as a filter and it's looking for the requests that are mapped in it's configuration. For example if I want it to filter all URLs I will write in web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
If you say the error 404 on index page itself, then you should ask yourself which URL corresponds to it and what action is mapped via configuration to that URL. If you need more detailed picture of what configuration is and what URLs you could enter to execute an action install the config-browser plugin.
for the above issue:"The requested resource is not available in struts2 when action class is configured in struts.xml"
I have a suggestion.
Copy and paste all the external jars in in the folder lib(WebContent-->WEB-INF-->lib)
remove all external jars from Build path (Project -->buildpath-->Configure Build path)
I found this solution is working fine for eclipse Luna with Tomacat 7

Access to jsp path with .action postfix in struts2

I have a project using struts 2.1.8. The project is configured by annotation using struts2-convention-plugin. Here is my struts config in web.xml:
<filter>
<filter-name>struts2Filter</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>
struts.xml:
<constant name="struts.convention.default.parent.package" value="borrow-default" />
<constant name="struts.convention.package.locators" value="action" />
<constant name="struts.convention.package.locators.basePackage" value="com.abc.action" />
<constant name="struts.convention.result.path" value="/" />
A.java:
#Namespace("/regist")
public class A extends ActionSupport{
#Action(value="/a", results = {#Result(location = "/a/test.jsp")})
public String execute(){
return SUCCESS;
}
}
Here is the problem, I can access the test.jsp in url http://localhost:8080/a/test.jsp and http://localhost:8080/regist/a.action, but I can still visit the same page in url http://localhost:8080/a/test.action. I don't know why this happens, what's wrong in my config or code?
I also tried some other url, it seems the namespace doesn't take effect.
In web.xml your url pattern is like:
<url-pattern>/struts/*</url-pattern>
but you are placed jsp and getting it from /a/test.jsp
once check it...
I upgraded the struts to 2.3.15.1 and this question disappeared

Categories

Resources