I have tried to create a generic means of enabling/disabling form components when required.
Code: Select all
<h:form id="myForm">
<p:remoteCommand name="toggle"
process="@this,source"
actionListener="#{myBean.toggle}"
update="@form" />
<h:inputHidden id="source" />
<p:inputText id="fldDepot"
value="#{myBean.fldDepot}"
disabled="#{myBean.isDisabled('fldDepot')}" />
<formlet:jtable
id="btnDepot"
disabled="#{myBean.isDisabled('btnDepot')}"
onsuccess="document.getElementById('myForm:source').value='btnDepot';toggle()" />
<p:commandButton
id="btnNew"
disabled="#{myBean.isDisabled('btnNew')}" />
The methods of interest in my backing bean are as follows:
Code: Select all
private HashMap<String, Boolean> enabled;
public boolean isDisabled(String field) {
return enabled.containsKey(field) ? !enabled.get(field) : true;
}
public void toggle() {
FacesContext ctx = FacesContext.getCurrentInstance();
String source = ctx.getExternalContext()
.getRequestParameterMap().get("myForm:source");
if (source.equals("btnDepot")) {
enabled.put("btnOperative", true);
enabled.put("btnNew", true);
}
}
FYI. The "toggle" method is invoked from javascript after the user closes the Applet dialog. I cannot therefore, use the onsuccess on the <p:commandButton> because that executes before the applet finishes.
I want the <p:remoteCommand> to remain generic and therefore not hard-code any component names into the update attribute (hence I'm using @form).
How can I force the field values to be persisted before the remoteCommand update is processed? I don't want to add valueChangeListeners to all of my components.
Any help greatly appreciated, Martin.