0

I've a page that shows an item via its id: item.xhtml?id=xxx

If no id is provided the list of all items is shown.

In the same page there is a form used to update item's fields. Using <f:viewParam> and an hidden input I'm able to show item.xhtml?id=xxx again when I submit the form. But if a validation error occurs (I use Bean Validation) the item.xhtml appears with the list of all items and the error message. Is there a way to redirect even if an error occurs?

PS: why jsf takes away the querystring from urls? I mean that these kind of problems would no exists if the rendered form action was /context/page.xhtml?query=string instead of just /context/page.xhtml. Where am I wrong?

Alf
  • 2,291
  • 1
  • 28
  • 34

1 Answers1

0

Put the managed bean in the view scope by @ViewScoped. If you really need your bean to be request scoped for some reason, then you need to pass the parameter along by <f:param>.

<h:commandButton value="Submit" action="#{bean.submit}">
    <f:param name="paramName" value="#{param.paramName}" />
</h:commandButton>

As to the form action URL, this is by design. You can override this by providing your own ViewHandler implementation wherein you override the getActionURL() method accordingly.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • @Alf: please describe "does not work" in more detail. It's not supported in JSF 1.x, but it's definitely supported in JSF 2.x. – BalusC Mar 18 '12 at 23:42
  • it doesn't work because if a validation error occurs the page shown is item.xhtml not item.xhtml?id=xxx. I tried with `@ViewScoped`. This works but I'm using CDI. – Alf Mar 19 '12 at 08:59
  • The parameter is been sent as POST request and not GET. The validation error is apparently caused because you used the wrong `` name or value. As to keeping the URL same, use a custom `ViewHandler` wherein you override `getActionURL()` accordingly, as said. – BalusC Mar 19 '12 at 12:09