Forum Stats

  • 3,874,176 Users
  • 2,266,677 Discussions
  • 7,911,757 Comments

Discussions

How do I refresh a dialog view after setCurrentRowWithKey()

DrHoneybear
DrHoneybear Member Posts: 50 Green Ribbon
edited Nov 17, 2022 3:16PM in JDeveloper and ADF

Below is a method called in prepareRender() in a backing bean to an ADF view. It is supposed to refresh the on-screen dialog displaying a list of Iods (Index Diagrams as we call them). The list is 10 items per page with a radio button on the left. A session bean stores any linked Iods that a user may have entered on a previous screen (the dialog is reused on many screens). If the linked Iods is in the table in the dialog then the radio button for the corresponding row in the table should be selected and the table row highlighted. Doesn't work.

Everything works except I cannot get the on-screen dialog table row to be selected. Always displays page 1 and the first item (top) in page 1 is the radio button selected row..


The view instance. is Iods_View1; it is bound to Iods_View1Iterator.


The view (table) dialog is invoked by a calling jspx using:

 <tr:panelLabelAndMessage label=" ">
         <tr:commandButton text="#{common['common.choose']}" action="dialog:showAuthorities" partialSubmit="true"
                  id="butChooseAuthority" immediate="true" useWindow="true" windowHeight="600"
                  windowWidth="750" returnListener="#{selection_IOLIssAuthority.returnListener}">
          <tr:setActionListener from="#{selection_IOLIssAuthority}" to="#{backing_Selection.backing}"/>
         </tr:commandButton>
        </tr:panelLabelAndMessage>

...which invokes the dialog :

View (table) dialog Object:

