JSF commandButton giving 404 - /500.shtml - jsf

I have a JSF commandButton, simply should submit a form,
<h:form role="form" enctype="multipart/form-data">
....
<h:commandButton id="submit" value="add"
onclick="return validate('submitForm')"
action="#{propertyBean.submit}"
class="btn btn-green btn-lg arabic"
rendered="#{propertyBean.isNew == true}">
</h:commandButton>
</h:form>
the button is working okey on localhost but when I deploy the application on a server I get this error
HTTP Status 404 - /500.shtml
type Status report
message /500.shtml
description The requested resource is not available.
the action method is never called, as the backing methods prints a statement as its called.

This problem is two-fold. A HTTP 500 error occurred (usually, because an exception was thrown), so the container needs to display a HTTP 500 error page which was in your case apparently registered as /500.shtml, but the container could in turn not find that file and hence the HTTP 404 error on that file.
In order to find out the problem causing the method not being invoked, you've 2 options:
Read the server logs to find the exception.
Register a valid HTTP 500 error page and let it print the stack trace.
Once having the real exception at hands, you can easily solve the underlying problem.

Related

Primefaces FileUpload: handle firewall error blocking upload

We have a JSF application that is currently working and live that uses Primefaces 7.0. The application allows users to upload files using the Primefaces FileUpload component which we then handle and process.
The firewall team is forcing a firewall to sit in front of the upload process which will block upload requests from hitting the application if it deems the file to not be suitable and return a 503 error to the browser. I am struggling to work out how we can handle the 503 error within the JSF application as the request never hits the server and I can't find a suitable attribute we can add to the FileUpload component that would listen for the 503 (tried using onerror as shown in code below but unfortunately it doesn't get called when the 503 error occurs). Without handling this error, nothing is presented to the user to suggest anything happened. Ideally we would present a growl message to the user asking them to try a different file type.
Below is the code currently for the FileUpload component however I'm not sure if it's any use as I'm looking more for advice than a code fix.
Anyone have any idea on how to potentially handle the 503?
Thanks
<p:fileUpload widgetVar="upload" id="upload"
disabled="#{user.filesRemaining eq 0}" label="SELECT FILES"
fileUploadListener="#{controller.handleFileUpload}"
styleclass="smallCommandButton" mode="advanced"
dragDropSupport="true" auto="true"
allowTypes="/(\.|\/)(jpeg|jpe|jpg|png|pdf)$/i" sizeLimit="10485760"
invalidSizeMessage="Image files must be under 10MB in size"
invalidFileMessage="Only JPG, PNG or PDF files can be uploaded"
onerror="#{controller.handleUploadError()}"
onstart="PF('uiBlocker').show()"
oncomplete="PF('uiBlocker').hide()">
</p:fileUpload>
Found a solution, I needed to add the below code to my fileUpload component, 'arguments' carries the information for the error:
onerror="handleUploadError(arguments)"
and then create the corresponding javascript function to handle the error e.g.
function handleUploadError(arguments) {
if(arguments[0].status === 503) {
**create message for user here**
}
}

Returning invalid view from JSF action method shows warning in the facelet, but how could I detect it earlier?

I have a JSF 2.3 application.
In my LoginBean, the username and password entered by the user are varified and then the user is redirected to the URL initially inquired: for example if the user inquires:
http://myhostname/admin/manage.jsf
then because every resource under http:///admin requires authentication, the user is first redirected to the logon view, something like
http://myhostname/login/login.jsf
and then, upon successful authentication, they are redirected to their initially inquired URL (in this case, the first URL above)
However, if the initially inquired URL is a view that does not exist, i.e.
http://myhostname/admin/nonExisting.jsf
after the user gets authenticated, nothing happens: He / she is neither shown an error page, nor an erroneous log entry is made in the logs. Just the user remains on the login page.
How could I solve this?!
I added an error handling in the facelet like this:
<p:growl id="messages" autoUpdate="true" showDetail="true" />
and then, for the logon button:
<p:commandButton action="#{loginBean.login}" value="Log In" update="#form"/>
Now, when a non-existing view is returned, I do see the warning message:
but how coul I handle it earlier?

Can not access the javax.servlet.error.* for error code 500 in JSF 2.2 with PrimeFaces 5.1

I am working on JSF 2.2 with PrimeFaces 5.1, in my application for exception handling I have configured error code 500 in web.xml like below
<error-page>
<error-code>500</error-code>
<location>/500.xhtml</location>
</error-page>
and in 500.xhtml I am trying to access error code like below
<h:outputText value="#{requestScope['javax.servlet.error.status_code']}"></h:outputText>
at the time of testing I found that, I was redirected to a url like below
https://localhost:8443/appname/500.xhtml
which is wrong it should like https://localhost:8443/appname/configerd_path
and here I found that in requestScope I don't have javax.servlet.error.*
so I cannot display error code, error message and so on ...
I would like to ask here that, what is the best practice to handle this kind of error in JSF 2.2 and how can I access error code and error message ?
As I am using primefaces and it's provides a built-in exception handler to take care of exceptions in ajax and non-ajax request easily.
with the following EL, I am able to catch exception at my 500.xhtml page.
<h:outputText value="#{pfExceptionHandler.exception}" ></h:outputText>
<h:outputText value="#{pfExceptionHandler.type}"></h:outputText>
<h:outputText value="#{pfExceptionHandler.message}" ></h:outputText>
I hope it helps others :-)

Intercepting session time-out when calling show on rich:modalpanel

I am trying to intercept a session time-out when a user click on commadLink that shows a modal panel. So far, I haven't been successful...
Example :
<a4j:commandLink execute="#form" oncomplete="#{rich:component('ContactModalPanel')}.show(); return false;" limitRender="true" render=":ContactModalPanelSubViewForm:ContactDataTable">
Many thanks,
JSF 2.1
RichFaces 4.3.3.Final

Faces in ADF can't get the request parameters

I have an ADF web application with Faces 1.2
In my managed bean I am trying to access the parameters of the post request, but always getting null.
This is my post form that I am posting to the Faces:
<form name="input" action="http://127.0.01:7072/myapplication/faces/login.jspx" method="post">
<input type="hidden" name="user" id="user" value="myUserName"/>
<input type="submit" value="Submit"/>
</form>
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("user");
FacesContext.getCurrentInstance().getExternalContext().getRequest().getParameter("user");
But I always get null and the method of the form I get is: GET, strange!
when you make a request for a URL like:
http://server/faces/somepage.jspx
ADF framework respone you by a "HTTP Error 302 Moved temporarily" response and redirect you to the URL like :
http://server/faces/somepage.jspx?_adf.ctrl-state=888888&_afrLoop=9999999
so your first POST request is omit and browser send an other request to the new URL that ADF returned in response, so because POST method send parameter in the request body the browser dont resend them in new Get request
so i think there is no way for you to get parameters direcly in side the ADF page ! :(
but i think the best way is to create a Servlet and get you param in it and put them to session and then redirect the user from servlet to your ADF page :)
I managed reading the request parameters through including my parsing operations in the filter mappings that my application was using.
In a very abnormal way FacesContext always rejected revealing the current parameters, till now it's a mystery for me why it's designed liked that, even through its external context ...

Resources