如何将值从绑定变量复制到adf中的Iterator?

时间:2019-03-14 19:13:14

标签: oracle-adf

我有一个包含许多列的adf表+一个具有button的列,这将打开一个弹出窗口以插入值

<af:table value="#{bindings.BpmCrMilestoneUPView1.collectionModel}" var="row" rows="#{bindings.BpmCrMilestoneUPView1.rangeSize}" >
                <af:column id="c49" headerText="#{bindings.BpmCrMilestoneUPView1.hints.MilestoneSeq.label}" width="50" displayIndex="-1" minimumWidth="12">
                  <af:inputText value="#{row.bindings.MilestoneSeq.inputValue}" readOnly="true" id="it16">
 </af:inputText>
    </af:column>
                  <af:column>
                <af:inputText value="#{row.bindings.Oldmilesseq.inputValue}"  id="it15">
                </af:column>

    <af:column label="openPopUp" >

    <af:button  action = "#{pageFlowScope.CRInitaitiveBean.openCommentsPopUp}" >
     </af:button>
    </af:column>
    <af:table>

这是包含输入文本字段的弹出窗口

    <af:popup  binding="#{pageFlowScope.CRInitaitiveBean.commentsPopUp}" id="p2">


    <div class="form-group" id="d7">
        <af:outputLabel value="#{lang.previous_comments}" />
        <af:inputText  autoSubmit="true" simple="true" 
        value="#{bindings.newCommentValue.inputValue}" />


   </div>
   </div>

,并且newCommentValue指向绑定选项卡中的BpmCrOutputUPView1Iterator。 如果我打开每一行的弹出窗口,然后键入values,则所有值都会正确保存

但是当我尝试以编程方式循环迭代器时,键入的值为null

这是代码

         RowSetIterator itr = ADFUtils.findIterator("BpmCrOutputUPView1Iterator").getRowSetIterator();
        while (itr.hasNext()) {
            Row row = itr.next();
            if (row != null) {
                System.out.println();
                System.out.println("Current OUTPUT Row Is Not Null");
                String newComment = (String) row.getAttribute("newCommentValue");
                System.out.println();
                System.out.println("new Comment is  -------------------> "+newComment); // it should print the typed value for that row

                but it's printed null 

1 个答案:

答案 0 :(得分:1)

对于这种特定的用例,使用强烈推荐的 JSFUtils 开源类 resolveExpression 函数会更容易。

JSFUtils和ADFUtils是三个ADF英雄Duncan Mills,Steve Muench和Ric Smith编写的两个实用Java类。您可以使用自己喜欢的搜索引擎轻松找到那些。

一旦添加到项目中,您就可以在Java bean中获得EL表达式的值,如下所示:

String newCommentValue= (String)JSFUtils.resolveExpression("#{bindings.newCommentValue.inputValue}");

以下是JSFUtils函数供您参考:

/**
 * Method for taking a reference to a JSF binding expression and returning
 * the matching object (or creating it).
 * @param expression EL expression
 * @return Managed object
 */
public static Object resolveExpression(String expression) {
    FacesContext facesContext = getFacesContext();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);
    return valueExp.getValue(elContext);
}