This discussion is archived
7 Replies Latest reply: Dec 12, 2012 1:51 AM by TPD-Opitz-Consulting-com RSS

geting first selected value when passing values

adf009 Explorer
Currently Being Moderated
hi am passing value from one method to another when i pass value to another method am geting only first selected value

am geting value from this method

my problem is am only geting first selected users and the rest is not been passed,i can select 3 users but only the first user i select is been passed

Edited by: adf0994 on 2012/12/11 5:08 PM

Edited by: adf0994 on 2012/12/11 5:25 PM

Edited by: adf0994 on 2012/12/11 5:25 PM

Edited by: adf0994 on 2012/12/11 5:44 PM

Edited by: adf0994 on 2012/12/14 11:25 AM
  • 1. Re: geting first selected value passed
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    adf0994 wrote:
    my problem is am only geting first selected users and the rest is not been passed,i can select 3 users but only the first user i select is been passed
    To me it looks you're getteng the last one since you return <tt>usrw</tt> rather than <tt>co</tt>.
    Move the declaration of <tt>usrw</tt> to the place where it gets assigned its value. Then you cannot return it (wrongly) at the end...

    bye
    TPD
  • 2. Re: geting first selected value passed
    adf009 Explorer
    Currently Being Moderated
    i put it inside my for loop
      String usrw = (String)r.getAttribute("name");
    but is not able to be recognise when i do the
    return usrw

    I even decalre global but still not able to recive all pass values

    Edited by: adf0994 on 2012/12/11 5:43 PM
  • 3. Re: geting first selected value passed
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    adf0994 wrote:
    i put it inside my for loop
    String usrw = (String)r.getAttribute("name");
    but is not able to be recognise when i do the
    return usrw
    Yes, because you don't want to return the intermediate variable <tt>usrw</tt> holding a single user name. You want to return the collection of all user names stored in <tt>co</tt>.
    I even decalre global but still not able to recive all pass values
    Don't try random solutions! Understand the problem!

    bye
    TPD
  • 4. Re: geting first selected value passed
    adf009 Explorer
    Currently Being Moderated
    i
    but am geting Error(606,16): incompatible types,i what to pass the value as string as the reciving method is define as string,how can i return the collection of all user names stored in co.how can i return co arraylist and pass it as string

    Edited by: adf0994 on 2012/12/12 9:47 AM

    Edited by: adf0994 on 2012/12/12 9:57 AM

    Edited by: adf0994 on 2012/12/12 9:59 AM

    Edited by: adf0994 on 2012/12/14 11:25 AM
  • 5. Re: geting first selected value passed
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    adf0994 wrote:
    am trying to use this but with no luck, i what to take arraylist define method and pass it to string define mathod,but first what to convert it to string
    String asString = ArrayList.toString(orgDetails.getusername());
    This is the wrong way. Createing a String from the list just to satisfy the methods interface is not a good idea.
    but am geting Error(606,16): incompatible types,i what to pass the value as string as the reciving method is define as string,how can i return the collection of all user names stored in co.how
    Simply change the methods signature to return your collection type
    public String getusername()
    // should be changed to
    public List<String> getusernames() 
    And yes, after this change your entire code will not be compilabe yet. You have to change all places calling <tt>getusername()</tt> to handle the output as a <tt>List</tt>.

    bye
    TPD
  • 6. Re: geting first selected value passed
    adf009 Explorer
    Currently Being Moderated
    You have to change all places calling getusername() to handle the output as a List.

    but my method is define as string i cannot just change it to list as is been used in diffirent class for diffirent purpose
  • 7. Re: geting first selected value passed
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    adf0994 wrote:
    You have to change all places calling getusername() to handle the output as a List.

    but my method is define as string i cannot just change it to list as is been used in diffirent class for diffirent purpose
    Looks like you have a design flaw.
    When I'd see the method <tt>getusername()</tt> I'd expect it to return a single users name as a string (as it does at the beginning).
    If I get you right you're currently expending it to return a string containing several userids.
    I would not do this.
    If you need a list of usernames you should create a new method with an appropriate name eg: <tt>List<String> getUsernames()</tt>.
    Also you should define for yourself how to uniquely identify the username queried in your current implementation. In your OP you return the a random username that happens to be the last returnd by the query.

    bye
    TPD

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points