Primefaces 4.0
I need to reset the initial disable-state of components contained in a p:dialog
.
The following simplified example shows the problem:
XTML:
<p:dialog header="header" widgetVar="dialog" appendTo="@(body)"
modal="true" resizable="false">
<h:form id="form">
<p:inputText value="#{bean.text}" id="text" />
<p:commandButton value="Disable InputText"
action="#{bean.disableInputText}" />
<p:commandButton value="Cancel"
action="#{bean.cancelDialog}"
process="@this"
update="@form" immediate="true">
<p:resetInput target="@form"/>
</p:commandButton>
</h:form>
</p:dialog>
ManagedBean:
@ViewScoped
public class Bean {
public void disableText() {
final FacesContext context = FacesContext.getCurrentInstance();
final UIViewRoot root = context.getViewRoot();
final UIComponent component = root.findComponent(":text");
if (uiComponent instanceof InputText) {
((InputText) uiComponent).setDisabled(true);
}
}
public void cancel() {
// reset disable-state of the disable-state of all components in a generic way.
}
}
While using the dialog the p:inputText
element can be disabled. If the dialog was canceled and opened again, inputText should not disabled. The initial state should have been restored. Please note that this example is simplified and i am looking for a general solution that also works with a formular with 10+ input elements.