As explained in the answer on Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes, you should use:
<h:commandButton ...>
<f:ajax execute="childForm2:clientId1 childForm2:clientId2 ..."/>
</h:commandButton>
As you already mentioned, this might result in a painfully long and unmaintainable string. In PrimeFaces you could use @(...)
to jQuery the inputs you want to process. In plain JSF there is no such thing.
What you could do is create a method in a utility bean which gets you all input clientIds
within a specific component. The OmniFaces Components
utility class comes in handy here:
public String inputClientIds(String clientId)
{
UIComponent component = Components.findComponent(clientId);
List<String> clientIds = new ArrayList<>();
for (UIInput input : Components.findComponentsInChildren(component, UIInput.class)) {
clientIds.add(input.getClientId());
}
return String.join(" ", clientIds);
}
Now you can use it in your XHTML like:
<h:commandButton ...>
<f:ajax execute="#{ajaxBean.inputClientIds('childForm2')}"/>
</h:commandButton>
If you are looking for a pure JSF / non-OmniFaces solution, things will get a bit more verbose:
public String inputClientIds(String clientId)
{
UIComponent component = FacesContext.getCurrentInstance().getViewRoot().findComponent(clientId);
List<String> clientIds = new ArrayList<>();
for (UIInput input : findChildsOfType(component, UIInput.class)) {
clientIds.add(input.getClientId());
}
return String.join(" ", clientIds);
}
public static <C extends UIComponent> List<C>
findChildsOfType(UIComponent component,
Class<C> type)
{
List<C> result = new ArrayList<>();
findChildsOfType(component, type, result);
return result;
}
private static <C extends UIComponent> void
findChildsOfType(UIComponent component,
Class<C> type,
List<C> result)
{
for (UIComponent child : component.getChildren()) {
if (type.isInstance(child)) {
result.add(type.cast(child));
}
findChildsOfType(child, type, result);
}
}
You might consider creating a class with some utility methods.
f:ajax
is general JSF and can be used with any component framework – Jasper de Vries