I'm starting from What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?
I have a pre render view event listener:
<f:metadata>
<f:event type="preRenderView" listener="#{loginBean.performWeakLogin()}" />
</f:metadata>
which invokes the following method:
public String performWeakLogin() {
FacesContext facesContext = FacesContext.getCurrentInstance();
String parameter_value = (String) facesContext.getExternalContext().getRequestParameterMap().get("txtName");
if (parameter_value != null && parameter_value.equalsIgnoreCase("pippo")) {
try {
return "mainPortal";
} catch (IOException ex) {
return null;
}
} else {
return null;
}
}
and the following navigation rule:
<navigation-rule>
<from-view-id>/stdPortal/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>mainPortal</from-outcome>
<to-view-id>/stdPortal/stdPages/mainPortal.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
However, it doesn't perform the navigation. It works when I use a command button as follows:
<p:commandButton ... action="#{loginBean.performWeakLogin()}" />
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…