When I add required="true", nothing happens
You need to <h:message(s)>show the messages of persons associated with this (input) component. You probably already know how to do this for <h:inputText>. You can do the same for <f:viewParam>.
<f:metadata>
<f:viewParam id="foo" ... required="true" />
</f:metadata>
...
<h:message for="foo" />
How can I make a redirect (or error) if f:viewParamempty?
JSF. <f:viewAction> ( , /, - /, <f:event type="preRenderView">).
<f:metadata>
<f:viewParam value="#{bean.foo}" />
<f:viewAction action="#{bean.checkFoo}" />
</f:metadata>
public String checkFoo() {
if (foo == null || foo.isEmpty()) {
return "some.xhtml";
} else {
return null;
}
}
HTTP- , ( HTTP 400):
public void checkFoo() {
if (foo == null || foo.isEmpty()) {
FacesContext context = Facescontext.getCurrentInstance();
context.getExternalContext().responseSendError(400, "Foo parameter is required");
context.responseComplete();
}
}
JSF OmniFaces, <o:viewParamValidationFailed> bean.
:
<f:metadata>
<f:viewParam ... required="true">
<o:viewParamValidationFailed sendRedirect="some.xhtml" />
</f:viewParam>
</f:metadata>
HTTP 400 :
<f:metadata>
<f:viewParam ... required="true">
<o:viewParamValidationFailed sendError="400" />
</f:viewParam>
</f:metadata>
. :