【问题标题】:How to use " @process and @update" in ADF Faces like Primefaces如何在 Primefaces 等 ADF Faces 中使用“@process 和 @update”
【发布时间】:2017-09-10 14:01:07
【问题描述】:

在此之前,我是 Oracle ADF Faces 的初学者。我知道 Primefaces,我通常在 commandLinkcommandButton 中使用 @process@update 来处理或更新指定这个地方。 ADF 面孔让我感到困惑,因为当我创建 commandLink(或 link)时,它将处理表单内的所有组件

这是一个插图 看图片。当我点击“button”时,它会处理所有表格,但我只想处理“table”并更新“child_form_02”。 如何在 ADF Faces 中执行此操作?

提前致谢。

【问题讨论】:

  • 我不确定。 Oracle 是否以另一种方式支持它,而不是使用 f:ajax?就像 Primefaces 所做的那样
  • f:ajax 是通用的JSF,可以和任何组件框架一起使用
  • 我明白了,我试试
  • 我不认为使用 f:ajax 是一种方式,因为我的按钮里面有这么多组件,大约 15 个组件,我不想在 f:ajax 里面写太多 id ?

标签: jsf jsf-2 oracle-adf


【解决方案1】:

您可以将表单拆分为 2 个子表单 (af:subform) 请看下面的例子: http://www.oracle.com/technetwork/developer-tools/adf/learnmore/40-ppr-subform-169182.pdf

【讨论】:

  • 所以,它没有用。我正在使用 JOPO 课程,也许这是我无法采取“跳过验证”步骤的原因,但它仍然无法正常工作:(
  • 如果您问我,在没有业务组件的情况下使用 ADF 毫无意义。 ADF Rich Faces with ADF BC 是经过 Oracle 严格测试的开发堆栈。所有其他提议的“解决方案”都只是营销。
  • 谢谢。但有时,当您是员工并被公司雇用时,您无法选择制作项目的方式。
【解决方案2】:

正如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);
  }
}

您可以考虑使用一些实用方法创建一个类。

【讨论】:

  • 哦,谢谢。我会试试看。但我不认为 Omifaces 可以与 Oracle ADF 集成。我曾尝试将 一起使用,但它不起作用
  • 如果您在使用 OmniFaces 时遇到问题,请通过 github.com/omnifaces/omnifaces/issues 报告问题
  • 顺便说一下,OmniFaces 应该与 ADF 一起使用。我在这里只使用 Components 实用程序类。您还可以使用普通的 JSF API 解析组件。这个想法仍然是一样的。
  • 我明天试试。但是你知道,ADF 的脸真的让我很困惑:/
  • 我已经在 github 上请求 BalusC 询问他“Omifaces 是否支持 ADF Faces”。感谢您的支持:)
猜你喜欢
  • 2014-02-21
  • 1970-01-01
  • 1970-01-01
  • 2012-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多