Forum Stats

  • 3,873,344 Users
  • 2,266,537 Discussions
  • 7,911,514 Comments

Discussions

Programmatically setting selected row on a table.

2750374
2750374 Member Posts: 109
edited May 1, 2017 10:13AM in JDeveloper and ADF

Im working with Jdeveloper 12.1.2.

I have a table based off a view iterator. On this table a have a custom Selection Listener. When the user selects a different row from the table it first checks that the required actions have been completed before allowing the user to change rows. This works in that it doesnt actually change the current row in the iterator, but the table will still highlight(select) the new row. Is there a way to set the selected row on a table?

This is what i have for the selection listener.

  1. public void tableSelectionListener(SelectionEvent selectionEvent) { 
  2.     String checkAllow = checkAllowFunc(); 
  3.          
  4.     if(checkAllow.equals("good")){ 
  5.             ADFUtil.invokeEL("#{bindings.testTableVO1.collectionModel.makeCurrent}", new Class[] {SelectionEvent.class},new Object[] { selectionEvent }); 
  6.     } 

Do i need an "else" with some specific code to revert the select? I hope that makes sense.

I would normally do my validations checks in the BC layer(as a business rule) but in this instance thats not an option.

Ashish Awasthi2750374

Best Answer

  • Ashish Awasthi
    Ashish Awasthi Oracle ACE Member Posts: 3,388 Bronze Crown
    edited Apr 28, 2017 2:49AM Answer ✓

    User do like this

    public void selctListener(SelectionEvent selectionEvent) {

       //Getp previous selected row key

      RowKeySet oldKeySet = selectionEvent.getRemovedSet();

      RichTable table = (RichTable) selectionEvent.getSource();

       if (1 == 2) {

      invokeEL("#{bindings.DepartmentsVO1.collectionModel.makeCurrent}", new Class[] { SelectionEvent.class }, new Object[] {

      selectionEvent });

      } else {

      

      table.setSelectedRowKeys(oldKeySet);

      AdfFacesContext adfFacesCtx = AdfFacesContext.getCurrentInstance();

      adfFacesCtx.addPartialTarget(table);

      FacesContext fctx = FacesContext.getCurrentInstance();

      fctx.addMessage("Wrong Move", new FacesMessage("Can not select new row due to validation failure"));

      fctx.renderResponse();

      }

      }

    replace if(1==2) with your condtion if(checkAllow.equals("good")

    Ashish

    2750374

Answers

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 38,904 Red Diamond
    edited Apr 25, 2017 12:04AM

    Try setting the blockRowNavigationOnError to always and throw validation exception from your check method.

    Timo

    Ashish Awasthi
  • Ashish Awasthi
    Ashish Awasthi Oracle ACE Member Posts: 3,388 Bronze Crown
    edited Apr 25, 2017 3:37AM
  • 2750374
    2750374 Member Posts: 109
    edited Apr 25, 2017 9:52AM

    Hmm not sure if im missing something but the table is still allowing me to select a new row when its failing my validation check. Am i missing something with throwing the validation exception?

    I set the block row navigation property to always on my table.

         blockRowNavigationOnError="always"

    and i altered my function like so adding the throw validation exception.

    1. public void tableSelectionListener(SelectionEvent selectionEvent) { 
    2.  
    3.     String checkAllow = checkAllowFunc(); 
    4.  
    5.     if(checkAllow.equals("good")){ 
    6.             ADFUtil.invokeEL("#{bindings.testTableVO1.collectionModel.makeCurrent}", new Class[] {SelectionEvent.class},new Object[] { selectionEvent }); 
    7.     } 
    8.     else{ 
    9.         try{ 
    10.             throw new ValidationException("TEST"); 
    11.         } 
    12.         catch(Exception e){/*IGNORE*/} 
    13.     } 
    14. }
    Ashish Awasthi
  • Ashish Awasthi
    Ashish Awasthi Oracle ACE Member Posts: 3,388 Bronze Crown
    edited Apr 28, 2017 2:49AM Answer ✓

    User do like this

    public void selctListener(SelectionEvent selectionEvent) {

       //Getp previous selected row key

      RowKeySet oldKeySet = selectionEvent.getRemovedSet();

      RichTable table = (RichTable) selectionEvent.getSource();

       if (1 == 2) {

      invokeEL("#{bindings.DepartmentsVO1.collectionModel.makeCurrent}", new Class[] { SelectionEvent.class }, new Object[] {

      selectionEvent });

      } else {

      

      table.setSelectedRowKeys(oldKeySet);

      AdfFacesContext adfFacesCtx = AdfFacesContext.getCurrentInstance();

      adfFacesCtx.addPartialTarget(table);

      FacesContext fctx = FacesContext.getCurrentInstance();

      fctx.addMessage("Wrong Move", new FacesMessage("Can not select new row due to validation failure"));

      fctx.renderResponse();

      }

      }

    replace if(1==2) with your condtion if(checkAllow.equals("good")

    Ashish

    2750374
  • Ashish Awasthi
    Ashish Awasthi Oracle ACE Member Posts: 3,388 Bronze Crown
    edited Apr 29, 2017 6:51AM

    User have you tried it ?

  • 2750374
    2750374 Member Posts: 109
    edited May 1, 2017 10:13AM

    Just got around to trying this. It worked perfectly! Thank you very much Ashish.

    Ashish Awasthi
This discussion has been closed.