Re: URLMapping pattern vs query parameters

Splash Forums PrettyFaces Users URLMapping pattern vs query parameters Re: URLMapping pattern vs query parameters

#21212

Let me explain a bit:

As you know PrettyFaces tries to encourage users to build RESTful URLs for their applications. The advantage of such URLs is that they are mostly stateless. This means that you can copy an paste the link to another browser, bookmark it, and so on. They work independently from other pages.

Additionally I think that applications should link to RESTful URLs using standard HTML links. This has a ton of advantages. The link URL will be created during rendering time. So there will be no need for postbacks when clicking them. Clicking these links will for example even work if the the user doesn’t use the browser for a long time which will typically cause the session and the view to expire (ViewExpiredException). You can even right-click the link and let the browser open it in a new tab! As you see you will get many advantages if you prefer standard HTML links over postbacks.

The JSF h:commandButton and h:commandLink are both designed to trigger actions on the server side which will require a postback to the server. But this isn’t required if you simply want to navigate to another page.

The pretty:link component (and h:link) will simply render something like this:

<a href="/account/manageAccount/123">EDIT</a>

This works very fine. The problem is that buttons behave entirely different. They are designed to submit forms, which we want to prevent. You could argue that we could render something like this:

<form action="/account/manageAccount/123" method="get">
<input type="submit" value="Edit">
</form>

But typically you will have h:form components on your page so that this new form will be embedded in another form, which will break both forms in some browsers.

The only possibility I see would be to render something like this:

<input type="submit" value="Edit" onclick="window.location='/account/manageAccount/123'; return false;">

I know that this doesn’t look nice and I’m unsure if something like this would actually work in all cases.

What do you think? Opinions?