<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core" xmlns:trh="http://myfaces.apache.org/trinidad/html"
          xmlns:tr="http://myfaces.apache.org/trinidad">
 <f:view>
  <trh:html>
   <jsp:directive.page contentType="text/html;charset=windows-1252"/>
   <trh:head title="#{loomconf['iodselection.pageTitle']}"/>
   <trh:body onload="document.getElementById('txtNo').focus();">
    <tr:form defaultCommand="search">
     <tr:panelGroupLayout layout="vertical">
      <tr:panelHeader text="#{loomconf['iodselection.iod']}">
       <tr:spacer width="10" height="20"/>
       <tr:panelBox>
        <tr:panelFormLayout partialTriggers="clear">
         <tr:inputText value="#{bindings.No.inputValue}" label="Index" columns="#{bindings.No.displayWidth}"
                id="txtNo"/>
         <f:facet name="footer">
          <tr:panelButtonBar>
           <tr:commandButton actionListener="#{bindings.Execute.execute}" text="#{common['common.search']}"
                    disabled="#{!bindings.Execute.enabled}" id="search">
            <tr:setActionListener from="#{null}" to="#{backing_IODSelection.currentIno}"/>
           </tr:commandButton>
           <tr:commandButton text="#{common['common.clear']}" id="clear"
                    actionListener="#{backing_IODSelection.clear}" partialSubmit="true">
            <tr:setActionListener from="#{null}" to="#{backing_IODSelection.currentIno}"/>
           </tr:commandButton>
          </tr:panelButtonBar>
         </f:facet>
        </tr:panelFormLayout>
        <tr:panelTip>
         <tr:outputText value="#{loomconf['iodselection.searchTip']}"/>
        </tr:panelTip>
       </tr:panelBox>
       <tr:spacer width="10" height="20"/>
       <tr:panelHeader text="#{loomconf['iodselection.tableHeading']}">
        <tr:table value="#{bindings['Iods_View1'].collectionModel}" var="row"
             rows="#{bindings['Iods_View1'].rangeSize}" first="#{bindings['Iods_View1'].rangeStart}"
             emptyText="#{bindings['Iods_View1'].viewable ? 'No rows yet.' : 'Access Denied.'}"
             selectionListener="#{backing_IODSelection.selectionChanged}" id="refresh" width="100%"
             selectedRowKeys="#{bindings['Iods_View1'].collectionModel.selectedRow}"
             partialTriggers=":clear" rowSelection="single" autoSubmit="true">
         <f:facet name="actions">
          <tr:panelGroupLayout layout="horizontal">
           <tr:commandButton text="#{common['common.choose']}"
                    actionListener="#{backing_Selection.backing.save}" accessKey="O">
            <tr:setActionListener from="#{''}" to="#{bindings.No.inputValue}"/>
           </tr:commandButton>
          </tr:panelGroupLayout>
         </f:facet>
         <tr:column headerText="#{bindings['Iods_View1'].labels.No}" sortProperty="No" sortable="false">
          <tr:outputText value="#{row.No}"/>
         </tr:column>
         <tr:column headerText="Issue" sortable="false">
          <tr:selectOneChoice readOnly="#{row.Ino != backing_IODSelection.currentIno}"
                    value="#{backing_IODSelection.selectedIssue[row.Ino]}"
                    valueChangeListener="#{backing_IODSelection.issueChanged}" autoSubmit="true">
           <f:selectItems value="#{backing_IODSelection.issues[row.Ino]}"/>
          </tr:selectOneChoice>
         </tr:column>
         <tr:column headerText="#{bindings['Iods_View1'].labels.Txt}" sortProperty="Txt" sortable="false">
          <tr:outputText value="#{row.Txt}"/>
         </tr:column>
         <tr:column sortable="false" headerText="#{bindings['Iods_View1'].labels.Effectivity}">
          <tr:outputText value="#{row.Effectivity}" truncateAt="75"/>
         </tr:column>
         <tr:column headerText="#{bindings['Iods_View1'].labels.Ec_No}" sortProperty="Ec_No" sortable="false">
          <tr:outputText value="#{row.Ec_No}"/>
         </tr:column>
         <tr:column headerText="Ino}" sortProperty="Ino" sortable="false">
          <tr:outputText value="#{row.Ino}"/>
         </tr:column>
         <tr:column headerText="IodIss_Ino" sortProperty="IodIss_Ino" sortable="false">
          <tr:outputText value="#{row.IodIss_Ino}"/>
         </tr:column>
         <tr:column headerText="IodIss_IodIno}" sortProperty="IodIss_IodIno" sortable="false">
          <tr:outputText value="#{row.IodIss_IodIno}"/>
         </tr:column>
        </tr:table>
       </tr:panelHeader>
      </tr:panelHeader>
      <tr:spacer width="10" height="20"/>
      <tr:panelHorizontalLayout halign="right">
       <tr:commandButton text="#{common['common.cancel']}" actionListener="#{backing_Selection.backing.cancel}"
                accessKey="C">
        <tr:setActionListener from="#{''}" to="#{bindings.No.inputValue}"/>
       </tr:commandButton>
      </tr:panelHorizontalLayout>
     </tr:panelGroupLayout>
    </tr:form>
   </trh:body>
  </trh:html>
 </f:view>
</jsp:root>

..which has the backing bean below. The key method is positionAtRowForIodIssIno() which is supposed to preselect a row in the table if the key field value matches the session bean stored value (currentLinkedIodIssIno). In the method IodsSelectionTable isnt mapped to the table in the dialog screen but I dont know how to do this, maybe there's a better way altogether. But ultimately the idea is that the table row is preselected if key value matches stored value. The corresponding table row on screen could be in any page, each page has 10 items.

Backing bean for the VO:

package wdms.view;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;


import javax.el.ELContext;
import javax.el.MethodExpression;


import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;


import oracle.adf.controller.v2.context.LifecycleContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;


import oracle.binding.OperationBinding;


import oracle.jbo.Row;
import oracle.jbo.RowIterator;
import oracle.jbo.RowSetIterator;
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaRow;
import oracle.jbo.ViewObject;
import oracle.jbo.domain.Number;
import oracle.jbo.uicli.binding.JUCtrlValueBindingRef;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.trinidad.component.core.data.CoreTable;
import org.apache.myfaces.trinidad.component.core.input.CoreSelectOneChoice;
import org.apache.myfaces.trinidad.event.RangeChangeEvent;
import org.apache.myfaces.trinidad.event.SelectionEvent;


import wdms.controller.util.ADFUtils;
import wdms.controller.util.JSFUtils;


import wdms.view.ext.CustomPageController;


