在此之前,我是Oracle ADF Faces的初学者。我知道Primefaces,我通常在 commandLink 和 commandButton 中使用 @process 和 @update 来处理或更新指定这个地方。当我创建 commandLink (或链接)时,ADF面孔让我感到困惑,它将处理表单中的所有组件
这是一个例子
看看图片。当我点击“按钮”时,它会处理所有表单,但我只想处理“表”并更新“ child_form_02 ”。 如何在ADF Faces中执行此操作?
提前感谢。
答案 0 :(得分:0)
您可以将表单拆分为2个子表单(af:子表单) 请看下面的例子: http://www.oracle.com/technetwork/developer-tools/adf/learnmore/40-ppr-subform-169182.pdf
答案 1 :(得分:0)
正如Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes的答案中所解释的那样,你应该使用:
<h:commandButton ...>
<f:ajax execute="childForm2:clientId1 childForm2:clientId2 ..."/>
</h:commandButton>
正如您已经提到的,这可能会导致一个痛苦的长而不可维护的字符串。在PrimeFaces中,您可以使用@(...)
来jQuery您要处理的输入。在简单的JSF中没有这样的东西。
您可以做的是在实用程序bean中创建一个方法,它可以获取特定组件中的所有输入clientIds
。 OmniFaces Components
实用程序类在这里派上用场:
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);
}
现在您可以在XHTML中使用它,如:
<h:commandButton ...>
<f:ajax execute="#{ajaxBean.inputClientIds('childForm2')}"/>
</h:commandButton>
如果您正在寻找纯粹的JSF /非OmniFaces解决方案,事情会变得更加冗长:
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);
}
}
您可以考虑使用一些实用方法创建一个类。