繁体   English   中英

循环中的 ADF Faces 1.1 的 JavaScript

[英]JavaScript for ADF Faces 1.1 within a loop

我在 ADF Faces af:interator中遇到了我的 js 函数问题。 我在af:iterator ( af:ouputText , af:inputText , af:selectBooleanCheckBox ) 中有 3 个控件,我想在复选框上有一个 js 函数,以便在选中复选框时, outputText的文本将被复制到输入inputText

这里的问题是在af:iterator ,ADF 将生成自己的 id 或为 id 附加一个奇怪的数字,我不确定是否应该依赖这些生成的 id 来编写我的 js 函数。 我知道我应该为此使用 PPR,但我不能。

为什么不能使用PPR? 根本不应该依赖 js ID,当假设您决定将任务流放在区域或 portlet 中时,它们会发生变化。

字段值应基于 VO 属性,如果它们不是 DB 支持的,您可以创建一个临时 VO。 然后更新 VO 上的值并调用

AdfFacesContext.getCurrentInstance().addPartialTarget(JSFUtils.findComponent("<comp_id of parent component>"));

您可以结合使用<af:clientAttribute/> and <af:clientListener/>以及一些 javascript 来实现此行为。

您还需要在<af:inputText/>上将 clientComponent 设置为 true 。

这适用于我的测试程序。

<af:document id="d1">
  <af:resource type="javascript">
    function copyFromTo(evt) {
        fromValue = evt.getSource().getProperty('fromValue');
        fromIndex = evt.getSource().getProperty('fromIndex');
        // iterator ID, then fromIndex, then inputText ID 
        id = 'i1:'+fromIndex+':it1'; 
        inputComponent = AdfPage.PAGE.findComponentByAbsoluteId(id);
        inputComponent.setValue(fromValue);
    }
  </af:resource>
  <af:form id="f1">
    <af:panelStretchLayout id="psl1">
      <f:facet name="center">
        <af:iterator id="i1" value="#{PageBean.outputTextValues}" var="row" varStatus="rowStatus">
          <af:panelGroupLayout id="pgl1" layout="horizontal">
            <af:selectBooleanCheckbox label="Copy" id="sbc1">
              <af:clientAttribute name="fromValue" value="#{row}"/>
              <af:clientAttribute name="fromIndex" value="#{rowStatus.index}"/>
              <af:clientListener method="copyFromTo" type="click"/>
            </af:selectBooleanCheckbox>
            <af:spacer width="10" height="10" id="s1"/>
            <af:outputText value="#{row}" id="ot1"/>
            <af:spacer width="10" height="10" id="s2"/>
            <af:inputText label="Label 1" id="it1" value="none" clientComponent="true"/>
          </af:panelGroupLayout>
        </af:iterator>
        <!-- id="af_one_column_stretched"   -->
      </f:facet>
    </af:panelStretchLayout>
  </af:form>
</af:document>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM