I have a simple JSF and managed bean and I need to make POST redirect when page render and some condition is true. JSF:
<h:panelGroup rendered="#{myBean.error=null}">
<p>Some data</p>
</h:panelGroup>
In managed bean, the init()
method, annotated as @PostConstruct
and in this method I do
@PostConstruct
public void init() {
if (someCondition) {
FacesContext context = FacesContext.getCurrentInstance();
String redirectUrl = "http://myurl.com";
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
try {
ec.redirect(redirectUrl);
} catch (IOException e) {
e.printStackTrace();
FacesMessage message = new FacesMessage(e.getMessage());
context.addMessage(null, message);
}
}
}
but I need navigate user to redirectUrl with POST params and cannot find how to do it. With button it will be like this:
<form method='post' action="myUrl">
<input type='hidden' name='param1' value='value1'/>
<input type='hidden' name='param2' value='value2'/>
<input name='button' type='submit' value="Button">
</form>