How to navigate in JSF? How to make URL reflect current page (and not previous one) -


i learning jsf , rather amazed , puzzled when realized whenever use <h:form>, standard behavior of jsf show me url of previous page in browser, opposed url of current page.

i understand has way jsf posts form same page , renders whatever page controller gives browser doesn't know page location has changed.

it seems jsf has been around long enough there must clean, solid way deal this. if so, mind sharing?

i have found various workarounds, sadly nothing seems real solid solution.

  • simply accept url misleading.
  • append "?faces-redirect=true" return value of every bean's action ,
    • figure out how replace @requestscoped else (flash scopes, cdi conversation, @sessionscoped, ...).
    • accept have 2 http round trips every user action.
  • use method (e.g. 3rd party library or custom code) hide page name in url, using same generic url every page.

if "?faces-redirect=true" gets, there way configure entire application treat requests way?

indeed, jsf being form based application targeted mvc framework submits post form same url page <h:form> been requested form. can confirm looking @ <form action> url of generated html output. in web development terms characterized postback. navigation on postback default not cause new request new url, instead loads target page content of response. indeed confusing when merely want page-to-page navigation.

generally, right approach navigation/redirection depends on business requirements , idempotence (read: "bookmarkability") of request.

  • if request idempotent, use form/link instead of post form (i.e. use <form>, <h:link> or <h:button> instead of <h:form> , <h:commandxxx>).
    example, page-to-page navigation, google-like search form, etc.

  • if request non-idempotent, show results conditionally in same view (i.e. return null or void , make use of e.g. <h:message(s)> and/or rendered).
    example, data entry/edit, multi-step wizard, modal dialog, confirmation form, etc.

  • if request non-idempotent, target page idempotent, send redirect after post (i.e. return outcome ?faces-redirect=true or <redirect/>).
    example, showing list of data after successful editing, redirect after login, etc.

note pure page-to-page navigation idempotent , many jsf starters fail abusing command links/buttons , complain afterwards urls don't change. note navigation cases used in real world applications developed respect seo/ux , many jsf tutorials fail letting readers believe otherwise.

also note using post absolutely not "more secure" because request parameters aren't visible in url. still visible in http request body , still manipulatable. there's absolutely no reason prefer post idempotent requests sake of "security". real security in using https instead of http , checking in business service methods if logged-in user allowed query entity x, or manipulate entity x, etc. decent security framework offers annotations this.

see also:


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -