The following is a simple use case of <f:viewAction>
.
<f:metadata>
<f:viewParam name="id" value="#{testManagedBean.id}" maxlength="20"/>
<f:viewAction action="#{testManagedBean.viewAction}"/>
</f:metadata>
The managed bean involved.
@ManagedBean
@ViewScoped
public final class TestManagedBean implements Serializable {
private static final long serialVersionUID = 1L;
private Long id; //Getter and setter.
public void viewAction() {
System.out.println("viewAction() called : " + id);
}
}
The parameter id
is passed through a URL. There is a conversion error, when a non-numeric value like xxx
is passed through the URL in question and the viewAction()
method associated with the listener of <f:viewAction>
is not invoked.
The value of id
is null
in this case. I would like to redirect to another page, when id
is not convertible to a desired target type (like in this case) or id
is not validated against the specified validation criteria to avoid potential exceptions which are likely to be thrown in the LazyDataModel#load()
method of PrimeFaces or somewhere else in the associated managed bean whenever access to these parameters is attempted in the corresponding managed bean. For this to be so, the viewAction()
method should be invoked.
How to proceed with this? Should I use
<f:event type="preRenderView">
in conjunction with <f:viewAction>
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…