public class IODSelection
  extends CustomPageController
{
  private Number currentIno = null;
  private Number currentLinkedIodIssIno = null;
  private HashMap issues = null;
  private HashMap selectedIssue = null;
  private CoreTable IodSelectionTable = null;
  private Log log = null;


  public IODSelection()
  {
    this.IodSelectionTable = new CoreTable();
    this.log = LogFactory.getLog(IODSelection.class.getName());
  }


  public void prepareRender(LifecycleContext context)
  {
    if (!isPostback())
    {
      currentLinkedIodIssIno = (Number) JSFUtils.resolveExpression("#{backing_CreateIOLProcess.iodIssIno}");


      CoreSelectOneChoice retroChoice =
        (CoreSelectOneChoice) JSFUtils.resolveExpression("#{backing_CreateIOLProcess.retroChoice}");
      String retroIndex = (String) retroChoice.getSubmittedValue();
      if ("1".equals(retroIndex)) // No comes 2nd in the dropdown of Yes and No
      {
        JSFUtils.setExpressionValue("#{bindings.InlineRetro.inputValue}", "N");
        JSFUtils.setExpressionValue("#{bindings.RetroRetro.inputValue}", "%");
      }
      else
      {
        JSFUtils.setExpressionValue("#{bindings.InlineRetro.inputValue}", "%");
        JSFUtils.setExpressionValue("#{bindings.RetroRetro.inputValue}", "Y");
      }


      DCBindingContainer bindings = ADFUtils.getDCBindingContainer();
      OperationBinding execute = bindings.getOperationBinding("Execute");
      execute.execute();


      positionAtRowForIodIssIno(); // #29566 set table row to currently linked IOD Index Issue (iodIssIno).
    }


    super.prepareRender(context);
  }


  /**
   * Sets the current displayed row in the list of IOD Indexes to the current selected (linked) IOD Index+Issue
   * if set in a linked previous screen that calls up this IOD Selection dialog.
   * @param nothing
   * @return nothing
   */
  private void positionAtRowForIodIssIno()
  {
    log.info("START positionAtRowForIodIssIno");
    if (this.currentLinkedIodIssIno != null)
    {
      DCIteratorBinding iodSelectionTable =
        ADFUtils.findIterator("Iods_View1Iterator"); // Iterator for the IOD Selection table
      int oldStart = iodSelectionTable.getRangeStart(); // Start of table as displayed
      int range = iodSelectionTable.getRangeSize(); // End of table as displayed
      int newStart; // New start of table - if needed.
      oracle.jbo.Key rowKey = null; // Key for the row matching linked Index


      // Search for the Index+Issue that may have been set in a previous IOD linked screen.
      log.info("Searching for linked IOD (using IodIss_Ino=" + this.currentLinkedIodIssIno + ")");
      RowIterator iterLinkedIodIssIno =
        iodSelectionTable.findRowsByAttributeValue("IodIss_Ino", true, this.currentLinkedIodIssIno);
      if (iterLinkedIodIssIno.first() != null)
      {
        // Found it so position dialog iterator row to the corresponding entry in the list of IODs.
        log.info("Found matching linked item (Ino=" + iterLinkedIodIssIno.getCurrentRow().getAttribute("Ino") + ")");
        rowKey = iterLinkedIodIssIno.getCurrentRow().getKey();
        iodSelectionTable.setCurrentRowWithKey(rowKey.toStringFormat(true));
        log.info("Set current row to: " + iodSelectionTable.getCurrentRow().getAttribute("No"));
      }


      // Calculate new range of Indexes to display on the selection dialog.
      // If a linked Index is used and found in the list then this is catered for via newStart.
      newStart = range * (iodSelectionTable.getCurrentRowIndexInRange() / range);
      iodSelectionTable.getRowSetIterator().setRangeStart(newStart);
      iodSelectionTable.setRangeStart(newStart);

/*-----------------------------------------------------------------
 * 
 * THIS IS THE PROBLEM AREA I THINK
 *
 --------------------------------------------------------------------*/

      // Trigger a refresh/update of the table dialog.
      log.info("Triggering dialog table update...");
      RangeChangeEvent event =
        new RangeChangeEvent(IodSelectionTable, oldStart, oldStart + range, newStart, newStart + range);
      IodSelectionTable.broadcast(event);
      log.info("END positionAtRowForIodIssIno");
      //JSFUtils.storeOnSession(LOOM_PLANNING_REINSTATE_ROW, null);
    }
  }
...
...
}  *