I have a @ViewScoped
@ManagedBean
which creates an unique ID. This ID is rendered in a form like:
<h:form>
<h:outputText value="#{myBean.uid}" id="uid"/>
<h:hiddenInput value="#{myBean.uid}" id="hiddenId" />
....
<p:commandButton actionListener="#{myBean.create}" ajax="true" update="@form" value="Create" />
</h:form>
So far so good. On first request the page is rendered correctly. After submitting the form and in the case of validation failure, the outputText
is empty but the hidden input field keeps its variable.
Any clue what I'd have to do to prevent this behavior and too let the outputText
keep its state?
I realized that the bean seems to be initialized after each ajax request. But then, why does the hidden input field keeps the old variable?
Here is the relevant code of my bean:
@ManagedBean(name = "myBean", eager = true)
@Stateful
@Model
@ViewScoped
public class MyBean implements Serializable {
...
private String uid;
...
@PostConstruct
public void initWithData() {
this.uid = UUID.randomUUID().toString();
}
}