Urgent query about copying array of objects to html item

I have an urgent query about how I can display an array of objects on a html form. The only suitable html item I can see for this is a drop down box. Ideally a combo box would be preferable but I cant find anything like this. Basically the display item needs to contain 3 columns of data and has to display a number of rows. Can anyone tell me how to copy the array of values into a drop down box?

Here is all the code from my jsp. It keeps returning null:
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page import="java.util.*, java.lang.*" %>
<html:html locale="true">
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"/>
<link rel="stylesheet" type="text/css" name="timesheet" href="stylesheets/timesheet.css"></link>
<script type="text/javascript" language="javascript" src="javascript/sum.js"></script>
<title><bean:message key="eng.title"/></title>
<html:base/>
</head>
<body bgcolor="white">
<table border="0" width="100%">
<tr>
<td width="30%"><html:img page="/images/PwC_logo.gif"/></td>
<td width="40%" class="applicationTitleCell">
<div align="center">
<bean:message key="application.title"/>
</div>
</td>
<td width="30%"> </td>
</tr>
</table>
<center>
<html:form action="/selectEng" focus="engSearchNumber">
<table border="0" width="100%">
<tr>
<td width="30%"></td>
<td width="20%" align="center"> <b> <bean:message key="eng.prompt.engSearchNumber"/> </b> </td>
<td width="20%" align="center"> <b> <bean:message key="eng.prompt.clientSearchName"/> </b> </td>
<td width="40%">   </td>
</tr>
<tr>
<td width="30%"></td>
<td width="20%" align="center"> <html:text property="engSearchNumber" size="20" maxlength="9" onchange='<%= "SearchLength(this)" %>' onkeypress="return NumberOnly()" /> </td>
<td width="20%" align="center"> <html:text property="clientSearchName" size="20" maxlength="20" onchange='<%= "SearchLength(this)" %>'/> </td>
<td width="30%">   </td>
</tr>
</table>
<table border="0" width="100%">
<tr>
<td width="30%"></td>
<td width="40%" align="center"><html:image property="findButton" src="images/Find.gif" alt="Find"/></td>
<td width="30%">   </td>
</tr>
<jsp:useBean id="selectEngForm" scope="session" class="Time.SelectEngForm" />
<% if (selectEngForm.getEngSearchNumber() != null) { %>
<tr>
<td width="30%"></td>
<td width="40%" align="center"><select name="engListing" size="5">
<%= selectEngForm.getEngListing() %>
</select></td>
<td width="30%">   </td>
</tr>
<% } else if (selectEngForm.getClientSearchName()!=null){ %>
<tr>
<td width="30%"></td>
<td width="40%" align="center"><select name="engListing" size="5">
<%= selectEngForm.getEngListing()%>
</select></td>
<td width="30%">   </td>
</tr>
<% } %>
<%=request.getParameter("engListing")%>
</table>
<br><br>
<table border="0" width="100%">
<tr>
<td width="30%"></td>
<td width="11%" align="center"> <html:image property="addButton" src="images/Add.gif" alt="Add the selected engagement to the timesheet"/> </td>
<td width="11%" align="center"> <html:image property="cancelButton" src="images/Cancel.gif" alt="Cancel"/> </td>
<td width="30%">   </td>
</tr>
</table>
</html:form>
</center>
<br>
<center><html:link forward="timesheet"> <html:img src="images/Back.gif" border="0"/> </html:link></center>
</body>
</html:html>

