I have a JSF 2.1, Primefaces 4.0 web app where I want to pass some values with GET to the managed bean. For this I have used:
<f:metadata>
<f:viewParam name="id" value="#{myMB.queueId}" required="true" requiredMessage="This field is required" converter="javax.faces.Integer" converterMessage="Cannot Convert"/>
<f:event type="preRenderView" listener="#{myMB.init}" />
</f:metadata>
and the managed bean :
public MyMB{
private Integer queueId;
// setters and getters....
public void init(){
FacesContext fc = FacesContext.getCurrentInstance();
if(!fc.isPostback()){
if(fc.isValidationFailed()){
//if validation fails i want to add here a message - Ideally to keep the validation/convertion errors declared in f:viewParam....
FacesMessage fm = new FacesMessage(..put validation error message here...)
fc.add(null,fm);
try {
fc.getExternalContext().redirect("viewQueues.xhtml?faces-redirect=true");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
So i want to send the validation error on the redirected page.
I also tried with :
context.getExternalContext().getFlash().setKeepMessages(true);
but on the redirected page i do not get any message.I have to mention here that on my viewQueues.xhtml i have an tag that should display the errors.
Is there a way to accomplish that ?