Initalizing loop variable - best practice?

Hello All,
What do people think is the best way to initalise a variable that is going to be assigned in a loop and used afterwards.
For instance say I had a vector of objects of some class (lets say class "Bean") and I want to find a bean in that Vector with a specific attribute value. I set up a loop variable, myBean, of type Bean and then test each object by assigning it to myBean:
Iterator it = myVector.iterator(); //1
while (it.hasNext()) {  //2
myBean = (Bean)it.next(); //3
if (myBean.getMyAttribute() == testValue) break; //4
myBean.doSomething(); //5
The question is how do I best set up myBean? I would like to simply place the line:
Bean myBean;
before the loop, except this is bad practice as the variable may never be initalised, I know it will in this simple case but in general its bad to leave null variables around.
I could use:
Bean myBean = new Bean();
but that is creating an object for no reason, and if I set up the variable in the loop (Bean myBean = (Bean)it.next()) it will not be available to me after the loop has terminated?
So is there a way to do this that doesn't require creating a useless object?
cheers
matt

It's not clear whether you need to use myBean outside the while loop or not. If you are not going to use myBean outside the loop,
while (it.hasNext()) { //2
   Bean myBean = (Bean)it.next(); //3
   if (myBean.getMyAttribute() == testValue) break; //4
   myBean.doSomething(); //5
}If you are going to use myBean outside the loop, you must declare it outside the loop. But you can set it to null so you don't needlessly create an object.
Bean myBean = null;
while (it.hasNext()) { //2
   myBean = (Bean)it.next(); //3
   if (myBean.getMyAttribute() == testValue) break; //4
if(myBean != null) myBean.doSomething(); //5

Similar Messages

  • Bad bind variable & best practice for delete

    I am working with three tables and very new to SQL. I need to create a procedure that will accept an ID and go through two sub tables and delete child records. Item is the main table. I am passing in the ID into the procedure and I want to use it as below. I keep getting a bad bind variable error message. I have verified that the table is setup as a number and my procedure accepts a number. I also want someone to review this from best practice as I am new to procedures.
    PROCEDURE DeleteItem (p_ItemID IN NUMBER, p_RowsAffected OUT number)
    IS
    p_RowsAffected NUMBER;
    -- select the itemdetail for the analysis
    CURSOR c_itemdetail
    IS
    SELECT
    itemdetailid
    FROM itemDETAIL
    WHERE itemid = :p_ItemID;
    BEGIN
    -- loop through each itemdetail and delete the itemdetailoutlay
    FOR r_itemdetail IN c_itemdetail
    LOOP
    BEGIN
    DELETE FROM ITEMDETAILOUTLAY
    WHERE itemdetailid = r_itemdetail.itemdetailid;
    COMMIT;
    END;
    END LOOP;
    -- delete the itemdetail
    BEGIN
    DELETE FROM ITEMDETAIL
    WHERE itemid = :p_ItemID;
    COMMIT;
    END;
    -- delete the main item
    BEGIN
    DELETE FROM ITEM
    WHERE itemdid = :p_ItemID;
    COMMIT;
    p_RowsAffected := SQL%ROWCOUNT;
    END;
    END DeleteItem;

    Hi,
    Welcome to the forum!
    As you may notice, this site normally compresses white-space. Whenever you post code, or any formatted text, on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    I don't think you mean to use bind variables anywhere, so don't use colons before any variable names.  You were doing this correctly with p_RowsAffected; do the same thing with p_ItemID.
    Try this:PROCEDURE DeleteItem (p_ItemID IN NUMBER, p_RowsAffected OUT number)
    IS
    -- p_RowsAffected NUMBER;     -- Don't name local variables the same as arguments
    -- select the itemdetail for the analysis
    CURSOR c_itemdetail
    IS
    SELECT
    itemdetailid
    FROM itemDETAIL
    WHERE itemid = p_ItemID;     -- No : before p_ItemID
    BEGIN
    -- loop through each itemdetail and delete the itemdetailoutlay
    FOR r_itemdetail IN c_itemdetail
    LOOP
    BEGIN
    DELETE FROM ITEMDETAILOUTLAY
    WHERE itemdetailid = r_itemdetail.itemdetailid;
    COMMIT;
    END;
    END LOOP;
    -- delete the itemdetail
    BEGIN
    DELETE FROM ITEMDETAIL
    WHERE itemid = p_ItemID;     -- No : before p_ItemID
    COMMIT;
    END;
    -- delete the main item
    BEGIN
    DELETE FROM ITEM
    WHERE itemdid = p_ItemID;     -- No : before p_ItemID
    COMMIT;
    p_RowsAffected := SQL%ROWCOUNT;
    END;
    END DeleteItem;
    The most important "best practice" with PL/SQL is to avoid doing it whenever possible. 
    If SQL offers a way o do the same thing, it's usally best not to code anything in PL/SQL.
    Have you considered foreign key constraints, with "ON DELETE CASCADE"?  That way, you could simply "DELETE FROM item", and all the dependent rows in the other tables would automatically be deleted.   You wouldn't need to remember to call a procedure like this; in fact, you would have no need for a procedure like this.
    Given that you do have such a procedure:
    You're doing row-by-row processing, which some mad wags like to call "slow-by-slow" processing.
    For example, iYou're xplicitly finding each ItemDetailID separately, and deleting each one separately, like this:... CURSOR c_itemdetail
    IS
    SELECT
    itemdetailid
    FROM itemDETAIL
    WHERE itemid = p_ItemID;
    -- loop through each itemdetail and delete the itemdetailoutlay
    FOR r_itemdetail IN c_itemdetail
    LOOP
    BEGIN
    DELETE FROM ITEMDETAILOUTLAY
    WHERE itemdetailid = r_itemdetail.itemdetailid;
    COMMIT;
    END;
    END LOOP;
    It's more efficient for the system (and less coding for you) if you let SQL handle as much as possible, so do this instead...     DELETE FROM ItemDetailOutlay
         WHERE ItemDetailID IN
              ( SELECT itemdetailid
              FROM     itemDETAIL
              WHERE     itemid     = p_ItemID
    Do you really want to COMMIT 3 times?  0 or 1 times might be better.
    What happens if there is some kind of error, say, after you've delete rows form ItemDetailOutlay and ItemDetail, but before you've delete from Item?  Wouldn't you want the entire transaction to fail, and leave all three tables in a consistent state?  If so, either have the calling procedure COMMIT, or have a single COMMIT at the end of DelteItem.
    Edited by: Frank Kulash on May 6, 2010 2:25 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Select One Choice attribute' LoV based on two bind variables, best practice

    Hello there,
    I am in the process of learning the ADF 11g, I have following requirement,
    A page must contain a list of school names which is needed to be fetched based on two parameters, the parameters are student information been inserted in the previous page.
    I have defined a read only view "SchoolNamesViewRO", it's query depends on two bind variables :stdDegree and stdCateg.
    added that RO View as a view accessor to the entity to which the name attribute belongs, and then add LoV for the name attribute using the ReadOnly view,
    added the name attribute as Select One Choice to page2,
    and now I need to pass the values of the bind variables of the ReadOnly view,
    the information needed to be passed as the bind variables is inserted in the previous page, I could have the data as bindings attribute values in the page2 definition
    I have implemented the next two appraoches but both resulted in an empty list :
    * added ExecuteWithParams Action to the bindings of the page and then defined an Invoke Action (set refresh condition) in the executable s, set the default values of the parameters to be the attributes values' input value,
    in the trace I code see that the binding fetches correct values as supposed , but the select list appears empty, does the this execution for the query considered to be connected to the list ?
    * added a method to the ReadOnly view Imp java class to set the bind variables, then I define it as a MethodAction in the bindings , and then create an Invoke action for it , also the select is empty,
    if the query been executed with the passed variables, then why the list is empty? is it reading data from another place than the page!
    and what is the best practice to implement that requirement?
    would the solution be : by setting the default value of the bind variables to be some kind of Expression!
    please notice that query execution had the bound variables ( I see in the trace) are set to the correct values.
    would you give some hints or redirect me to a useful link,
    Thanks in advance
    Regards,

    please give me any example using backing bean .for example
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
    <af:document id="d1">
    <af:form id="f1">
    <af:selectOneChoice label="Label 1" id="soc1" binding="#{Af.l1}"
    autoSubmit="true">
    <af:selectItem label="A" value="1" id="si1"/>
    <af:selectItem label="B" value="2" id="si2"/>
    </af:selectOneChoice>
    <af:selectOneChoice label="Label 2" id="soc2" disabled="#{Af.l1=='2'}"
    partialTriggers="soc1">
    <af:selectItem label="C" value="3" id="si3"/>
    <af:selectItem label="D" value="4" id="si4"/>
    </af:selectOneChoice>
    </af:form>
    </af:document>
    </f:view>
    </jsp:root>
    package a;
    import oracle.adf.view.rich.component.rich.input.RichSelectOneChoice;
    public class A {
    private RichSelectOneChoice l1;
    public A() {
    public void setL1(RichSelectOneChoice l1) {
    this.l1 = l1;
    public RichSelectOneChoice getL1() {
    return l1;
    is there any mistake

  • Best practices for file I/O within producer/c​onsumer loops

    I'm looking to add file recording and playback functionality to a pre-existing data collection program.  The original progam is based on a Moore-style state machine, which I have added four additional states to.  They are: Record Start, Record Stop, Playback Start, and Playback Stop.
    What I have done, and what has since been identified as poor programming practice, was to "initialize" (either create or load) the appropriate file within the state machine loop during the "Start" command (for record or playback functionality), and then provide the file reference as an indicator, which is linked to for the appropriate read or write operation(whether I'm playing back or recording).  The actual I/O occurs within the the Consumer Loop. (screenshots attached).
    This is my first labview project outside of tutorials or other small examples, so any advise and constructive criticisims are welcomed.  Specifically with regards to file IO and refnum routing (it gets a little hairy in the consumer loop)!
    I'm running Labview 8.6 on Vista business.
    Attachments:
    Playback Start.JPG ‏71 KB
    Consumer_Loop.JPG ‏122 KB
    File Playback subvi.JPG ‏14 KB

    jamoore84 wrote:
    Ben,
    Thanks for the suggestion.  I think it's a little outside my ken at this moment, but  I'll look it over.  Despite any grevious coding transgressions, I have experienced some limited success with the current setup.  While the use of Action Engines/Functional Globals may constitute the best practice, I might revise my post to read "acceptable and/or easily absorbable practices" instead.
    Are there any other opinions on this?  Let me start by listing a problem and posing a question:
    Problem:  I am able to playback a file only once.  Subsequent attempts at file playback do not work.
    Thanks in advance,
    jimmy 
    HI Jimmy,
    I don't give up easy.
    Let me try to exaplain the issue with race conditons with a contrived example, the
     "Command by Mail box" case.
    Imagine you had a job where you recieved your orders via an old fashioned mail box. You never really saw your supervisor but relied on getting orders via the mail box. Now imagine the mail box could only hold one message and any time a new message was inserted, the old one would fall into the trash.
    So you come to work each day check your mail box do what was ordered and everyone is happy.
    The next day you come in and without your knowing, you are assigned to do the work of two bosses. So as long as you check your mail box more often than the two of them assigne work everything is fine... until you take a day of vacation! So you come back in the day after vacation and check you mail box and work a way until you catch hell for ignoring orders !?! Wel it turn out the order from boss 1 was replaced by the order from boss 2 while you were on vacation. Oh bother!
    How can we fix it?
    1) Expand the mail box so it hold more than one order. You just process them in the oder they are recieved.
    2) Change to mail box to not accept a new order until you have removed the old.
    Now back to reality!
    Local variables act like the funky mail box. The last message insterted over-rides the previous.
    Multiple variable writer ar like multiple bosses.
    Queues operate like an expanded mail box, letting you handle each message in order.
    Action Engines operate like the "mutexed" mail box.
    Why I don't want to encorage you to "just patch up" what you have.
    All of the less than ideal solutions either over-sample (Check e-mail twice as often as bosses assign work, waste CPU, an exercise in futility if you are coding in a non-Real-Time envirionment like Windows) or use a mutex to control access to the shared resource ( in this case local varialbes).
    LV offers mutexes through semaphores (found on the syncronization pallete) but...
    WHY WORK SO HARD?
    In my AE Nugget I explain that the exection of an AE is automatically protected by LV. So in the long run it will actually be easier to learn how to use the AE programming construct than it will be to learn how to solve the problem without them.
    so GO FOR IT! Take the lazy route and learn how to use the AE construct. Use the Syncronization pallete for Queues.  
    Just trying to help,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Row level security with session variables, not a best practice?

    Hello,
    We are about to implement row level security in our BI project using OBIEE, and the solution we found most convenient for our requirement was to use session variables with initalization blocks.
    The problem is that this method is listed as a "non best practice" in the Oracle documentation.
    Alternative Security Administration Options - 11g Release 1 (11.1.1)
    (This appendix describes alternative security administration options included for backward compatibility with upgraded systems and are not considered a best practice.)
    Managing Session Variables
    System session variables obtain their values from initialization blocks and are used to authenticate Oracle Business Intelligence users against external sources such as LDAP servers or database tables. Every active BI Server session generates session variables and initializes them. Each session variable instance can be initialized to a different value. For more information about how session variable and initialization blocks are used by Oracle Business Intelligence, see "Using Variables in the Oracle BI Repository" in Oracle Fusion Middleware Metadata Repository Builder's Guide for Oracle Business Intelligence Enterprise Edition.
    How confusing... what is the best practice then?
    Thank you for your help.
    Joao Moreira

    authenticating / authorizing part is take care by weblogic and then USER variable initialized and you may use it for any initblocks for security.
    Init block for authenticating / authorizing and session variables are different, i guess you are mixing both.

  • Best practice: Using break statement inside for loop

    Hi All,
    Using break statment inside FOR loop is a best practice or not?
    I have given some sample code:
    1. With break statement
    2. With some boolean variable that decide whether to come out of the loop or not.
    for(int i = 0; i < 10; i++){
    if(i == 5){
    break;
    boolean breakForLoop = false;
    for(int i = 0; i < 10 && !breakForLoop; i++){
    if(i == 5){
    breakForLoop = true;
    The example may be a stupid one. But i want to know which one is good?
    Thanks and Regards,
    Ashok kumar B.

    Actually, it's bad practice to use break anywhere other than in conjunction with a switch statement.Presumably, if you favour:
    boolean test = true;
    while (test)
      test = foo && bar;
      if (test)
    }overfor (;;)
      if (! ( foo && bar) ) break;
    }then you also favour
    boolean test = foo && bar;
    if (test)
    }overif (foo && bar)
    }Or can you justify your statement with any example which doesn't cause more complexity, more variables in scope, and multiple assignments and tests?

  • Best Practice for setting bind variable when application loads

    I am using JDeveloper 11.1.2.3.
    When my application loads, the first unbounded page has a table populated by a named query.
    I would like to set the parameter used by the named query when the page loads, to populate the initial data that is displayed.
    What is the best practice for a solution to this issue?

    user6003393 wrote:
    I am using JDeveloper 11.1.2.3.
    When my application loads, the first unbounded page has a table populated by a named query.
    I would like to set the parameter used by the named query when the page loads, to populate the initial data that is displayed.
    What is the best practice for a solution to this issue?Hi,
    You can set the bind variable on VO by overriding prepareSession() method in Application Module check this http://docs.oracle.com/cd/E37975_01/web.111240/e16182/bcservices.htm#sthref357
    Setting bind variable on runtime http://docs.oracle.com/cd/E37975_01/web.111240/e16182/bcquerying.htm#CHDECJHD
    Zeeshan

  • What is the best practice to set Captivate variables from Get (less ideal) and Post (more ideal)?

    We are trying to set a couple of variables in Captivate 7 by posting the information from a URL. Is there a best practice for doing this, or does it require a custom JS or other call in order to do this?
    Essentially, we want to pass three variables from a URl to named variables in a Captivate 7 swf so that the information can be drawn from a database, and does not need to be entered by the user.
    Suggestions, thoughts, pointers to where we may be able to find this information - all would be greatly appreciated!

    Not sure how Captivate treats FlashVars internally, but the native html template includes a script to read URL parameters:
    var strURLFull = window.document.location.toString();
    var intTemp = strURLFull.indexOf("?");
    var strURLParams = "";
    then:
    if(strURLParams != "")
       so.addVariable("flashvars",strURLParams);
    It also has a script to add variables but you'd have to parse the variables first first to use it:
    so.addVariable("variable1", "value1");

  • Best Practice in defining variables

    Hi All
    What is the best practice to use variables inside a method and any specific advantage .i.e. initializing variables starting of the method vs defining them where they are required.
    public String abc(){
    int i = 0;
    String s = null;
    i = 10 + 50;
    s = "Java" + "world";
    return s;
    vs
    public String abc(){
    int i = 10 + 50;
    String s = "Java" + "world";
    return s;
    }

    SRAVZ wrote:
    What is the best practice to use variables inside a method and any specific advantage .i.e. initializing variables starting of the method vs defining them where they are required.As the others wrote the later is preferred. One reason is that this can save memory.
    Another (IMHO) important reason is that it eases the use of refactorings provided by your IDE.
    Look at this code: public int testRefactoring() {
              int result = 0, factor = 0;
              RefactoringTest rt = new RefactoringTest();     
              result = rt.getA();
              factor *=result ;
              result= factor;
              result += rt.getB();
              return result;
         }As you may see the calculation of the result uses only values from the class <tt>RefactoringTest</tt> so it should be placed there. This is no problem since almost any IDE can do this in 2 steps:<ol><li>extract method</li><li>move method (to one of its parameters)</li></ol>Lets start with the first step: <ul><li>select lines 4 to 7 </li><li> hit "shift+alt+m" (in eclipse),</li><li> enter a name for the new method </li><li> click OK.</li></ul>
    The result is a method with 3 Parameters. Two of them are useless.
    If you'd switch line 2 and 3 you could include the variable declaration in your selection thus leading to a method with one parameter only...
    bye
    TPD

  • Best practices for logging results from Looped steps

    Hi all
    I would like to start a discussion  to document best practices for logging results (to reports and databases) from Looped Steps 
    As an application example - let's say you are developing a test for one of NI's analog input or output cards and need to measure a voltage across multiple inputs or outputs.
    One way to do that would be to create a sequence that switches the appropriate signals and performs a "Voltage Measurement" test in a loop.    
    What are your techniques for keeping track of the individual measurements so that they can be traced to the individual signal paths that are being measured?
    I have used a variety of techniques such as
    i )creating a custom step type that generates unique identifiers for each iteration of the loop.    This required some customization to the results processing . Also the sequence developer had to include code to ensure that a unique identifier was generated for each iteration
    ii) Adding an input parameter to the test function/vi, passing loop iteration to it and adding this to Additional results parameters to log.   

    I have attached a simple example (LV 2012 and TS 2012) that includes steps inside a loop structure as well as a looped test.
    If you enable both database and report generation, you will see the following:
    1)  The numeric limit test in the for loop always generates the same name in the report and database which makes it difficult to determine the result of a particular iteration
    2) The Max voltage test report includes the paramater as an additional result but the database does not include any differentiating information
    3) The Looped Limit test generates both uniques reports and database entries - you can easily see what the result for each iteration is.   
    As mentioned, I am seeking to start a discussion for how others handle results for steps inside loops.    The only way I have been able to accomplish a result similar to that of the Looped step (unique results and database entry for each iteration of the loop) is to modify the process model results processing.  
    Attachments:
    test.vi ‏27 KB
    Sequence File 2.seq ‏9 KB

  • Best practices for setting environment based static variables?

    I have a set of static string variables that hold the url location of modules in a project. These locations change depending on whether I'm building for development, staging or production.
    What's the best way to set static variables in this way?

    I don't know if this is best practice, but here's the solution I've come up with.
    The root domain is accessible within the swf via a node on a loaded xml file. So I created a simple method that sets a url variable based on that domain node.
    The domain-based url variable is then used within the static string variables that define the location of the modules.
    Simplified like so:
    var domain:String = xml.node.value;
    static var bucketLocation:String = getLocation()
    static var moduleLocation:String = bucketLocation + "modulename.swf";
    function getLocation():String
         var loc:String
         switch (domain) {
              case stagingUrl:
                  loc = "pathToAmazonStagingBucket";
                   break;
              case productionUrl:
                   loc = "pathToAmazonProductionBucket";
                   break;

  • Best practices for defining Environment Variables/User Accounts in Linux

    Hello,
    After reading throught the Quick Install guide for 10gR2 on x86_64 Linux, I see that it is not recommended to define ANY variables in .bash_profile.
    I'm hoping to get a Best practices approach for defining environment variables - right now we use the oracle linux account for administration including sql*plus. So, where should the myriad variables be defined? Is it important enough to create a user account in linux to support best practices?
    What variables, exactly, should be defined? It seems that LD_LIBRARY_PATH is no longer being used?
    Thanks in advance
    Doug

    Something that I've done for years on unix/linux boxes is to create a seperate environment variable setup file for each instance on the box. This would include things like ORACLE_HOME, ORACLE_SID, etc. Then I would create an alias in my .bash_profile that would execute this script. As an example, I would create a orcl.env file that would hold all of the environment variables for this instance. Then in my .bash_profile I would create a line like the following:
    alias orcl=". $HOME/orcl.env"
    Then from anywhere you could type orcl and you would set your environment to connect to that database.
    Also, if you are using 10g, something else that is really nice if you are using sqlplus, and you connect to different databases without starting a new sqlplus session is to set a parameter in your $ORACLE_HOME/sqlplus/admin/glogin.sql file:
    set sqlprompt "_user 'at' _connect_identifier >"
    This will automatically change your command prompt to look like this:
    RALPH at ORCL >
    if you connect as GEORGE, your prompt will immediately change to :
    GEORGE at ORCL >
    This way you can always know who and where you are connected to.
    Good luck!

  • Best Practice for managing variables for multiple environments

    I am very new to Java WebDynPro and have a question
    concerning our deployments to Sandbox, Development, QA,
    and Production environments.
    What is the 'best practice' that people use so that if
    you have information specific to each environment you
    don't hard-code it in your Java WebDynPro code.
    I could put the value in a properties file, but how do I
    make that variant?  Otherwise I'd still have to make a
    change for each environment to the property file and
    re-deploy.  I know there are some configurations on the
    Portal but am not sure if that will work in my instance.
    For example, I have a URL that varies based on my
    environment.  I don't want to hard-code and re-compile
    for each environment.  I'd prefer to get that
    information on the fly by knowing which environment I'm
    running in and load the appropriate URL.
    So far the only thing I've found that is close to
    telling me where I'm running is by using a Parameter Map
    but the 'key' in the map is the URL not the value and I
    suspect there's a cleaner way to get something like that.
    I used Eclipse's autosense in Netweaver to discover some
    of the things available in my web context.
    Here's the code I used to get that map:
    TaskBinder.getCurrentTask().getWebContextAdapter().getRequestParameterMap();
    In the forum is an example that gets the IP address of
    the site you're serving from. It sounds like it is going
    to be or has been deprecated (it worked on my system
    right now) and I would really rather have something like
    the DNS name, not something like an IP that could change.
    Here's that code:
    String remoteHost = TaskBinder.getCurrentTask().getWebContextAdapter().getHttpServletRequest().getRemoteHost();
    Thanks in advance for any clues you can throw my way -
    Greg

    Hi Greg:
         I suggest you that checks the "Software Change Managment Guide", in this guide you can find an explication of the best practices to work with a development infrastructure.
    this is the link :
    http://help.sap.com/saphelp_erp2005/helpdata/en/83/74c4ce0ed93b4abc6144aafaa1130f/frameset.htm
    Now if you can gets the ip of your server or the name of your site you can do the next thing:
    HttpServletRequest request = ((IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();
    String server_name = request.getServerName();
    String remote_address =     request.getRemoteAddr()
    String remote_host = request.getRemoteHost()
    Only you should export the servlet.jar in your project properties > Build Path > Libraries.
    Good Luck
    Josué Cruz

  • Best practice to process inbound soapenc:Array

    Hi, I'm working my way through a real world example where I've sent a keyword search query to Amazon and it return 10 results. This works great. Now I want to loop thru the Array and put the returned values into a table in the database. I can't seen to get down to the element level via XQuery to assign the returned values to my local variables. The XML returned is defined in the wdsl as:
         <xsd:complexType name="DetailsArray">
         <xsd:complexContent>
         <xsd:restriction base="soapenc:Array">
    <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:Details[]"/>
    </xsd:restriction>
    </xsd:complexContent>
    </xsd:complexType>
         <xsd:complexType name="Details">
    What's the best practice for walking thru this incoming XML Array?
    Thanks...Matt

    Hello again!
    Thanks for quick reply!
    The instance state says : closed.completed.
    Perhaps the problem is not the insert into db, but the transformation activity?
    This is what the audit trail (raw xml) looks like:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <audit-trail>
    - <event sid="0" cat="2" type="2" n="0" date="2008-06-24T10:16:21.875+02:00">
    - <message>
    - <![CDATA[ New instance of BPEL process "BPELProcess3" initiated (# "150001").
      ]]>
    </message>
    </event>
    - <event sid="BpPrc0.1" cat="1" type="2" label="process" n="1" date="2008-06-24T10:16:21.875+02:00" psid="0">
    - <message>
    - <![CDATA[ _cr_
      ]]>
    </message>
    </event>
    - <event sid="BpTry0.2" cat="1" type="2" n="2" date="2008-06-24T10:16:21.890+02:00" psid="BpPrc0.1">
    - <message>
    - <![CDATA[ _cr_
      ]]>
    </message>
    </event>
    - <event sid="BpSeq0.3" cat="1" type="2" label="sequence" n="3" date="2008-06-24T10:16:21.890+02:00" psid="BpTry0.2">
    - <message>
    - <![CDATA[ _cr_
      ]]>
    </message>
    </event>
    - <event sid="BpSeq0.3" cat="2" type="2" wikey="150001-BpRcv0-BpSeq0.3-1" n="4" date="2008-06-24T10:16:21.921+02:00">
    - <message>
    - <![CDATA[ Received "inputVariable" call from partner "client"
      ]]>
    </message>
    - <details>
    - <![CDATA[
    <inputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload"><ns1:BPELProcess3ProcessRequest xmlns:ns1="http://xmlns.oracle.com/BPELProcess3">
                <ns1:stations>18700</ns1:stations>
                <ns1:username/>
            </ns1:BPELProcess3ProcessRequest>
    </part></inputVariable>
      ]]>
    </details>
    </event>
    - <event to="GetStationProperties_getStationsProperties_InputVariable" sid="BpSeq0.3" cat="2" type="1" wikey="150001-BpAss0-BpSeq0.3-2" n="5" date="2008-06-24T10:16:21.953+02:00">
    - <message>
    - <![CDATA[ Updated variable "GetStationProperties_getStationsProperties_InputVariable"
      ]]>
    </message>
    - <details>
    - <![CDATA[
    <GetStationProperties_getStationsProperties_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="stations"><stations>18700</stations>
    </part><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="username"><username xmlns="" xmlns:def="http://www.w3.org/2001/XMLSchema" xsi:type="def:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    </part></GetStationProperties_getStationsProperties_InputVariable>
      ]]>
    </details>
    </event>
    - <event to="GetStationProperties_getStationsProperties_InputVariable" sid="BpSeq0.3" cat="2" type="1" wikey="150001-BpAss0-BpSeq0.3-2" n="6" date="2008-06-24T10:16:21.953+02:00">
    - <message>
    - <![CDATA[ Updated variable "GetStationProperties_getStationsProperties_InputVariable"
      ]]>
    </message>
    - <details>
    - <![CDATA[
    <GetStationProperties_getStationsProperties_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="stations"><stations>18700</stations>
    </part><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="username"><username/>
    </part></GetStationProperties_getStationsProperties_InputVariable>
      ]]>
    </details>
    </event>
    - <event sid="BpSeq0.3" cat="2" type="2" wikey="150001-BpInv0-BpSeq0.3-3" partnerWSDL="MetDataService2Ref.wsdl" n="7" date="2008-06-24T10:16:22.968+02:00">
    - <message>
    - <![CDATA[ Invoked 2-way operation "getStationsProperties" on partner "MetDataService".
      ]]>
    </message>
    - <details>
    - <![CDATA[
    <messages><GetStationProperties_getStationsProperties_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="stations"><stations>18700</stations>
    </part><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="username"><username/>
    </part></GetStationProperties_getStationsProperties_InputVariable><GetStationProperties_getStationsProperties_OutputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="return"><return xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Array" xmlns:ns3="http://no.met.metdata/IMetDataService.xsd" ns2:arrayType="ns3:no_met_metdata_StationProperties[1]" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <item xsi:type="ns3:no_met_metdata_StationProperties">
    <toDay xsi:type="xsd:int">0</toDay>
    <toMonth xsi:type="xsd:int">0</toMonth>
    <fromYear xsi:type="xsd:int">1937</fromYear>
    <municipalityNo xsi:type="xsd:int">301</municipalityNo>
    <amsl xsi:type="xsd:int">94</amsl>
    <latDec xsi:type="xsd:double">59.9427</latDec>
    <lonDec xsi:type="xsd:double">10.7207</lonDec>
    <toYear xsi:type="xsd:int">0</toYear>
    <department xsi:type="xsd:string">OSLO</department>
    <fromMonth xsi:type="xsd:int">2</fromMonth>
    <stnr xsi:type="xsd:int">18700</stnr>
    <wmoNo xsi:type="xsd:int">492</wmoNo>
    <latLonFmt xsi:type="xsd:string">decimal_degrees</latLonFmt>
    <name xsi:type="xsd:string">OSLO - BLINDERN</name>
    <fromDay xsi:type="xsd:int">25</fromDay>
    </item>
    </return>
    </part></GetStationProperties_getStationsProperties_OutputVariable></messages>
    ]]>
    </details>
    </event>
    - <event to="StoreStationProperties_insert_InputVariable" sid="BpSeq0.3" cat="2" type="1" wikey="150001-BpAss1-BpSeq0.3-4" n="8" date="2008-06-24T10:16:23.000+02:00">
    - <message>
    - <![CDATA[ Updated variable "StoreStationProperties_insert_InputVariable"
      ]]>
    </message>
    - <details>
    - <![CDATA[
    <StoreStationProperties_insert_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="EklimaStationsTblCollection"><EklimaStationsTblCollection xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/top/db" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/top/db"/>
    </part></StoreStationProperties_insert_InputVariable>
      ]]>
    </details>
    </event>
    - <event sid="BpSeq0.3" cat="2" type="2" wikey="150001-BpInv1-BpSeq0.3-5" partnerWSDL="db.wsdl" n="9" date="2008-06-24T10:16:27.312+02:00">
    - <message>
    - <![CDATA[ Invoked 1-way operation "insert" on partner "db".
      ]]>
    </message>
    - <details>
    - <![CDATA[
    <StoreStationProperties_insert_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="EklimaStationsTblCollection"><EklimaStationsTblCollection xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/top/db" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/top/db"/>
    </part></StoreStationProperties_insert_InputVariable>
      ]]>
    </details>
    </event>
    - <event sid="BpSeq0.3" cat="2" type="2" wikey="150001-BpRpl0-BpSeq0.3-6" n="10" date="2008-06-24T10:16:27.312+02:00">
    - <message>
    - <![CDATA[ Reply to partner "client".
      ]]>
    </message>
    - <details>
    - <![CDATA[
    <outputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload"><BPELProcess3ProcessResponse xmlns="http://xmlns.oracle.com/BPELProcess3"/>
    </part></outputVariable>
      ]]>
    </details>
    </event>
    - <event sid="BpSeq0.3" cat="1" type="2" n="11" date="2008-06-24T10:16:27.312+02:00">
    - <message>
    - <![CDATA[ _cl_
      ]]>
    </message>
    </event>
    - <event sid="BpPrc0.1" cat="1" type="2" n="12" date="2008-06-24T10:16:27.312+02:00">
    - <message>
    - <![CDATA[ _cl_
      ]]>
    </message>
    </event>
    - <event sid="BpPrc0.1" cat="2" type="2" n="13" date="2008-06-24T10:16:27.328+02:00">
    - <message>
    - <![CDATA[ BPEL process instance "150001" completed
      ]]>
    </message>
    </event>
    </audit-trail>
    The webservice-method I'm calling in this case is getStationsProperties.
    Kind regards
    Jørn Eirik

  • Best practice for lazy-loading collection once but making sure it's there?

    I'm confused on the best practice to handle the 'setup' of a form, where I need a remote call to take place just once for the form, but I also need to make use of this collection for a combobox that will change when different rows in the datagrid or clicked. Easier if I just explain...
    You click on a row in a datagrid to edit an object (for this example let's say it's an "Employee")
    The form you go to needs to have a collection of "Department" objects loaded by a remote call. This collection of departments only should happen once, since it's not common for them to change. The collection of departments is used to populate a form combobox.
    You need to figure out which department of the comboBox is the selectedIndex by iterating over the departments and finding the one that matches the employee.department.id
    Individually, I know how I can do each of the above, but due to the asynch nature of Flex, I'm having trouble setting up things. Here are some issues...
    My initial thought was just put the loading of the departments in an init() method on the employeeForm which would load as creationComplete() event on the form. Then, on the grid component page when the event handler for clicking on a row was fired, I call a setup() method on my employeeForm which will figure out which selectedIndex to set on the combobox by looking at the departments.
    The problem is the resultHandler for the departments load might not have returned (so the departments might not be there when 'setUp' is called), yet I can't put my business logic to determine the correct combobox in the departmentResultHandler since that would mean I'd always have to fire the call to the remote server object every time which I don't want.
    I have to be missing a simple best practice? Suggestions welcome.

    Hi there rickcr
    This is pretty rough and you'll need to do some tidying up but have a look below.
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Script>
            <![CDATA[
                import mx.controls.Alert;
                import mx.collections.ArrayCollection;
                private var comboData:ArrayCollection;
                private function setUp():void {
                    if (comboData) {
                        Alert.show('Data Is Present')
                        populateForm()
                    } else {
                        Alert.show('Data Not')
                        getData();
                private function getData():void {
                    comboData = new ArrayCollection();
                    // On the result of this call the setUp again
                private function populateForm():void {
                    // populate your form
            ]]>
        </mx:Script>
        <mx:TabNavigator left="50" right="638" top="50" bottom="413" minWidth="500" minHeight="500">
            <mx:Canvas label="Tab 1" width="100%" height="100%">
            </mx:Canvas>
            <mx:Canvas label="Tab 2" width="100%" height="100%" show="setUp()">
            </mx:Canvas>
        </mx:TabNavigator>
    </mx:Application>
    I think this example is kind of showing what you want.  When you first click tab 2 there is no data.  When you click tab 2 again there is. The data for your combo is going to be stored in comboData.  When the component first gets created the comboData is not instansiated, just decalred.  This allows you to say
    if (comboData)
    This means if the variable has your data in it you can populate the form.  At first it doesn't so on the else condition you can call your data, and then on the result of your data coming back you can say
    comboData = new ArrayCollection(), put the data in it and recall the setUp procedure again.  This time comboData is populayed and exists so it will run the populate form method and you can decide which selected Item to set.
    If this is on a bigger scale you'll want to look into creating a proper manager class to handle this, but this demo simple shows you can test to see if the data is tthere.
    Hope it helps and gives you some ideas.
    Andrew

Maybe you are looking for