0

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:

enter image description here

but how coul I handle it earlier?

Alex Mi
  • 1,409
  • 2
  • 21
  • 35
  • 1
    So, you're using ajax to login, and there's no exception handler for ajax requests? – BalusC Apr 30 '20 at 17:25
  • nope, I am using form submit like this: – Alex Mi Apr 30 '20 at 17:36
  • So you don't know that **by default** the PrimeFaces `p:commandButton` is doing ajax https://www.primefaces.org/showcase/ui/button/commandButton.xhtml? An [mcve] would have shown this. – Kukeltje Apr 30 '20 at 21:55
  • No, I did not know. However replacing p:commandButton by h:commandButton does not change anything – Alex Mi May 01 '20 at 05:04
  • Please let me know what "the normal" behavior should be - shall I get an error, a HTTP 404 or what? – Alex Mi May 01 '20 at 05:08
  • this problem, and its solution are described here: https://stackoverflow.com/questions/27526753/exception-handling-in-jsf-ajax-requests – Alex Mi May 01 '20 at 07:52
  • with a plain `h:commandButton` you should get an error... Certainly if you run your application in development mode. – Kukeltje May 01 '20 at 09:10

0 Answers0