This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java ArrayList into Name value pair Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java ArrayList into Name value pair" Watch "Java ArrayList into Name value pair" New topic
Author

Java ArrayList into Name value pair

sangram nani
Greenhorn

Joined: Nov 27, 2011
Posts: 21
In a java class, am using an arraylist say reports containing list of all the reports which have reportid, reportname, reporttype etc which i want to add into NameValuePair and send a Http postmethod call to a particular url.

I want to add the arraylists - reportname into name value pair(org.apache.commons.httpclient.NameValuePair) and then use the http client post method to submit the name value pair data to a particular url.

Here is my name value pair






please suggest me how to add the reports arraylist reportname into reports field of NameValuePair.

--
thanks
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7716
    
  20

sangram nani wrote:please suggest me how to add the reports arraylist reportname into reports field of NameValuePair.

It strikes me that what you do is likely to be dictated by what the target of your HttpPost expects. Do you know that?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
sangram nani
Greenhorn

Joined: Nov 27, 2011
Posts: 21
Winston Gutkowski wrote:
sangram nani wrote:please suggest me how to add the reports arraylist reportname into reports field of NameValuePair.

It strikes me that what you do is likely to be dictated by what the target of your HttpPost expects. Do you know that?

Winston



i will be using this name value pair to call a http postmethod to a salesforce URL so that the details of name value pair are stored in the salesforce site as a lead.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7716
    
  20

sangram nani wrote:i will be using this name value pair to call a http postmethod to a salesforce URL so that the details of name value pair are stored in the salesforce site as a lead.

Yes, but what does that salesforce URL expect? Because that will govern what you put into your NameValuePair instance(s).

Winston
sangram nani
Greenhorn

Joined: Nov 27, 2011
Posts: 21
Winston Gutkowski wrote:
sangram nani wrote:i will be using this name value pair to call a http postmethod to a salesforce URL so that the details of name value pair are stored in the salesforce site as a lead.

Yes, but what does that salesforce URL expect? Because that will govern what you put into your NameValuePair instance(s).

Winston



Here is the code am using to send the data to sales force url along with the salesforce access credentials in the data variable. The sales force url has servlet namespace,.

for (NameValuePair nameValuePair : Data) {
postData[count] = nameValuePair;
count++;
}
post.setRequestBody(postData);
BufferedReader in = null;
try {
int returnCode = client.executeMethod(post);
in = new BufferedReader(new InputStreamReader(
post.getResponseBodyAsStream()));

String inputLine;


while ((inputLine = in.readLine()) != null) {


response+=inputLine;
System.out.println(inputLine);
}
in.close();
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7716
    
  20

sangram nani wrote:Here is the code am using to send the data to sales force url along with the salesforce access credentials in the data variable. The sales force url has servlet namespace,

I don't think you quite understand. You asked how to convert an ArrayList of reports to name/value pairs; what you have given me is the code to put those pairs into a request.

The question you need to answer is: what does your URL expect?
Is it it the name "report", followed by a comma-delimited list of report names as the value? Or is it a whole slew of NameValuePair objects of the form:
reportname=report1
reportid=1
reporttype=big
reportname=report2
reportid=2

...
The answer will determine what you need to do, but only you can answer that question.

Winston

Having thought about it, another option might be:
reportnames=report1,report2,...
reportids=1,2,...
reporttypes=big,small,...

but you still have to know what it is.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java ArrayList into Name value pair