Similar Messages

  • Question about an Array of objects

    I'm writing a program that is supposed to store a String and a double in an array of CustomerBill objects. I just want to know if I am doing it correctly. Heres my code:
    public static CustomerBill[] getCustomerData()
             //Local variables
             int numCust;     //The number of customers being processed
             double amt;
             String customer;        
          //Ask for the number of customers to be processed.
             System.out.print("How many customers are to be processed? ");
             numCust = Integer.parseInt(keyboard.nextLine());
             CustomerBill[] array = new CustomerBill[numCust];
             //Ask user to enter the data.
             System.out.println("\nPlease enter customer data when prompted.");
             System.out.println("Enter customer's last name, then first name.");
          //Get the customer data from user.
             for (int i = 0; i < array.length; i++)
               array[i] = new CustomerBill();
               System.out.print("\nCustomer name:  ");
               customer = keyboard.nextLine();       
               array.setName(customer);
    System.out.print("Total bill amount: ");
    amt = Double.parseDouble(keyboard.nextLine());
    array[i].setAmount(amt);
    System.out.println();
    return array;

    Write a test() method that:
    (1) Gets an array of CustomerBills using getCustomerData()
    (2) In a for-loop print out each of the CustomerBills. It will help if
    CustomerBill has a toString() method but, in any case you should be
    able to see that the aray contains the right number of nonnull elements.
    Then write a main() method that calls the test() method.
    [Edit] And then run it! You may need to do this a few times and check
    what happens with "crazy" data.

  • An Urgent Query about ODI

    Hi,
    I have done a scenario which executes sum.sh file.This scenario is successfully executed by OraclediAgent. Now a web service(Let from bpel/soap ui) invokes this agent using agent's wsdl url (like this:-
    http://localhost:8886/oraclediagent/OdiInvoke?wsdl) and then the OraclediAgent execute the scenario. I am successful for this case too.Now my questions are:-
    *1)Is it possible to return the summation result to the invoker web service(bpel/soap ui) through odi.*
    *2)Is it possible to show the o/p(result of the summation) in odi console.*
    and my last question is:
    *3)Every time when the bpel/soap ui invokes OraclediAgent it gets session id as a return.How do I know the execution of the sum.sh file is successfully done or not wrt to invoker.(or more clear to say in weblogic console?)*
    Please ans.It's urgent
    Thanks
    Papai

    hi,
    any update??At least please tell me the reverse procedure i.e i also want to send two number from webservice to the odiOScommand so that the the sum.sh will run successfully where the odiOscommand parameter are variables not a static value.How'ii I do it?
    Please Ans.
    Thanks
    Papai

  • Query about Function based geometry object problem

    Hi, I got stuck with a query like this:
    SELECT count(*)
    FROM property_point WHERE
    get_geom(v_start,v_end,t_start,t_end).get_gtype() = 1 --point
    AND --get all the points within the rectangle (min,min,  now,now)
    SDO_RELATE(get_geom(v_start,v_end,t_start,t_end),
    mdsys.sdo_geometry(2003,NULL,NULL,
    mdsys.sdo_elem_info_array(1,1003,3),
    mdsys.sdo_ordinate_array(
    to_number(to_char(to_date('01-JAN-1992','DD-MON-YYYY'),'J')),
    to_number(to_char(to_date('01-JAN-1992','DD-MON-YYYY'),'J')),
    to_number(to_char(sysdate,'J')),
    to_number(to_char(sysdate,'J')))),
    'mask=INSIDE querytype=WINDOW') = 'TRUE'
    OR
    get_geom(v_start,v_end,t_start,t_end).get_gtype() = 2 --line
    AND --get all the lines interact with transaction now
    SDO_RELATE(get_geom(v_start,v_end,t_start,t_end),
    mdsys.sdo_geometry(2002,NULL,NULL,
    mdsys.sdo_elem_info_array(1,2,1),
    mdsys.sdo_ordinate_array(
    to_number(to_char(sysdate,'J')),
    to_number(to_char(to_date('01-JAN-1992','DD-MON-YYYY'),'J')),
    to_number(to_char(sysdate,'J')),
    to_number(to_char(to_date('31-DEC-2008','DD-MON-YYYY'),'J')))),
    'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'
    AND --get all the lines interact with valid now
    SDO_RELATE(get_geom(v_start,v_end,t_start,t_end),
    mdsys.sdo_geometry(2002,NULL,NULL,
    mdsys.sdo_elem_info_array(1,2,1),
    mdsys.sdo_ordinate_array(
    to_number(to_char(to_date('01-JAN-1992','DD-MON-YYYY'),'J')),
    to_number(to_char(sysdate,'J')),
    to_number(to_char(to_date('31-DEC-2008','DD-MON-YYYY'),'J')),
    to_number(to_char(sysdate,'J')))),
    'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'
    OR
    get_geom(v_start,v_end,t_start,t_end).get_gtype() = 3 --rectangle
    AND --interact with transaction now
    SDO_RELATE(get_geom(v_start,v_end,t_start,t_end),
    mdsys.sdo_geometry(2002,NULL,NULL,
    mdsys.sdo_elem_info_array(1,2,1),
    mdsys.sdo_ordinate_array(
    to_number(to_char(sysdate,'J')),
    to_number(to_char(to_date('01-JAN-1992','DD-MON-YYYY'),'J')),
    to_number(to_char(sysdate,'J')),
    to_number(to_char(to_date('31-DEC-2008','DD-MON-YYYY'),'J')))),
    'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'
    AND --interact with valid now
    SDO_RELATE(get_geom(v_start,v_end,t_start,t_end),
    mdsys.sdo_geometry(2002,NULL,NULL,
    mdsys.sdo_elem_info_array(1,2,1),
    mdsys.sdo_ordinate_array(
    to_number(to_char(to_date('01-JAN-1992','DD-MON-YYYY'),'J')),
    to_number(to_char(sysdate,'J')),
    to_number(to_char(to_date('31-DEC-2008','DD-MON-YYYY'),'J')),
    to_number(to_char(sysdate,'J')))),
    'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'
    which returns 0 rows.
    But if only use the first condition, say
    SELECT count(*)
    FROM property_point WHERE
    get_geom(v_start,v_end,t_start,t_end).get_gtype() = 1 --point
    AND --get all the points within the rectangle (min,min,  now,now)
    SDO_RELATE(get_geom(v_start,v_end,t_start,t_end),
    mdsys.sdo_geometry(2003,NULL,NULL,
    mdsys.sdo_elem_info_array(1,1003,3),
    mdsys.sdo_ordinate_array(
    to_number(to_char(to_date('01-JAN-1992','DD-MON-YYYY'),'J')),
    to_number(to_char(to_date('01-JAN-1992','DD-MON-YYYY'),'J')),
    to_number(to_char(sysdate,'J')),
    to_number(to_char(sysdate,'J')))),
    'mask=INSIDE querytype=WINDOW') = 'TRUE'
    will return 688 rows.
    besides, 2nd and 3rd condition will return 0 and 5 rows.
    Why it became 0 when putting them together?
    This is the structure of table property_point and function get_geom
    and I am using 10.1.0.3 version
    CREATE TABLE property_point (
              SALES_ID number,
              AGENT_ID number,
              SALES_PRICE number,
              LOCATION MDSYS.SDO_GEOMETRY,
              V_START date,
              V_END     date,
              T_START date,
              T_END     date);
    CREATE OR REPLACE FUNCTION get_geom(v_start in date, v_end in date, t_start in date, t_end in date)
    return MDSYS.SDO_GEOMETRY deterministic is
    I wonder if I missed anything here?

    I have not used this myself, but check if this works for you.
    RSPO_DOWNLOAD_SPOOLJOB
    Regards,
    Ravi
    Note : Please mark the helpful answers

  • Query about SAP locks /enqueue objects

    I have created an lock object for a bespoke table which has 5 key fields.  For arguments sake let's call them
    WERKS QMGRP QMCOD OTGRP OTEIL.
    The problem I have is the following:
    User 1 has a house profile that can access the following data:
    WERKS QMGRP QMCOD OTGRP OTEIL
    9026  HOUSE CUST
    User 2  has a functional profile which gives them access to the following:
    WERKS QMGRP QMCOD OTGRP OTEIL
    9026  HOUSE CUST 
    9026  HOUSE CUST   CS    C001
    9026  HOUSE CUST   CS    C002
    I am building a front-end to the table to enable the users to change data associated with these keys.  My problem is the following.  If User 2 locks the entries,(s)he has access to first, the user 1 entry will be locked to changes,  which is correct.  If, however, user 1 locks its entry first, <b>all</b> of user 2's entries are locked even though only the first entry is allowed to be accessed by both.  I think this is happening because the SAP lock object does not recognise '   ' '    ' as a separate value to 'CS' 'C001'.  It thinks because 9026 HOUSE CUST '   ' '    ' is locked, then the other entries should be locked because they share 9026 HOUSE CUST from the key, even though there are other values in the key following 9026 HOUSE CUST.
    What I want is if user 1 locks its entry first, then only the entry that matches the key  totally for user 2 is locked, leaving the other 2 entries to which user 2 has access free to be edited.
    Is there a way I can get the SAP lock object to recognise this eitehr by changing the enqueue function module or by the way I cal the enqueue object or not?
    Any help would be appreciated.
    Hope this makes sense
    Larissa

    Hi Larissa,
    As far as I know, You cannot change generated enqueue function module. The other way as i think might work would be to create a new FM and do manipulation (for space to be changed as some other value) before calling this generated Enqueue FM.
    Hope this helps.
    Regards,
    Vicky
    PS: Award points if helpful

  • Urgent query about submitting jsp

    I have a hidden field on a jsp that I want to submit when a particular button is clicked. I dont want the rest of the form to submit. Is it possible to do this?

    You can put the hidden field in it's own seperate HTML form and then have the button submit this form.
    <form name=hiddenForm action=>
    <input type=hidden name=hiddenField value=>
    </form>
    <button type=button onClick='doSubmitHiddenForm();' >
    <Script>
    function doSubmitHiddenForm() { document.hiddenForm.submit(); }
    </script>

  • View query to results array

    previus information... jdeveloper 10.1.3.0.4, the application is java swing adf bc .
    hi, i have a bc view (sql only) inside an application module, how could i assign the results of view's query with an array of objects.

    Not sure if this is on target, but if you are using ADF BC the view object's query results are already in an array of objects. Reference the following document to view how the results are structured. You can programmatically then work with the results set using the ViewObject, RowSet, and RowSetIterator Interfaces. See the SRDemo Application Module services for some examples of this in action (demo is in JSF though, not Swing.)
    http://www.oracle.com/technology/products/jdev/tips/muench/mostcommon/index.html
    thanks

  • Check this out: making a copy of an array of objects

    I have an array of objects called Figs of type Figure and I am making a copy of this array called OriginalFigs so later when Figs change, I can use the original values stored in OriginalFigs.
    But I found out that when values in Figs change, values in OriginalFigs also change.
    I tried to store values in Vector too but even in Vector values are changing.
    seems like they both are storing reference to Figs and when Figs change , they(Vector and OriginalFigs) chnage too.
    Is there any way to come around this problem?
    if u know then plz share with me..........

    Hi,
    how do you copy them - if you use the method from Object(? was it there, never use this), you will get a shallow copy - that is a new object with the same references in it - not a new object with new objects of the figures in it.
    How about providing a methode in your figure-objects which can do a total copy? - This must be easy as so you know how to construct such an object efficiently.
    Another way to hold a copy is to write the figures out to a stream temporarily - all objects are serializable and so they can be stored to a stream - but your figures should not have references to other parts of the program in it, because the serialisation-process tries to serialize all references the object has, that is to be serialized. If there is for exampe a link to the main JFrame in it, the serialisation process tries to store your hole program to the stream and this may be impossible - I hat this with parts of a JTree that refuse to be stored to a stream.
    Hope, this will help
    greetings Marsian

  • Passing an array of objects to a named query

    I'm trying to use a named query that will have a
    in() expression operator (clause) to retrieve a set of objects.
    The in() operator requires an array of objects to pass in.
    Specifically I want to pass an array of BigDecimal of unknown size.
    The query looks like that:
    ExpressionBuilder seq = new ExpressionBuilder();
    Expression exp = seq.get("id").in(keys);
    ReadAllQuery query = new ReadAllQuery();
    query.setReferenceClass(RegistrationNumberSequencer.class);
    query.addArgument("keys");
    query.setSelectionCriteria(exp);
    And the "keys" would be:
    Object[] keys = new Object[2];
    keys[0]= new BigDecimal(1);
    keys[1]= new BigDecimal(2);
    I have got a conversion exception(Could not convert to BigDecimal class) when executing the query.
    Can I pass this array as a parameter somehow ?
    Thanks a lot
    Ovidiu

    Hi Ovidiu,
    My apologies for the missed code. You need to pass the vector of elements into another vector, so TopLink will interpret the single element of the second vector as the correct query argument, and expend the elements in the first vector into the IN clause.
    The named query defined I sent in previous mail is still correct, but you need to pass in the argument like:
    Vector keys = new Vector();
    keys.addElement(new BigDecimal(1));
    keys.addElement(new BigDecimal(2));
    Vector arg = new Vector(1);
    arg.addElement(keys);
    Now you can pass the arg in when executing the query, and should get the correct result.
    To stand my claim, I did a mini test using our TopLink Employee demo and here is the generated SQL:
    Call:SELECT t0.VERSION, t1.EMP_ID, t0.L_NAME, t0.F_NAME, t1.SALARY, t0.EMP_ID, t0.GENDER, t0.END_DATE, t0.START_DATE, t0.MANAGER_ID, t0.START_TIME, t0.END_TIME, t0.ADDR_ID FROM EMPLOYEE t0, SALARY t1 WHERE ((t0.EMP_ID IN (1, 2)) AND (t1.EMP_ID = t0.EMP_ID))
    You can see the IN clause in generated as expected!
    As Doug said, we do not officially support array as query argument yet. I would use the proper way to build the query.
    King

  • Retrieving array of objects using Named Query

    Can i retrieve an array of objects using a Named Query? The execute query method of Session returns only an Object but not an array. Please let me know if there is any possibility.
    Thanks in advance,

    Hi,
    You define a named ReadAllQuery query object, and after query execution, you can cast the returned Object as Vector, and further convert it to an array.
    King

  • Turning a resultset into an array of objects.

    First I will give some background on the situation...
    I have a table in which has many lines of data. Each line of data has a boolean (for a jcheckbox) we will call that "A" and then a bunch of other attributes that are related...we will call those B, C, and D. On a later screen there will be a reduced table in which has only the lines from the original table that were selected. This is why the whole row in the table has to be an object.
    So I have a query like this:
    ResultSet rs = stmt.executeQuery("SELECT A, B, C, D FROM tableName WHERE A= '1'");and then I would like to use:
    String ObjectRef;
                Boolean A;
                String B;
                String C;
                String D;
                while (rs.next()) {
                     A = rs.getString("A");
                     B = rs.getString("B");
                     C = rs.getString("C");
                    D = rs.getString("D");At this point I need to create an ArrayList or an Array of objects....each object having A, B, C, and D. how do I do that in this while condition?
    Or if someone knows a better way of goign about this please let me know. The main objective is to populate this table with objects containing each of of the above attributes. I tried to keep the scenario as simple as possible, so if it was confusing or I need to explain more, just ask.
    Thanks in advance.

    Atreides wrote:
    At this point I need to create an ArrayList or an Array of objects....each object having A, B, C, and D. how do I do that in this while condition?Create the list before you start the while loop. Then, inside the while loop, after extracting A..D, do something like this:
    MyClass mine = new MyClass(A, B, C, D); // or a no-arg c'tor and then a bunch of setters.
    list.add(mine);

  • Copying arrays, performance questions

    Hello there
    The JDK offers several ways to copy arrays so I ran some experiments to try and find out which would be the fastest.
    I was measuring the time it takes to copy large arrays of integers. I wrote a program that allocates arrays of various sizes, and copy them several times using different methods. Then I measured the time each method took using the NetBeans profiler and calculated the frequencies.
    Here are the results I obtained (click for full size):  http://i.share.pho.to/dc40172a_l.png
    (what I call in-place copy is just iterating through the array with a for loop and copying the values one by one)
    I generated a graph from those values:  http://i.share.pho.to/049e0f73_l.png
    A zoom on the interesting part: http://i.share.pho.to/a9e9a6a4_l.png
    According to these results, clone() becomes faster at some point (not sure why). I've re-ran these experiments a few times and it seems to always happen somewhere between 725 and 750.
    Now here are my questions:
    - Is what I did a valid and reliable way to test performances, or are my results completely irrelevant? And if it's not, what would be a smarter way to do this?
    - Will clone be faster than arraycopy past 750 items on any PC or will these results be influences by other factors?
    - Is there a way to write a method that would copy the array with optimal performances using clone and arraycopy, such that the cost of using it would be insignificant compared to systematically using one method over the other?
    - Any idea why clone() can become faster for bigger arrays? I know arraycopy is a native method, I didn't try to look into what it does exactly but I can't imagine it's doing anything more complicating than copying elements from one location in the memory to another... How can another method be faster than that?
    (just reminding I'm copying primitives, not objects)
    Thanks!
    Message was edited by: xStardust! Added links, mr forum decided to take away my images

    yeh, everyone thinks that at some point. it relies,
    however, on you being perfect and knowing everything
    in advance, which you aren't, and don't (no offence,
    the same applies to all of us!). time and time again,
    people do this up-front and discover that what they
    thought would be a bottleneck, isn't. plus,
    the JVM is much smarter at optimizing code than you
    think: trust it. the best way to get good performance
    out of your code is to write simple, straightforward
    good OO code. JVMs are at a point now where they can
    optimize java to outperform equivalent C/C++ code
    (no, really) but since they're written by human
    beings, who have real deadlines and targets, the
    optimizations that make it into a release are the
    most common ones. just write your application, and
    then see how it performs. trust me on this
    have a read of
    [url=http://java.sun.com/developer/technicalArticles/I
    nterviews/goetz_qa.html]this for more info anda chance to see where I plagiarized that post from :-)
    Thanks for that link you gave me :)
    Was usefull to read.
    About time and money of programming, that is not really an issue for me atm since i'm doing this project for a company, but through school (it's like working but not for money).
    Of course it should not last entirely long but I got time to figure out alot of things.
    For my next project I will try to focus some more on building first, optimizing performance later (if it can be done with a good margin, since it seems the biggest bottlenecks are not the code but things outside the code).
    @promethuuzz
    The idea was to put collection objects (an object that handles the orm objects initialized) in the request and pass them along to the jsp (this is all done through a customized mvc model).
    So I wanted to see if this method was performance heavy so I won't end up writing the entire app and finding out halve of it is very performance heavy :)

  • Copy & paste embeded object to file system

    Cross-post at:
    http://stackoverflow.com/questions/27685791/copy-paste-embeded-object-to-file-system
    Background:
    I wrote a large piece of VBA code in an Excel workbook to help handle a lot of repeating jobs. I found it is painful to maintain and modify the code by using the "pool" VBA Editor. Then, I decided to move those VBA code to C# solutions, which I
    suppose I can benefit from the modern editor - Visual Studio.
    Problem:
    Although I don't know too much about VBA, I know even less about C#. Hence I got some problem when I try to "translate" my VBA code to C#, and here is one of them:
    I create a document-level solution for Excel. I need to embed some files (.cab, .exe) into the solution, so when I run a method (e.g. by clicking a button), those files will be copied to the file system, and do some job.
    In VBA, I embedded those files in the Excel workbook, then I can copy the embedded objects to the clipboard by using the following VBA code:
    Sheet1.OLEObjects("obj_cab").COpy
    And then I can paste the object to the file system by using the following VBA code:
    CreateObject("Shell.Application").Namespace("C:\Sample\").Self.InvokeVerb "Paste"
    In the C# solution, I can use the following equivalent method to copy the embedded object to the clipboard:
    Microsoft.Office.Interop.Excel.OLEObject OLEobj = (Microsoft.Office.Interop.Excel.OLEObject)sheet1.OLEObjects("obj_cab");
    OLEobj.Copy();
    Then I stuck here, I don't know how to get this object from clipboard and put it to the file system. The 'CreateObject' method does not exist in C#.
    Anyone can help? Either a better way to embed those files or a working way to paste those objects (files) from clipboard to the file system?
    Thanks a lot!

    Hi FantaC,
    It's possible to save the oleobject to the disk. But it's not very simple. Because when you call the Copy method of OLEObject to clipboard, it's actually not the exact the oleobject file itself, it's actually a wrapper of the file, it means that it has different
    file headers and some other information from the original oleobject file.
    To save oleobject on the disk, you need to analyze the byte array by yourself, this would be a little complicated. You could check the answer in this thread for the code sample:
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/1ab7a178-8021-4c67-a14b-5031a254fd9c/saving-oleobject-content-to-a-file
    The original poster of this thread also write a blogpost about this, you can check it here:
    Saving OLEObject Content To File
    Detailed information and code samples are provided in this blogpost.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Copying value of objects, not reference?

    This has been bothering me for a while. I learned that when you set one object equal to another you are really just assigning the same reference to both, so that if one is altered they are both altered. Well, how can you set one object equal to the value of another but not the same reference so that altering one will not alter the other. My concern stems from returning arrays in methods. Since the reference itself is passed, any changes I make to the array are permanent, correct, and not just existing inside the method? So I was thinking maybe the best solution would be to use a tmp{] variable that is equal to the VALUE of the array I pass in, and then return that, so the original array is not altered in any way. Is this the customary practice for dealing with such situations? If not, what is typically done? Oh and just for future reference, because it might be of value to know, how DO I copy a value and not a reference? (and yes, that WAS on purpose ;) )

    violagirl23 wrote:
    My concern stems from passing arrays to [KRC] methods. Since the reference itself is passed, any changes I make to the array are permanent, correct, and not just existing inside the method? So I was thinking maybe the best solution would be to use a tmp{] variable that is equal to the VALUE of the array.Both georgemc and tschodt have already given you some good pointers, I'll try not to reiterate the same advise.
    This is an old "problem", discussed at length by folks much smarter than myself, and (IMHO) there still is no definitive question, let alone universal answer. What I mean is that sometimes this ability to modify the contents of a collection or array within a method is highly desirable; and sometimes of course it's just a source of bugs, when a noob calls your method not realising that it modifies the contents of the passed array (which shouldn't make it past unit testing anyway)... So, I think probably the best thing I can do for you is to give you the terms to google.
    What you're talking about is called a defensive copy... which, especially with arrays and collections, typically involves a deep copy (make a copy of every attribute of every object, all the way down the reference tree)... as apposed to Arrays.copyOf, which is a shallow copy, i.e. it just copies the references to the "top" objects.
    If you're writing a system from scratch you could decide to implement clone methods for everything you ever need to defensive copy. Cloning is ugly, no matter how you cook it. It requires every part of the class heirarchy being cloned to support the clone method (properly).
    In the past, I've tried to write a "generic" copy method, in the abstract-base-type of a class heirarchy using reflections. Everything I've tried has "pretty fatal" flaws. The only "proper" solution (AFAIK) is to just implement clone in every single frickin class... and that's a lot more "boiler plate" code than I personally think should be required to implement such a common, mundane task.
    Alternately, you could make all your data transfer objects immutable, so a shallow copy (Arrays.copyOf) of the array is enough to protect the calling code from unexpected changes to the array contents because you are passing "a copy" of the references to things-that-cannot-change... So the callee cannot mutate a pointed-to object, and if the callee changes which object an array element points-to, you won't "see" the change... and of course the callee cannot change which array your reference points to, because Java passes references by value.
    Google all the italic stuff... Sun's stuff is the best, then lookout for IBM's stuff, and most Wikipedia articles are really good (a few not so good).
    HTH. Cheers. Keith.

  • Displaying the contents of an array of objects

    Hello All,
    My Java teacher gave us a challenge and I'm stumped. The teacher wants us to display the contents of the array in the main menthod. The original code is as follows:
    public class TestObjects
         public static void main ( String args[] )
              Thing[] thingArray = { new Thing(4), new Thing(7) };
    }I understand that the elements of the array are objects, and each one has a value assigned to it. The following code was my first attempt at a solution:
    public class TestObjects
         public static void main ( String args[] )
              Thing[] thingArray = { new Thing(4), new Thing(7) };
                                    for ( int i = 0; i < thingArray.length; i++)
                                       System.out.println( thingArray );                         
    }To which I'm given what amounts to garbage output. I learned from reading about that output that its basically displaying the memory location of the array, and the the contents of the array. There was mention of overriding or bypassing a method in System.out.println, but I don't believe that we're that far advanced yet. Any thoughts? I know I have to get at the data fields in the objects of the array, but i'm not having an easy time figuring it out. Thanks very much in advance!

    robrom78 wrote:
    public class TestObjects
         public static void main ( String args[] )
              Thing[] thingArray = { new Thing(4), new Thing(7) };
    for ( int i = 0; i < thingArray.length; i++)
    System.out.println( thingArray );                         
    Note that you're trying to print the entire array at every loop iteration. That's probably not what you meant to do.
    You probably meant to do something more like
                                 System.out.println( thingArray[i] );Also, note that the java.util.Arrays class has a toString method that might be useful.
    To which I'm given what amounts to garbage output. It's not garbage. It's the default output to toString() for arrays, which is in fact the toString() defined for java.lang.Object (and inherited by arrays).
    I learned from reading about that output that its basically displaying the memory location of the array, and the the contents of the array.It displays a default result that is vaguely related to the memory, but probably shouldn't be thought of us such. Think of it as identifying the type of object, and a value that differentiates it from other objects of the same type.
    By the way I assume you mean "+not+ the contents of the array" above. If so, that is correct.
    There was mention of overriding or bypassing a method in System.out.println, but I don't believe that we're that far advanced yet. Any thoughts? No, you don't override a method in println; actually methods don't contain other methods directly. You probably do need to override toString in Thing.
    I know I have to get at the data fields in the objects of the array, but i'm not having an easy time figuring it out. You can get to the individual objects in the array just by dereferencing it, as I showed you above.
    But I suspect that won't be sufficient. Most likely, Thing doesn't have a toString method defined. This means that you'll end up with very similar output, but it will say "Thing" instead of "[Thing" and the numbers to the right of the "@" will be different.
    You'll need to override the toString() method in Thing to get the output you want.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • My Adobe Flash Player won't install. ( At all )

    So when I try to install Adobe Flash Player, everytime, on every user on my computer, it always pops up when i launch it, but nothing happens. It is just a boring gray screen. I need Flash Player to play like all the games in the world ( exaggeration

  • How to tell if my netbook has gigabit Ethernet (and/or can use it)

    I have owned an Asus Eee 701SD (the 8GB version) since 2009, and installed Arch on it last summer (a great move :-) ). The other day, I came across a page on the FreeBSD wiki, which suggested that certain 700-series Eee's have a gigabit Ethernet inte

  • Technical interview questions on this objects

    Hi every one  i am putting some objects in my resume can any one tell me the all possible questions on these objects. my id is [email protected] Reports:      Developed a Report to display the values of Total Finished Goods filtered by Plant.      

  • Memory Leak in Linux OS

    Using JNI1.2 for C++ and JAVA communication. And the Java application is a multithread application and monitoring JBoss application server using JMX. In each 5 minute interval the C++ application is invoking a method of java class and for each method

  • MPS and MRP question

    Hi all, There are two kinds of planning run (i.e. MPS and MRP). I have few questions on this. 1 - Do I need to setup two background jobs, one for MPS job, and another follow by MRP job, in the system? 2 - Can I just run MPS using MD40 (total MPS run)