Sorting a vector of objects using attribute of object class as comparator

i would like to sort a vector of objects using an attribute of object class as comparator. let me explain, i'm not sure to be clear.
class MyObject{
String name;
int value1;
int value2;
int value3;
i've got a Vector made of MyObject objects, and i would sort it, for instance, into ascending numerical order of the value1 attribute. Could someone help me please?
KINSKI.

Vector does not implement a sorted collection, so you can't use a Comparator. Why don't you use a TreeSet? Then you couldclass MyObject
  String name;
  int value1;
  int value2;
  int value3;
  // Override equals() in this class to match what our comparator does
  boolean equals (Object cand)
    // Verify comparability; this will also allow subclasses.
    if (cand !instanceof MyObject)
      throw new ClassCastException();
    return value1 = cand.value1;
  // Provide the comparator for this class. Make it static; instance not required
  static Comparator getComparator ()
    // Return this class's comparator
    return new MyClassComparator();
  // Define a comparator for this class
  private static class MyClassComparator implements Comparator
    compare (Object cand1, Object cand2)
      // Verify comparability; this will also allow subclasses.
      if ((cand1 !instanceof MyObject) || (cand2 !instanceof MyObject))
        throw new ClassCastException();
      // Compare. Less-than return -1
      if ((MyObject) cand1.value1 < (MyObject) cand2.value1))
        return -1;
      // Greater-than return 1
      else if ((MyObject) cand1.value1 > (MyObject) cand2.value1))
        return 1;
      // Equal-to return 0.
      else
        return 0;
}then just pass MyObject.getComparator() (you don't need to create an instance) when you create the TreeSet.

Similar Messages

  • How to find object use in other object

    Hi All,
    I want to find one object for example procedure which is used in other object like function,procedure or view.
    How can i find it?
    Thanks in advance.

    user647572 wrote:
    Hi All,
    I want to find one object for example procedure which is used in other object like function,procedure or view.
    How can i find it?
    Thanks in advance.Use DBA_DEPEDENCIES view :
    SQL> create table my_tab (id number);
    Table created.
    SQL> create or replace procedure my_proc
      2  as
      3  p_id number;
      4  begin
      5  select id into p_id from my_tab;
      6  end;
      7  /
    Procedure created.
    SQL> select owner, name, referenced_name from dba_dependencies where referenced_name='MY_TAB';
    OWNER      NAME                 REFERENCED_NAME
    SYS        MY_PROC              MY_TAB
    SQL>

  • Align object using a key object

    Hi there,
    has anybody successfully been able to script CS6s align using key object? I've tried this in applescript and I'm farely sure my syntax is ok but I just can't make it work.
    tell application "Adobe InDesign CS6"
      activate
              set mydoc to document 1
              set f to properties of align distribute preferences
              set keyObject to item 1 of (every page item of mydoc whose label is "key_object")
              set theFrame to item 1 of (every page item of mydoc whose label is "myframe")
      select keyObject
      select theFrame existing selection add to
      select keyObject existing selection set key
      --set selection key object to keyObject
              tell align distribute preferences to set align distribute bounds to key object
      align document 1 align distribute items {keyObject, theFrame} align option vertical centers align distribute bounds key object
    end tell
    when I run the above script on a document that consists of 2 frame, one labelled 'key_object' and another labelled 'myframe' the script just returns this error:
    error "Adobe InDesign CS6 got an error: Missing required parameter 'reference' for method 'align'." number 30479
    Any help would be appreciated.
    Thanks,
    Nik

    Hi There,
    It's been a couple of weeks since I originally posted this message but I finally got another chance to look at it.
    Firstly thanks to Marijan for your reply and using JavaScript the command works perfectly, but I'm still unable to get this to work in applescript!!! I stripped it back to basics and just created a document with 2 frames and selected a key object, then I ran the below code:
    tell application "Adobe InDesign CS6"
              set f to selection key object of document 1
      align document 1 align distribute items selection align option horizontal centers align distribute bounds key object
    end tell
    When I run this command I still get this error:
    --> error "Missing required parameter 'reference' for method 'align'." number 30479
    Now I noticed that in JavaScript the align command is passed the parameter of the selection key object but in applescript there's no way to pass this so that the syntax compiles. I would love to know if anybody can get this to work in applescript.
    For the time being I have manged to run the JavaScript from within applescript like this:
    set myJavaScript to "var mD = app.activeDocument;
    var mS = app.selection;
    mD.align ( mS, AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.KEY_OBJECT, mD.selectionKeyObject );"
    tell application "Adobe InDesign CS6"
      do script myJavaScript language javascript
    end tell
    Thanks again,
    Nik

  • Using SQL view object to create ADF table

    Hi,
    I have created a column called "Month" (which extracts month from the date column) and another column to count the no. of requests.
    i want to create an ADF table with 2 columns, a column showing the month and another is showing the no. of requests for that month.
    However, now I only managed to achieve the ADF table to show the overall total requests, which means if i add up all the requests for all the months and i get 500
    My ADF table shows this:
    Jan: 500
    Feb: 500
    Mar: 500
    How should I create the view or what should I do to make it such that the no. of request is based on the month?
    Please advice.
    Thanks (:

    Hi,
    For the given situation you can create a Query Based View Object with the following query
    SELECT
    COUNT(TEMP1.DT) REQUEST,
    TO_CHAR(TEMP1.DT, 'Mon') MONTH
    FROM
    TEMP1
    GROUP BY
    TO_CHAR(TEMP1.DT, 'Mon')
    where DT is the date column and temp1 is the name of the database table.
    Following are the steps that i followed to get this query :
    i have taken the following sample table :
    create table temp1
    (srno number primary key,
    dt date)
    *Note you may use any existing column instead of srno or use dt only (i took an extra column as u know we need a primary key /row id)
    the following is the sample data
    insert into temp1 values (1,sysdate);
    insert into temp1 values (2,sysdate);
    insert into temp1 values (3,add_months(sysdate,1));
    insert into temp1 values (4,add_months(sysdate,1));
    insert into temp1 values (5,add_months(sysdate,3));
    insert into temp1 values (6,add_months(sysdate,5));
    the table appears as follows
    SRNO DT
    1 22-JUN-12
    2 22-JUN-12
    3 22-JUL-12
    4 22-JUL-12
    5 22-SEP-12
    6 22-NOV-12
    To start with ADF View Object Creation (Using Jdeveloper 11.1.2):
    Create the view object using Create View Object wizard
    In Step 1. Name window
    set the value for Name : Viewab (you can use any of ur choice)
    In the data source section : select query
    In Step 2. Query window
    a. Click Query builder (it will pop up sql statment window)
    b. In the SQL Statement window
    in quick-pick objects section -> select temp1 table -> shuttle the columns from available list to selected list
    in select clause section -> select srno column from select list-> choose count() function from function drop down list -> insert function -> set alias to REQUEST-> click validate
    now select dt column from select list -> choose to_char() function -> click insert function -> alter the function to to_Char(temp1.DT,'Mon') -> set alias to Month -> click validate
    in the group by clause section -> Click the green symbol to add -> from the expression palette insert dt column -> insert the to_char function -> alter the function to to_char(temp1.DT,'Mon') -> click validate
    in the Entire SQL Query section -> click test query -> in the test query window -> click query result-> you will see the result -> click close -> click ok
    Click next
    Step 3: Bind Variables
    Click Next
    Step 4: Attribute Mappings
    click Finish
    So the view object is ready :)

  • How to sort a Vector that stores a particular object type, by an attribute?

    Hi guys,
    i need help on this problem that i'm having. i have a vector that stores a particular object type, and i would like to sort the elements in that vector alphabetically, by comparing the attribute contained in that element. here's the code:
    Class that creates the object
    public class Patient {
    private String patientName, nameOfParent, phoneNumber;
    private GregorianCalendar dateOfBirth;
    private char sex;
    private MedicalHistory medHistory;
    public Patient (String patientName, String nameOfParent, String phoneNumber, GregorianCalendar dateOfBirth, char sex) {
    this.patientName = patientName;
    this.nameOfParent = nameOfParent;
    this.phoneNumber = phoneNumber;
    this.dateOfBirth = dateOfBirth;
    this.sex = sex;
    this.medHistory = new MedicalHistory();
    Class that creates the Vector.
    public class PatientDatabase {
    private Vector <Patient> patientDB = new Vector <Patient> ();
    private DateFunction date = new DateFunction();
    public PatientDatabase () throws IOException{
    String textLine;
    BufferedReader console = new BufferedReader(new FileReader("patient.txt"));
    while ((textLine = console.readLine()) != null) {
    StringTokenizer inReader = new StringTokenizer(textLine,"\t");
    if(inReader.countTokens() != 7)
    throw new IOException("Invalid Input Format");
    else {
    String patientName = inReader.nextToken();
    String nameOfParent = inReader.nextToken();
    String phoneNum = inReader.nextToken();
    int birthYear = Integer.parseInt(inReader.nextToken());
    int birthMonth = Integer.parseInt(inReader.nextToken());
    int birthDay = Integer.parseInt(inReader.nextToken());
    char sex = inReader.nextToken().charAt(0);
    GregorianCalendar dateOfBirth = new GregorianCalendar(birthYear, birthMonth, birthDay);
    Patient newPatient = new Patient(patientName, nameOfParent, phoneNum, dateOfBirth, sex);
    patientDB.addElement(newPatient);
    console.close();
    *note that the constructor actually reads a file and tokenizes each element to an attribute, and each attribute is passed through the constructor of the Patient class to instantiate the object.  it then stores the object into the vector as an element.
    based on this, i would like to sort the vector according to the object's patientName attribute, alphabetically. can anyone out there help me on this?
    i have read most of the threads posted on this forum regarding similar issues, but i don't really understand on how the concept works and how would the Comparable be used to compare the patientName attributes.
    Thanks for your help, guys!

    Are you sure that you will always sort for the patient's name throughout the application? If not, you should consider using Comparators rather than implement Comparable. For the latter, one usually should ensure that the compare() method is consistent with equals(). As for health applications it is likely that there are patients having the same name, reducing compare to the patient's name is hazardous.
    Both, Comparator and Comparable are explained in Sun's Tutorial.

  • Sort 2 Vector containg Objects

    I have 2 Vector , both contains objects
    I merge both the vector and make one Vector of Objects.
    Now i want to sort the Vector with the date filed.
    Can anybody write the code sorting the vector of objects on the basis of Date.?

    I have Vector name Employee( this contais object)
    Attribute: Name , Age , Date(on which user make entry:sysdate)
    like :
    Vector Employee= new Vector();
    Collections.sort(list,comparator);
    Plz help me how to use this Collections.sort(list,comparator);?
    What should be the code for comparator.?

  • Sorting a vector of objects?

    I'm having a real hard time sorting my vector, which contains objects that are made up of 4 Strings and 1 integer each.
    This is what I have for the sort routine, but something needs to go in the line that has "if (current.compareTo(smallest) < 0 )" to make it access the name fields of the current and smallest elements.
    Any ideas?
    Thanks,
    Mike
    private void sortname() {
         int nextslot;
         int max = cust_rex.size()-1;
         for (nextslot = 0; nextslot < max; nextslot++) {
              int j = getSmallestName(nextslot);
              swap (nextslot, j);
    private void swap(int a, int b) {
         Object temp = cust_rex.elementAt(a);
         cust_rex.setElementAt(cust_rex.elementAt(b),a);
         cust_rex.setElementAt(temp,b);
    private int getSmallestName (int k) {
         if (cust_rex == null || cust_rex.size() <= k)
              return -1; //error value
         int small = k;
         for (int i = k + 1; i < cust_rex.size(); i++) {
         Customer current = (Customer) cust_rex.elementAt(i);
         Customer smallest = (Customer) cust_rex.elementAt(small);
         if (current.compareTo(smallest) < 0 )
              small = i;
         return small;
         }

    Look at java.util.Comparator and write your own comparator. Then look at java.util.Collections and use the sort method from there instead of writing your own.

  • Sorting a vector using the selection sort method

    I have to write a program that sorts a Vector using the selection sort algorithm. Unfortunately the textbook only has about 2 pages on vectors so needless to say I'm pretty clueless on how to manipulate vectors. However I think I'm on the right path, however I'm stuck on one part as shown in the code below.     
    private static void  selectionSort(Vector parts)
          int index;
            int smallestIndex;
            int minIndex;
            int temp = 0;
            for (index = 0; index < parts.size() - 1; index++)
              smallestIndex = index;
              for (minIndex = index + 1; minIndex < parts.size(); minIndex++)
               if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex))  // this is where I'm having trouble
                  smallestIndex = minIndex;
                parts.setElementAt(temp, smallestIndex);
                parts.setElementAt(smallestIndex, index);
                parts.setElementAt(index, temp); if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex))
    is returning "ProcessParts3.java:51: operator < cannot be applied to java.lang.Object,java.lang.Object"
    Here is the full program:
    import java.util.*;
    import java.io.*;
    public class ProcessParts3
         static Vector parts;
         public static void main(String[] args)
              loadVector();
         private static void loadVector()
         try
              Scanner fileIn = new Scanner(new File("productionParts.txt"));
              parts = new Vector();
              String partIn;
              while (fileIn.hasNext())
                   partIn = fileIn.nextLine();
                        parts.addElement(partIn.trim());
              selectionSort(parts);
                   for (int i = 0; i < parts.size(); i ++)
                   System.out.println(parts.elementAt(i));
         catch(Exception e)
              e.printStackTrace();
         private static void  selectionSort(Vector parts) //from this part down I'm responsible for the coding, everything
                                                               // everything above this was written by the teacher
                 int index;
            int smallestIndex;
            int minIndex;
            int temp = 0;
            for (index = 0; index < parts.size() - 1; index++)
                smallestIndex = index;
                for (minIndex = index + 1; minIndex < parts.size(); minIndex++)
                    if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex))
                        smallestIndex = minIndex;
                parts.setElementAt(temp, smallestIndex);
                parts.setElementAt(smallestIndex, index);
                parts.setElementAt(index, temp);
    }Edited by: SammyP on Nov 27, 2009 11:43 AM

    SammyP wrote:
    I have to write a program that sorts a Vector using the selection sort algorithm...Hmmm.... Your teacher is, in my humble opinion, a bit of a tard.
    1. Vector is basically deprecated in favor of newer implementations of the List interface which where introduced in [the collections framework|http://java.sun.com/docs/books/tutorial/collections/index.html] with Java 1.5 (which became generally available back in May 2004, and went end-of-support Oct 2009). ArrayList is very nearly a "drop in" replacement for Vector, and it is much better designed, and is marginally more efficient, mainly because it is not syncronised, which imposes a small but fundamentally pointless overhead when the collection is not being accessed across multiple threads (as is the case in your program).
    2. Use generics. That "raw" Vector (a list of Objects) should be a genericised List<String> (a list of Strings)... because it's compile-time-type-safe... mind you that definately complicates the definition of your static sort method, but there's an example in the link... Tip: temp should be of type T (not int).
    Note that String implements [Comparable<String>|http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html], so two String's can safely be compared using the compareTo method... In Java the mathematical operators (<, >, &#43;, -, /, &#42;, etc) are only applicable to the primitive types (byte char, int, float, etc)... The Java Gods just chose to muddy the waters (especially for noobs) by "overloading" the &#43; operator for String (and String only) to enable succinct, convenient string-concatenation... which I personally now see as "a little bit of a mistake" on there part.
         private static void  selectionSort(Vector parts)  {
    int index, smallestIndex, minIndex, temp = 0;
    for (index = 0; index < parts.size() - 1; index++) {
    smallestIndex = index;
    for (minIndex = index + 1; minIndex < parts.size(); minIndex++) {
    if (parts.elementAt(minIndex) < parts.elementAt(smallestIndex)) {
    smallestIndex = minIndex;
    parts.setElementAt(temp, smallestIndex);
    parts.setElementAt(smallestIndex, index);
    parts.setElementAt(index, temp);
    }3. ALLWAYS use {curly braces}, even when not strictly necessary for correctness, because (a) they help make your code more readable to humans, and also (b) if you leave them out, you will eventually stuff it up when you insert a line in the expectation that it will be part of the if statement (for example) but you forgot to also add the now mandatory curly-braces... This is far-too-common source of bugs in noob-code. Almost all professionals, nearly allways allways use curly braces, most of the time ;-)
    4. Variable names should be meaningful, except (IMHO) for loop counters... Ergo: I'd rename index plain old i, and minIndex to plain old j
        for ( int i=0; i<list.size()-1; ++i) {
          int wee = i; // wee is the index of the smallest-known-item in list.
          for ( int j=i+1; j<list.size(); ++j ) {Cheers. Keith.
    Edited by: corlettk on 28/11/2009 09:49 ~~ This here fraggin forum markup friggin sucks!

  • Can't warp pasted AI vector Smart Object using Free Transform in PS CS6

    Hi
    I pasted a vector object into PS CS6 (13.0.1 x32) today directly from Illustrator CS6 (16.0.1 x32), and selected "Paste as Smart Object" (Windows XP Pro SP3).
    I then tried to warp the pasted object using the Free Transform tool by dragging one of the corner handles with CTRL held down (Windows).
    This usually warps\distorts the object, but instead, this launched a skew operation.
    If I paste as Shape Layer or as Pixels then apply Free Transform, <Ctrl + corner handle drag> performs a warp\distort operation.
    Also, if I rasterise the pasted AI object, and then convert to a Smart Object I can warp\distort.
    Is it not possible to paste an Illustrator vector in as a Smart Object, and then warp\distort it directly using this technique?
    Thanks for your help.
    Richard

    Your right in that on a pasted vector smart one can't warp, distort or perform perspective transforms.
    One workaround would be to right click on the vector smart object layer in the layers panel and
    choose convert to smart object.
    It depends on what your object is, but you'd probably get better quality from a pasted shape or path, but then you won't be able to open the object
    back in illustrator from photoshop.

  • View Object transient attribute (Calculate sum) using groovy problem

    Hi
    I have a read only view object named "ConnectionVVO". And it has database field name "points"(type is number).
    Now I need to take the sum of points.
    For this I did the following.
    Self view object added to the same view object as a view accessor named "ConnectionVVO1".
    Created a transient attribute named "TotalPoints".
    Added following groovy as the value expression of the above transient attribute.
    adf.object.ConnectionVVO1.getRowSet().sum("points")after that when I run the application module and run the view object it was extremely slow. Actually nothing was appeared. There after I modified the sql statement and added a where clouse to select few rows.
    Then it was appeared without slowness.
    The table has around 11 million records.
    Could you please provide a hint or any alternate way for doing this(getting the sum of points).
    Please help.
    Edited by: deshan on Mar 9, 2011 2:56 PM

    Hi Timo,
    Thank you very much for the explanation and direction. I will do that way. I have found that implementing view object and view row class I could do the similar kind of thing for the transient attribute.
    public Number getTotalPoints() {   
    RowIterator con= getConnectionViewImpl();
       Number sum = new Number(0);
       while (con.hasNext()) {     
          sum = sum.add( (Number)con.next().getAttribute("Points"));
        }    return sum;
      } took form
    http://technology.amis.nl/blog/1295/creating-a-dynamic-ajax-column-footer-summary-in-a-table-component-using-adf-faces
    But it also slow as 1 st method
    I am wonder whether both ways behave as similarly or they are totally different implementation?

  • Java.util.Arrays.sort for Vector

    I used the java.util.Arrays.sort to sort an array based on the method below.
                  java.util.Arrays.sort(array, 0, total, new ComparatorX());
               repaint();
                class ComparatorX implements java.util.Comparator
              public int compare( Object p1, Object p2){
                   int x1=((Point)p1).x;
                   int x2=((Point)p2).x;
                   if(x1>x2)
                                return 1;
                   if(x1>x2)
                                return -1;
                   return 0;
         }I've since changed the array to a vector. Is there anyway I can keep the comparator. Or how can I sort the vector based on the above method.

    BTW: Don't know if it's just a typing mistake, but your code contains an error:
    class ComparatorX implements java.util.Comparator     {
       public int compare( Object p1, Object p2) {
          int x1=((Point)p1).x;
          int x2=((Point)p2).x;
          if (x1>x2) {
             return 1;
          if (x1>x2) {  // Should be: if (x2 > x1) ...
             return -1;
          return 0;

  • Sorting a vector where each element is a vector

    Hi,
    Sorry for the post but I can't seem to get my head around sorting in Java using Comparator.
    I've a vector where each element is a vector containing strings, integers and doubles and the first element of each vector is a double.
    I need to sort the vector based on this first value of each element which is a vector.
    Hope some can help,
    Thanks in advance,
    Lou

    Here is a generic comparator you can use to sort a List. Vector implements the List interface to you can sort the Vector.
    import java.util.Comparator;
    import java.util.List;
    * A comparator to sort Lists of data based on a column within each List
    public class ListComparator implements Comparator
        private int column;
        private boolean ascending;
        ListComparator(int column, boolean ascending)
            this.column = column;
            this.ascending = ascending;
        public int compare(Object a, Object b)
            List v1 = (List)a;
            List v2 = (List)b;
            Object o1 = v1.get(column);
            Object o2 = v2.get(column);
            // Treat empty strings like nulls
            if (o1 instanceof String && ((String)o1).length() == 0)
                o1 = null;
            if (o2 instanceof String && ((String)o2).length() == 0)
                o2 = null;
            // Sort nulls so they appear last, regardless  of sort order
            if (o1 == null && o2 == null) return 0;
            if (o1 == null) return 1;
            if (o2 == null) return -1;
            //  Compare objects
            if (o1 instanceof Comparable)
                if (ascending)
                    return ((Comparable)o1).compareTo(o2);
                else
                    return ((Comparable)o2).compareTo(o1);
            else  // Compare as a String
                if (ascending)
                    return o1.toString().compareTo(o2.toString());
                else
                     return o2.toString().compareTo(o1.toString());
    }You invoke the sort by using:
    Collections.sort(yourVector, new ListComparator(column, ascending));

  • Can't access object using "id" or "name" if created with actionscript

    How can you register an instance of an object with actionscript so that it's id or name value is accessible?
    I included a simple example where a Button is created using mxml and in the same way it is created using actionscript.  The actionscript object is inaccessible using it's "id" and "name" property.
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                   creationComplete="application1_creationCompleteHandler(event)">
        <fx:Script>
            <![CDATA[
                import mx.events.FlexEvent;
                protected function application1_creationCompleteHandler(event:FlexEvent):void
                    import spark.components.Button;
                    var asBtn:Button = new Button();
                    asBtn.label = "actionscript";
                    asBtn.x = 200;
                    asBtn.id = "asButton";
                    asBtn.name = "asButtonName";
                    addElement(asBtn);
                    trace("mxmlButton="+this["mxmlButton"].label); // returns: mxml  label
                    //trace("mxmlButton="+this["asButton"].label); // returns runtime error: ReferenceError: Error #1069: Property asButton not found on TestId and there is no default value.
                    //trace("mxmlButton="+this["asButtonName"].label); // returns runtime error: ReferenceError: Error #1069: Property asButtonName not found on TestId and there is no default value.
            ]]>
        </fx:Script>
        <s:Button
            id="mxmlButton"
            label="mxml label"
            alpha="0.8"/>
    </s:Application>

    Hi Dan,
    It is a very rare occurrence when I miss not being able to access an object (object property, really) using the ["name"] notation for objects created using actionscript.
    In MXML the compiler is conveniently adding an attribute to the class with the same name as the id, so you can conveniently refer to it using the [] notation. While we explicitly specify an application container to use, the MXML compiler creates a custom container which is a derivative of the base container and to that it adds properties for the children declared in MXML. I guess it also effectively calls "addElement" for us when  the container is being constructed.
    Your example assumes that using "addElement" to add the button to the application container is the same as declaring a variable (ie property ). It isn't, so there's no point in looking for an property of the name "as3Button" using the [] notation, because it doesn't exist. The container is managing a collection of children in it's display list and that's not the same as being accessible as properties of the container.
    Generally speaking, accessing properties using the ["name"] syntax isn't necessary.
    Paul
    [edit: you may wonder why "addElement" doesn't conveniently also add the "id" attribute to be an property of the container class. Unfortunately, it can't because the container class would need to be dynamic and it's not. A further complication would be that adding properties at runtime would invite naming clashes at runtime with associated mayhem. MXML can do this because the compiler generates the class and can trap name duplication at compile time.
    Great question, BTW.
    -last edit changed my "attributes" to be "properties" in line with Adobe's terminology]

  • How to Use Transient View Objects to Store Session-level Global Variables

    hi
    Please consider section "40.8.5 How to Use Transient View Objects to Store Session-level Global Variables"
    at http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcstatemgmt.htm#ADFFD19610
    Based on this documentation I created the example application
    at http://www.consideringred.com/files/oracle/2010/ProgrammaticalViewObjectAndRollbackApp-v0.01.zip
    It behaves as show in the screencast at http://screencast.com/t/qDvSQCgpvYdd
    Its Application Module has a Transient View Object instance "MyEmployeesContextVOVI", as master for the child View Object instance "EmpInCtxJobVI".
    On rollback the Transient View Object instance keeps its row and attribute values.
    Also when passivation and activation is forced (using jbo.ampool.doampooling=false ) the Transient View Object instance seems to keep its row and attribute values.
    questions:
    - (q1) Why does the expression #{bindings.MyEmployeesContextVOVIIterator.dataControl.transactionDirty} evaluate as true when a Transient View Object instance attribute value is changed (as shown in screencast at http://screencast.com/t/qDvSQCgpvYdd )?
    - (q2) What would be a robust approach to make a Transient View Object instance more self-contained, and manage itself to have only one single row (per instance) at all times (and as such removing the dependency on the Application Module prepareSession() as documented in "5. Create an empty row in the view object when a new user begins using the application module.")?
    many thanks
    Jan Vervecken

    Thanks for your reply Frank.
    q1) Does sample 90 help ? http://blogs.oracle.com/smuenchadf/examples/
    Yes, the sample from Steve Muench does help, "90. Avoiding Dirtying the ADF Model Transaction When Transient Attributes are Set [10.1.3] "
    at http://blogs.oracle.com/smuenchadf/examples/#90
    It does point out a difference in marking transactions dirty by different layers of the framework, "... When any attribute's value is changed through an ADFM binding, the ADFM-layer transaction is marked as dirty. ...".
    This can be illustrate with a small change in the example application
    at http://www.consideringred.com/files/oracle/2010/ProgrammaticalViewObjectAndRollbackApp-v0.02.zip
    It now shows the result of both these expressions on the page ...
    #{bindings.MyEmployeesContextVOVIIterator.dataControl.transactionDirty}
    #{bindings.MyEmployeesContextVOVIIterator.dataControl.dataProvider.transaction.dirty}... where one can be true and the other false respectively.
    See also the screencast at http://screencast.com/t/k8vgNqdKgD
    Similar to the sample from Steve Muench, another modification to the example application introduces MyCustomADFBCDataControl
    at http://www.consideringred.com/files/oracle/2010/ProgrammaticalViewObjectAndRollbackApp-v0.03.zip
    public class MyCustomADFBCDataControl
      extends JUApplication
      @Override
      public void setTransactionModified()
        ApplicationModule vApplicationModule = (ApplicationModule)getDataProvider();
        Transaction vTransaction = vApplicationModule.getTransaction();
        if (vTransaction.isDirty())
          super.setTransactionModified();
    }Resulting in what seems to be more consistent/expected transaction (dirty) information,
    see also the screencast at http://screencast.com/t/756yCs1L1
    Any feedback on why the ADF Model layer is so eager to mark a transaction dirty is always welcome.
    Currently, question (q2) remains.
    regards
    Jan

  • Using a view-object as a data web bean?

    Hi,
    When writing JSP pages, I'd like to have a web bean that allows basic data manipulation such as:
    - set up a row set - e.g. by specifying a view object and an (optional) where clause;
    - navigate this row set (first, next, etc.);
    - get or set the values of the attributes of the current row;
    - insert, update or delete a row;
    - commit or rollback the modifications;
    - etc.
    This bean should be "silent" - i.e. it would not have to be able to "render" anything - instead, I would use it in <%= bean.method() %> tags, or in <% ...java code... %> sections, in conjunction with other (custom) beans.
    I guess I could use a view object - but:
    1) How would I have to use it in a JSP context?
    2) Or, are there more appropriate objects to do this job?
    3) What methods could I use (i.e. where are they documented)?
    4) What pitfalls should I be aware of (most notably related to housekeeping after bean use)?
    Any information greatly appreciated!
    Thanks in advance,
    Serge

    Hi,
    When writing JSP pages, I'd like to have a web bean that allows basic data manipulation such as:
    - set up a row set - e.g. by specifying a view object and an (optional) where clause;
    - navigate this row set (first, next, etc.);
    - get or set the values of the attributes of the current row;
    - insert, update or delete a row;
    - commit or rollback the modifications;
    - etc.
    This bean should be "silent" - i.e. it would not have to be able to "render" anything - instead, I would use it in <%= bean.method() %> tags, or in <% ...java code... %> sections, in conjunction with other (custom) beans.
    I guess I could use a view object - but:
    1) How would I have to use it in a JSP context?
    2) Or, are there more appropriate objects to do this job?
    3) What methods could I use (i.e. where are they documented)?
    4) What pitfalls should I be aware of (most notably related to housekeeping after bean use)?
    Any information greatly appreciated!
    Thanks in advance,
    Serge

Maybe you are looking for