Skip navigation.

JOracle

Oracle's Java technologies: JDeveloper, OC4J, ADF

Oracle ADF: Adding/deleting entries in a many-to-many relationship

I am using JDeveloper 10.1.3 and the ADF BC / ADF Model / ADF Faces / JSF technology stack.

For this question, I am using the SRDemo application as an example, specifically the many-to-many relationship between USERS and PRODUCTS (the Staff Expertise relationship), outlined in red in this schema diagram:

Users may have any number of product expertise areas and many users may have the same product expertise area. For the purposes of this example I have added two reference fields from the PRODUCT table into the ExpertiseAreas VO (Name and Description), outlined in red in this data control palette section:

I have created a page which shows the details of a user (1), along with a table showing the expertise areas the user has (3), and a table of all the products available (2), numbered on this design page: and corresponding to the numbered data controls on this data control palette section: , where 1 is rendered as an ADF Read-only Form, 2 is an ADF Read-only Table with a tableSelectMany element in the selection facet, and 3 is also an ADF Read-only Table.

What I am trying to do is have the tableSelectMany element reflect which of the products are linked to the current user in the expertise areas relationship (by having the checkbox for currently linked products checked), and when you check or uncheck a product's checkbox, it should add or remove the row in the EXPERTISE_AREAS intersection table, respectively (asume for this example that there are default values for Expertise Level and Notes).

So far I have been following the process used in section 19.8 of the ADF Developer's Guide for Forms/4GL Developers, which describes how to set up a selectManyShuttle which implements the adding and deleting functionality. So I have a Client Interface method in the Application Module, updateSkillsForCurrentStaff (described in section 10.6.7.2), and I have a selection listener for the assignment table in the backing bean for the page, which calls the updateSkillsForCurrentStaff method:

public void selectionChanged(SelectionEvent event)
{
  BindingContainer bc = getBindings();
  DCIteratorBinding productsIB = (DCIteratorBinding)bc.get("ProductListIterator");
  
  Set keys = getTable1().getSelectionState().getKeySet();
  Iterator iter = keys.iterator();
  List productIds = new Vector();
  
  while (iter.hasNext())
  {
    String product = ((Key)iter.next()).toStringFormat(true);
    productsIB.setCurrentRowWithKey(product);
    ViewRowImpl productRow = (ViewRowImpl)productsIB.getCurrentRow();
    Number productId = (Number)productRow.getAttribute("Id");
    productIds.add(productId);
  }
  
  OperationBinding ob = bc.getOperationBinding("updateSkillsForCurrentStaff");
  Map pm = ob.getParamsMap();
  pm.put("productIds", productIds);
  ob.execute();
}


All of this works, but I can't work out how to link the selection state of the assignment table to the expertise areas that are linked to the user. Also I think the method listing above must be a bit of a hack, but I don't know enough about this to know if there's an easier way of doing it.

Any help is appreciated.

My first blog and competition entryProgrammatic Authentication for Oracle ADF Business Components

Comments

Matthew Wilson 3. October 2006, 15:27

I posted this on the Oracle forums here: Link, and Steve Muench replied with this message:

Have a look at this example I cooked up for you.

http://radio.weblogs.com/0118231/2006/10/03.html#a739

It might not be the first way one thinks to implement something, but it illustrates a very interesting, model-centric approach to the problem you propose.

My feelings won't be hurt if you prefer a more view-centric approach, but I wanted to illustrate what was a maximally-model-centric solution (in fact, which doesn't even require a backing bean!) If you like a more view-centric approach, I can help you figure out what's wrong with your key-handling above. For one, I would probably start by passing the Set of Key's directly to the middle tier application module method to eliminate client-side code.

Check it out and let me know what you think. Try it directly in the Business Components Tester to appreciate one of the benefits a model-centric solution can bring.



This is an interesting solution to my problem. I am going to try for a more view-centric approach based on this and I'll put up another comment if I am successful.

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31