Swap two objects method

Hi,
I got this code from the forum that can swap two objects. Can anyone explain the code to me? Thanks.
public static Object swap(Object o1,Object o2){
return o1;
o2=swap(o1,o1=o2);
It looks like o2=swap(o1,o1=o2) is passing o1 object and o2 object, the method create new reference for o1 and o2, return the o1 object and assign the reference to o2. Now o2 is o1 but how about o1?

Don't touch that code, it's rubbish. The method claims to "swap" two objects, but it doesn't actually do that unless you call it in precisely that tricky and confusing way.
Anyway, "swap two objects" is not a good way to ask the question because it confuses objects with the variables that refer to them. If you want to change two variables so that they each end up referring to the object originally referred to by the other, just write this:Object temp = o1;
o1=o2;
o2=temp;You can't do it with a method.

Similar Messages

  • Swap two objects

    Can anyone please explain to me why the following code does not swap two objects?
    public void swap(Object a, Object b) {
    Object temp = a;
    a = b;
    b = temp;
    I know when you do a=b, it means assigning the b reference to a. So this piece of code should work. First assign the a reference to temp, then assign b referene to a and assign temp to b. So now a has b's reference and b has a's reference. So why is this wrong? Thanks.

    Simply because all parameters are passed by
    value, not by reference.right, to further clarify, all object parameters are references. So when you pass references by value, you make a copy of it and send it to the method. Therefore, changing what the reference points to has no effect outside of the method.

  • How swap two objects into a UILoader

    Hi.
    I'm taking a snapshot from a webcam and adding a frame around this snapshot.
    I add the snapshot before to load the frame from a file. How can I swap between those objects? because the frame appears at last and the snapshot appears infront. I wanna swap those in the way that the snapshot appears at last and then the frame.

    A UILoader (or any loader) can only hold/load one object, so I don't know how that fits into swapping two things into it.  If the frame is a movieclip, just use addChild(frameName) to have the frame move out front.

  • How to swap the position of two objects?

    I have four self made componensts that I imported them into my main mxml file
    and placed each on four corners.
    What I want to achieve is to drag each component onto others then swap their position.
    For example, comp A is dragged over comp B, when this is detected, swap the position of A and B.
    But at the moment it doesn't seem to work properly. I could not figure out what's wrong with my code. Could any one help me achieve that?
    Many thanks to any who could give me a hand!
    *********This is one of my component***********
    *********All other three components are made the same way, except each source of image file is different******************
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Box xmlns:mx="http://www.adobe.com/2006/mxml" width="42" height="42">
        <mx:Image source="Images/air.png"/>
    </mx:Box>
    *********This is my mxml that calls my components***********
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:comp="Comp.*" creationComplete = "onInit()">
        <mx:Script>
            <![CDATA[
                import mx.containers.Box;
                import Comp.Icon_illustrator;
                import Comp.Icon_air;
                import Comp.Icon_flash;
                import Comp.Icon_flex;
                private var i_1:Icon_air; //1
                private var i_2:Icon_flash; //2
                private var i_3:Icon_flex; //3
                private var i_4:Icon_illustrator; //4
                private var origX:Number;
                private var origY:Number;
                private var startObj:String;
                private var icons:Array;
                private var h_1:Box;
                private var h_2:Box;
                private var h_3:Box;
                private var h_4:Box;
                private function onInit():void{
                    //initialise all icons
                    i_1 = new Icon_air();
                    i_2 = new Icon_flash();
                    i_3 = new Icon_flex();
                    i_4 = new Icon_illustrator();
                    i_1.name = "i_1";
                    i_2.name = "i_2";
                    i_3.name = "i_3";
                    i_4.name = "i_4";
                    //populate icon
                    showArea.addChild(i_1);
                    showArea.addChild(i_2);
                    showArea.addChild(i_3);
                    showArea.addChild(i_4);
                    //set x position
                    i_1.x = 100;
                    i_2.x = 200;
                    i_3.x = 100;
                    i_4.x = 0;
                    //set y position
                    i_1.y = 0;
                    i_2.y = 100;
                    i_3.y = 200;
                    i_4.y = 100;
                    icons = [i_1, i_2, i_3, i_4];
                    //addEventListeners
                    for(var i:int=0; i<icons.length; i++){
                        icons[i].addEventListener(MouseEvent.MOUSE_DOWN, moveMe);
                        icons[i].addEventListener(MouseEvent.MOUSE_UP, stopDragMe);
                }//end of onInit
                private function moveMe(e:MouseEvent):void{
                    e.currentTarget.startDrag();   
                    showArea.setChildIndex(DisplayObject(e.currentTarget), 0);
                    origX = e.currentTarget.x;
                    origY = e.currentTarget.y;
                    startObj = e.currentTarget.name;   
                private function stopDragMe(e:MouseEvent):void{
                    if(this[startObj].hitTestObject(icons[1])){
                        trace("hit 2");
                        this[startObj].x = i_2.x;
                        this[startObj].y = i_2.y;
                        i_2.x = origX;
                        i_2.y = origY;
                    }else if(this[startObj].hitTestObject(icons[0])){
                        trace("hit 1");
                        this[startObj].x = i_1.x;
                        this[startObj].y = i_1.y;
                        i_1.x = origX;
                        i_1.y = origY;
                    }else{
                        trace("hit others");
                        this[startObj].x = origX;
                        this[startObj].y = origY;
                    e.currentTarget.stopDrag();
                }//end of stopDragMe
            ]]>
        </mx:Script>
        <mx:Panel id="showArea" width="400" height="300" layout="absolute" backgroundColor="0x999999"/>
    </mx:WindowedApplication>

    Here is a sample of swaping two objects in Flex (not Air)   I believe it is the same.  Take a look at the way the x and y coords are swapped using the dragInitator and the currentTarget object in the dragDropHandler.
    Hope this helps
    <?xml version="1.0" encoding="utf-8"?><mx:Application  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
     <mx:Script>
    <![CDATA[
     import mx.containers.Box; 
    import mx.core.UIComponent; 
    import mx.managers.DragManager; 
    import mx.core.DragSource; 
    import mx.events.DragEvent; 
    private var dragProxy:Box= new Box(); 
    public function dragDropHandler(e:DragEvent): void { 
    //These variables are the x and y coords of the objects 
    //the e.dragInitator is the object being dragged 
    //the e.currentTarget is the object being dropped on 
    //First save the x and y coords of each of the objects 
    var xdi:int = e.dragInitiator.x; 
    var ydi:int = e.dragInitiator.y; 
    var xct:int = e.currentTarget.x; 
    var yct:int = e.currentTarget.y; 
    //now switch them around.e.dragInitiator.x = xct;
    e.dragInitiator.y = yct;
    e.currentTarget.x = xdi;
    e.currentTarget.y = ydi;
    public function dragEnterHandler(event:DragEvent):void { 
    DragManager.acceptDragDrop(UIComponent(event.target));
    public function mouseMoveHandler(event:MouseEvent):void { 
    if(event.buttonDown == false) return; 
    var dragInitiator:UIComponent = event.target as UIComponent; 
    var dragSource:DragSource = new DragSource(); 
    dragProxy =
    new Box();dragProxy.width = dragInitiator.width;
    dragProxy.height = dragInitiator.height;
    dragProxy.setStyle(
    "borderStyle","solid")dragProxy.setStyle(
    "borderColor","0x000000")dragProxy.setStyle(
    "backgroundColor","0xc6c6c6"); 
    DragManager.doDrag(dragInitiator, dragSource, event, dragProxy,
    event.localX * -1, event.localY * -1, 1.00);
    ]]>
    </mx:Script>
     <mx:Canvas width="84" height="93" x="23" y="14" borderStyle="
    solid" borderColor="
    #030303" backgroundColor="
    #F83C3C"dragEnter="dragEnterHandler(event)"
    dragDrop="dragDropHandler(event)"
    mouseMove="mouseMoveHandler(event)"
    >
     </mx:Canvas>
     <mx:Canvas width="84" height="93" x="223" y="14" borderStyle="
    solid" borderColor="
    #030303" backgroundColor="
    #C5F83C"dragEnter="dragEnterHandler(event)"
    dragDrop="dragDropHandler(event)"
    mouseMove="mouseMoveHandler(event)"
    >
     </mx:Canvas>
     </mx:Application>

  • How to swap two primitive dataelements using swap function??

    How to write a swap function that can swap two integer..??

    Now we are getting somewhere. Next time you post code, use the code tags!! See Formatting Tips or just select the code and click the Code button.
    you cant swap i,j using the above code...You're right. You can't do that.
    so how to do that??The ints must be within some object, like I showed you
    You cannot swap the values of two arguments to a method and expect the caller's variables be swapped because Java passes arguments by value not reference. There is no such thing as a pointer to a variable in Java as there is in C/C++.

  • How to swap two numbers in java

    i have an idea in c but i don't know in java..somenoe like to share their idea i appreciate a lot...
    here is a sample code in c...hope u can help me in java.....thanks a lot ....
    #include<stdio.h>
    void swap(int x, int y)
    int temp;
    temp=x;
    x=y;
    y=temp;
      void main(void)
        int x=10,y=20;
          clrscr();
    printf("Before swap:x=%d,y-%d", x,y);
        swap(x,y);
    printf("\n After swap:x=%d,y=%d",x,y);
       getch();
    #include<stdio.h>
    void swap(int* x, int* y)
    int temp;
    temp=*x;
    *x=*y;
    *y=temp;
    void main(void)
    int x=10,y=20;
    clrscr();
    printf("Before swap:x=%d,y-%d", x,y);
    swap(&x,&y);
    printf("\n After swap:x=%d,y=%d",x,y);
    getch();
    }My aim of this program is to make one java file and 2 class files in java and display the output . The first output would be the number before swapping and the number after swapping.....

    There are several ways to achieve the results. You can use an array or a custom "Swaper" class to swap two values. Here is an example using generics for better code reuse.
    public class Swapper<T> {
       private T first;
       private T second;
       public Swapper(T first, T second) {
          this.first = first;
          this.second = second;
       public void swap() {
          T temp = first;
          first = second;
          second = temp;
       public <T> Swapper<T> swap(T first, T second) {
          return new Swapper<T>(second, first);
       public T getFirst() {return first;}
       public T getSecond() {return second;}
       private static void swap(int[] num) {
          if (num.length != 2) {
             throw new IllegalArgumentException("num array must be of length 2");
          int temp = num[0];
          num[0] = num[1];
          num[1] = temp;
       public static void main(String[] args) {
          // method 1: use array
          int[] num = {1, 2};
          System.out.printf("Before swap:first=%d,second=%d\n", num[0], num[1]);
          Swapper.swap(num);
          System.out.printf("After swap:first=%d,second=%d\n", num[0], num[1]);
          // method 2: use a custom "Swapper" class
          Swapper<Integer> swapper = new Swapper<Integer>(3, 4);
          System.out.printf("Before swap:first=%d,second=%d\n", swapper.getFirst(), swapper.getSecond());
          swapper.swap();
          System.out.printf("After swap:first=%d,second=%d\n", swapper.getFirst(), swapper.getSecond());
          // method 2: using another data type
          Swapper<String> stringSwapper = new Swapper<String>("C#", "Java");
          System.out.printf("Before swap:first=%s,second=%s\n", stringSwapper.getFirst(), stringSwapper.getSecond());
          stringSwapper.swap();
          System.out.printf("After swap:first=%s,second=%s\n", stringSwapper.getFirst(), stringSwapper.getSecond());
          /*    --- OUTPUT ---
           * Before swap:first=1,second=2
           * After swap:first=2,second=1
           * Before swap:first=3,second=4
           * After swap:first=4,second=3
           * Before swap:first=C#,second=Java
           * After swap:first=Java,second=C#
    }

  • Two objects from one table

    My current setup is two tables and two objects with a one to one relationship between them, Object and ObjectMD (metadata).
    Not sure why my predecessors set it up like this but...that's how it is.
    The problem is that my Object table (and thus ObjectMD also) has reached 40 million rows and large joins between Object and ObjectMD are taking forever and are completely unnecessary.
    I want to import the ObjectMD data into the Object table and go forward with a single table. The problem is that the ObjectMD table has it's own java surrounding it and that code is used in way too many places to weed it out. I need to leave the Java object structure in place.
    I think I should be able to create both these objects from a single table, but I can not figure out the descriptor. My set method needs to be getMetaData().setMethod, but of course TL's reflection doesn't like this. I suppose I could create new methods in Object to get/set all these fields and just forward them to the real methods.
    How can I define descriptors to create two objects from a single table?

    What I decided on for my last problem was to use a method to setBar, and inside that method, set the Foo of the Bar.
    Here are my files for future reference:
    --------------------------------------Foo.java-------------------------------------
    public class Foo {
         public int id;
         public String first;
         public Bar bar;
         public void setBar(Bar newBar){
              if(newBar != null){
                   newBar.foo = this;
              this.bar = newBar;
    --------------------------------------Bar.java-------------------------------------
    public class Bar {
         public Foo foo;
         public String second;
    --------------------------------------Descriptors.java-------------------------------------
    public class Descriptors {
         public static void addDescriptors(Project project) {
    project.addDescriptor(Descriptors.buildFooDescriptor());
    project.addDescriptor(Descriptors.buildBarDescriptor());
    private static Descriptor buildFooDescriptor() {
    Descriptor descriptor = new Descriptor();
    //     basic information
    descriptor.setJavaClass(Foo.class);
    descriptor.addTableName("FOO");
    descriptor.setPrimaryKeyFieldName("ID");
    //     mappings
    DirectToFieldMapping directToFieldMapping;
    AggregateObjectMapping aggregateObjectMapping;
    //     id mapping
    directToFieldMapping = new DirectToFieldMapping();
    directToFieldMapping.setAttributeName("id");
    directToFieldMapping.setFieldName("ID");
    descriptor.addMapping(directToFieldMapping);
    //     first mapping
    directToFieldMapping = new DirectToFieldMapping();
    directToFieldMapping.setAttributeName("first");
    directToFieldMapping.setFieldName("FIRST");
    descriptor.addMapping(directToFieldMapping);
    //     bar mapping
    aggregateObjectMapping = new AggregateObjectMapping();
    aggregateObjectMapping.setAttributeName("bar");
    aggregateObjectMapping.setReferenceClass(Bar.class);
    aggregateObjectMapping.setSetMethodName("setBar");
    aggregateObjectMapping.dontAllowNull();
    descriptor.addMapping(aggregateObjectMapping);
    return descriptor;
    private static Descriptor buildBarDescriptor() {
    Descriptor descriptor = new Descriptor();
    // basic information
    descriptor.descriptorIsAggregate();
    descriptor.setJavaClass(Bar.class);
    //     mappings
    DirectToFieldMapping directToFieldMapping;
    //     second mapping
    directToFieldMapping = new DirectToFieldMapping();
    directToFieldMapping.setAttributeName("second");
    directToFieldMapping.setFieldName("SECOND");
    descriptor.addMapping(directToFieldMapping);
    return descriptor;
    ----------------------------------------Go.java------------------------------------
    public class Go {
         public static void main(String[] args) {
              if(args.length != 0){
                   throw new RuntimeException("Arguments are not supported");
              Project project = new Project();
              project.setName("fooBarProject");
              DatabaseLogin login = new DatabaseLogin();
         login.usePlatform(new Oracle9Platform());
         login.setDriverClassName("oracle.jdbc.driver.OracleDriver");
         login.setConnectionString("jdbc:oracle:thin:@nnn.nnn.nnn.nnn:nnnn:SERVICE");
         project.setDatasourceLogin(login);
         Descriptors.addDescriptors(project);
         Server server = project.createServerSession(2, 2);
         server.setLogLevel(oracle.toplink.sessions.SessionLog.FINE);
         server.login("schema", "password");
         Session session = server.acquireClientSession();
         UnitOfWork uow = session.acquireUnitOfWork();
         Foo fooBar = (Foo) uow.newInstance(Foo.class);
         fooBar.id = (int) (Math.random() * 10000);
         fooBar.first = "abcd";
         uow.commit();
         ExpressionBuilder builder = new ExpressionBuilder();
         Foo fooBarLoad = (Foo) session.readObject(Foo.class, builder.get("id").equal(fooBar.id));
         System.out.println("ID:" + fooBarLoad.id + " FIRST:" + fooBarLoad.first + " SECOND:" + fooBarLoad.bar.second );
         session.release();
         server.logout();
    ------------------------------------------------------------------------------------------

  • How to Invoke two java methods parallaly

    Hi,
    I need to invoke two Java methods parallaly ,for example if i am having two methods in a class
    public class Test {
        public Test() {
        public static void main(String[] args)
        Test test = new Test();
        String returnString1 = test.test1();
        String returnString2 = test.test2();
        public String test1(){
        String newString1 = "";
        return newString1;
        public String test2(){
        String newString2 = "";
        return newString2;
    }if i run the above class two methods will be invoked one by one(Sequentially).is there any possibility to invoke these two methods parallaly (ie) both methods need to be invoked at the same time.

    import java.lang.reflect.Method;
    class Paralell implements Runnable{
          private Object srcObject;
          private String methodName;
          private Class parameterTypes[];
          private Object parameterArgs[];
          private Object returnObject;
          public Paralell(Object srcObject, String methodName, Class parameterTypes[], Object parameterArgs[]){
              this.srcObject = srcObject;
              this.methodName = methodName;
              this.parameterTypes = parameterTypes;
              this.parameterArgs = parameterArgs;
          public Object getReturnObject(){
             return this.returnObject;
          public void run(){
               Method method = null;
                try{
                    method =  srcObject.getClass().getDeclaredMethod(this.methodName,this.parameterTypes);
                    this.returnObject =method.invoke(this.srcObject,this.parameterArgs);  
                }catch(Exception exp){
                   exp.printStackTrace();
                }finally{
                    method = null;
    }

  • How do you swap two variables A and B without using a 3rd variable?  No fun

    How do you swap two variables A and B without using a 3rd variable? No function or method allowed.
    For example:
    Given:
    A = 35
    B = 10
    Result
    A = 10
    B = 35

    How do you swap two variables A and B without using a
    3rd variable? No function or method allowed.
    For example:
    Given:
    A = 35
    B = 10
    Result
    A = 10
    B = 35
    A = A + B  (A = 35 + 10 = 45)
    B = A - B (B = 45 - 10 = 35)
    A = A - B (A = 45 - 35 = 10)

  • How do you swap two variables A and B without using a 3rd variable?

    How do you swap two variables A and B without using a 3rd variable? No function or method allowed.
    For example:
    Given:
    A = 35
    B = 10
    Result
    A = 10
    B = 35

    How do you swap two variables A and B without using a
    3rd variable? No function or method allowed.
    For example:
    Given:
    A = 35
    B = 10
    Result
    A = 10
    B = 35
    A = A + B  (A = 10 + 35 = 45)
    B = A - B (B = 45 - 35 = 10)
    A = A - B (A = 45 - 10 = 35)

  • Comparing two Objects

    Hi, I want to compare two objects
    using the formula below
    if((Integer)v.elementAt(i) == new Integer(comp.getCard(j).getValue())){but it doesn't work
    I am trying to compare an element in a vector which was of a type Integer
    key1 = new Integer(dk.getCard(f).getValue());note that key1 is actually a key used for a mapping
    can anyone tell me how I can compare the elements in vector and the other object was an int.

A: Comparing two Objects

Hello zainuluk,
You can not use '==' operator to compare to objects in Java, 'cause it just compare the reference of two oprands. You should use the "equals()" method, just like this:
if(Integer)v.elementAt(i).equals(new Integer(comp.getCard(j).getValue())){...}
Or you can get the int value of element in the vector to compare using '==' operator:
if(Integer)v.elementAt(i).intValue() == comp.getCard(j).getValue()){..}

Hello zainuluk,
You can not use '==' operator to compare to objects in Java, 'cause it just compare the reference of two oprands. You should use the "equals()" method, just like this:
if(Integer)v.elementAt(i).equals(new Integer(comp.getCard(j).getValue())){...}
Or you can get the int value of element in the vector to compare using '==' operator:
if(Integer)v.elementAt(i).intValue() == comp.getCard(j).getValue()){..}

  • If there are two synchronized methods in one class.

    If there are two synchronized methods in one class then what will be the beheviour of the threads accessing the methods.

    Synchronization is on objects, not methods or classes. A thread, entering a synchronized method, synchronizes on the object on which that method is called. Another thread, attempting to synchronize on that object, will be made to wait until the first thread releases it.

  • Connect to COM(OBJECTS/METHODS) FROM ABAP

    Dear all.
    How can I connect to COM objects/methods from abap?
    Could give me link to example.

    Yes this method raises and exception with this message
    Message ID:          FDT_CORE
    Message number:      085
    DO_IM_DATETIME is not in the context
    The method SET_VALUE corresponds to IF_FDT_CONTEXT. This is the method's calls
          lv_name = 'DO_IM_DATETIME'.
          TRY.
              o_context->set_value( iv_name =  lv_name
                                    ia_value = lv_element_tzone ).
            CATCH cx_fdt INTO lx_fdt.
              RAISE incorrect_parameter.
          ENDTRY.
    I reactivate the aplication, the function, the expression and the data objects.
    But the method is still giving this exception.
    I have only this exception when I try to set up this two parameters:
    DO_IM_DATETIM of type Timepoint
    DO_IM_LANGU which is binding to the element type LANGU
    But in my BRFPlus Function Context I do have this two parameters.
    Thanks !

  • Need this explained: Two objects reporting back same values...

    Hello,
    I have a datagrid and a form binded to the selectedItem record of the datagrid.  I need to update the values according to whatever is typed into the form fields.
    I use a CFC to handle the update.  I have a newBean class which holds the new values from the form and also an oldBean object which holds old values to verify I'm updating the correct record.
    In my actionscript I have two objects, newObj and oldObj.  Here is how I set them up in my update function.
    var oldObj:Object = new Object;
    oldObj = dg.selectedItem;
    var newObj:Object = newObject;
    newObj = dg.selectedItem;
    newObj.value1 = field1.text;
    newObj.value2 = field2.text;
    newObj.value3 = field3.text;
    remoteObject.update(oldObj, newObj);
    So, I set the oldObj to the selectedItem and then I set the newObj to that same item, which initially should give them the current values of the selectedItem in the datagrid.  Then I set the values of newObj to match the form fields.  Lastly I have a remoteObject method "update()" send the two objects to the CFC I mentioned above.  When I found out it wasn't updating properly, I set up a cfdump to my email to list the values for both oldObj and newObj.
    Results:
    newObj properly takes all the new values as intended.  oldObj strangely also takes on the new values, yet I never assigned oldObj to accept the new values.  So why is oldObj also accepting the values in the form fields when there's no visible connection between oldObj and any of the fields?

    I don't have an external site I can load this on.  It's a component of an application as well, so I'd have to publish the whole thing.  Instead, I'll just post all relevent code.  Notes: cfc is generated from the ColdFusion wizard.  apptTable is a valueObject that contains the structure of the record data.
    The Remote Object:
        <mx:RemoteObject id="apptRO" endpoint="http://10.118.40.100:85/flex2gateway/"
            destination="ColdFusion" source="cms.cfc.apptTableDAO" showBusyCursor="true" fault="Alert.show(event.fault.faultString, 'Error')">
            <mx:method name="read" result="apptsReceived(event)"/>
            <mx:method name="create" result="apptCreated(event)"/>
            <mx:method name="update" result="apptUpdated(event)"/>
            <mx:method name="deleted" result="apptDeleted(event)"/>
        </mx:RemoteObject>
    The original update function in Flex:
        private var upObj:apptTable;
        private var oldObj:Object;
        private function updateAppt():void{
            oldObj = new Object;
            oldObj = dg.selectedItem;
            upObj = new apptTable;
            upObj = apptTable(dg.selectedItem);
            upObj.clientName = clientNameInput.text;
            upObj.topic = topicInput.text;
            upObj.info = infoInput.text;
            upObj.apptDate = dateInput.text;
            upObj.apptTime = timeInput.text + ' ' + ampmCbx.value.toString();
            apptRO.update(oldObj,upObj);
    The UPDATE function in the CFC:
        <cffunction name="update" output="false" access="public">
            <cfargument name="oldBean" required="true" type="cms.cfc.apptTable">
            <cfargument name="newBean" required="true" type="cms.cfc.apptTable">
            <cfset var qUpdate="">
            <cfquery name="qUpdate" datasource="cmsdb" result="status">
                update dbo.apptTable
                set clientName = <cfqueryparam value="#arguments.newBean.getclientName()#" cfsqltype="CF_SQL_VARCHAR" />,
                    topic = <cfqueryparam value="#arguments.newBean.gettopic()#" cfsqltype="CF_SQL_VARCHAR" />,
                    info = <cfqueryparam value="#arguments.newBean.getinfo()#" cfsqltype="CF_SQL_VARCHAR" />,
                    dateSubmitted = <cfqueryparam value="#arguments.newBean.getdateSubmitted()#" cfsqltype="CF_SQL_VARCHAR" />,
                    apptDate = <cfqueryparam value="#arguments.newBean.getapptDate()#" cfsqltype="CF_SQL_VARCHAR" />,
                    apptTime = <cfqueryparam value="#arguments.newBean.getapptTime()#" cfsqltype="CF_SQL_VARCHAR" />,
                    userID = <cfqueryparam value="#arguments.newBean.getuserID()#" cfsqltype="CF_SQL_BIGINT" null="#iif((arguments.newBean.getuserID() eq ""), de("yes"), de("no"))#" />,
                    userName = <cfqueryparam value="#arguments.newBean.getuserName()#" cfsqltype="CF_SQL_VARCHAR" />
                where apptID = <cfqueryparam value="#arguments.oldBean.getapptID()#" cfsqltype="CF_SQL_BIGINT" />
                  and clientName = <cfqueryparam value="#arguments.oldBean.getclientName()#" cfsqltype="CF_SQL_VARCHAR" />
                  and topic = <cfqueryparam value="#arguments.oldBean.gettopic()#" cfsqltype="CF_SQL_VARCHAR" />
                  and info = <cfqueryparam value="#arguments.oldBean.getinfo()#" cfsqltype="CF_SQL_VARCHAR" />
                  and dateSubmitted = <cfqueryparam value="#arguments.oldBean.getdateSubmitted()#" cfsqltype="CF_SQL_VARCHAR" />
                  and apptDate = <cfqueryparam value="#arguments.oldBean.getapptDate()#" cfsqltype="CF_SQL_VARCHAR" />
                  and apptTime = <cfqueryparam value="#arguments.oldBean.getapptTime()#" cfsqltype="CF_SQL_VARCHAR" />
                  and userID = <cfqueryparam value="#arguments.oldBean.getuserID()#" cfsqltype="CF_SQL_BIGINT" />
                  and userName = <cfqueryparam value="#arguments.oldBean.getuserName()#" cfsqltype="CF_SQL_VARCHAR" />
            </cfquery>
            <!--- if we didn't affect a single record, the update failed --->
            <cfquery name="qUpdateResult" datasource="cmsdb"  result="status">
                select apptID
                from dbo.apptTable
                where apptID = <cfqueryparam value="#arguments.newBean.getapptID()#" cfsqltype="CF_SQL_BIGINT" />
                  and clientName = <cfqueryparam value="#arguments.newBean.getclientName()#" cfsqltype="CF_SQL_VARCHAR" />
                  and topic = <cfqueryparam value="#arguments.newBean.gettopic()#" cfsqltype="CF_SQL_VARCHAR" />
                  and info = <cfqueryparam value="#arguments.newBean.getinfo()#" cfsqltype="CF_SQL_VARCHAR" />
                  and dateSubmitted = <cfqueryparam value="#arguments.newBean.getdateSubmitted()#" cfsqltype="CF_SQL_VARCHAR" />
                  and apptDate = <cfqueryparam value="#arguments.newBean.getapptDate()#" cfsqltype="CF_SQL_VARCHAR" />
                  and apptTime = <cfqueryparam value="#arguments.newBean.getapptTime()#" cfsqltype="CF_SQL_VARCHAR" />
                  and userID = <cfqueryparam value="#arguments.newBean.getuserID()#" cfsqltype="CF_SQL_BIGINT" />
                  and userName = <cfqueryparam value="#arguments.newBean.getuserName()#" cfsqltype="CF_SQL_VARCHAR" />
            </cfquery>
            <cfif status.recordcount EQ 0>
                <cfthrow type="conflict" message="Unable to update record">
            </cfif>
            <cfreturn arguments.newBean />
        </cffunction>
    If you look at the update code from the CFC, you can see all my table columns, some of which are not present in my form fields because they should never change.
    Fields in form: clientNameInput, topicInput, infoInput, dateInput, timeInput, and a combo box for am/pm.
    Columns not in form: apptID, dateSubmitted, userID, userName
    Working code:
    private function updateAppt():void{
            oldObj = new Object;
            oldObj = dg.selectedItem;
            upObj = new apptTable;
            upObj.apptID = dg.selectedItem.apptID;
            upObj.clientName = clientNameInput.text;
            upObj.topic = topicInput.text;
            upObj.info = infoInput.text;
            upObj.dateSubmitted = dg.selectedItem.dateSubmitted;
            upObj.apptDate = dateInput.text;
            upObj.apptTime = timeInput.text + ' ' + ampmCbx.value.toString();
            upObj.userID = dg.selectedItem.userID;
            upObj.userName = dg.selectedItem.userName;
            apptRO.update(oldObj,upObj);
    This code does not set upObj to the selectedItem record of the dg.  Instead it just accepts the values of the form fields and any values in the datagrid that do not change.

  • How to compare two Objects !!!!

    Hi All,
    I know that this question has been asked 100 times till now. But trust me I have checked all of them but couldn`t find answer. Here is my question:
    I have an objecs. In that object I am setting (Id,Name,DOJ). Now I want to check whether the object I am trying to save in database already exists or not. If exists then I need to check whether all the setters are same for the two objects. Now can anyone tell me ,how to compare two objects directly without comparing the setters individually.
    Thanks in advance.

    pavan13 wrote:
    That is pretty good idea. However I have a query. Does that code actually compare all the setters in a two beans. I don`t want to check each setter seperately.Well, it's pretty meaningless to talk about "comparing setters", setters are methods, they don't have values to compare. Because equals is inside the class, you can simply compare the fields that get set by the setters. "Properties" is probably a better name.
    In principal you could write something that tried to find all relevant fields and compare them, using reflection or bean info stuff. The resulting code would be about 50 times longer and take about 50 times longer to run. It's hardly asking a lot to put three comparisons between && operators.
    Remember, though, not to compare string fields with ==, you should call .equals on the string fields.
    p.s. don't let the bean terminology confuse you. Beans are just ordinary objects which follow a few rules. Personally I wish the term had never been coined.
    Edited by: malcolmmc on Dec 6, 2007 4:15 PM

  • Maybe you are looking for

    • BAPI to unaccept service entry sheet

      Hello, I have created and accepted service entry sheet using BAPI "BAPI_ENTRYSHEET_CREATE". Now i have requirement where I need to unaccept already accepted service entry sheet. Can any one provide me the BAPI which will help me in resolving this iss

    • Strange Broken Link

      I have an SQL Report with a link to a detail page. The link works for 9 out of the 10 rows, but on the 10th row, I'm getting a http 404, broken link error. The link is the same, session is the same, and the only difference is value of the key being p

    • When Premiere Elements 9

      Does anyone knows when the next version of Premiere Elements is to be released and what are the expected changes compare with Premiere Elements 8? Andrew

    • PDF Security for passowrd protection of HP Printer stored document

      I am trying to use the XML RTF template PDF Security feature to password protect printed checks so they are stored on the HP printer until the password is entered on the printer. We are sending the PDF directly to the printer (HPLJ3000) where it is b

    • Regarding javax.crypto package?

      Hey,do we get this package as default one. Or do we have to get it separately? if we have to get it separately ..pls tell me where can we get it? thanks a lot hari