free web page hit counter
Friday Nov 11, 2005

Code Google Search in no time using Creator 2.

Java Studio Creator is bundled with a very powerful data handling layer between the components and the underlying data. Data Provider allows the users to access data in a consistent way, even though the data may come from different sources such as Database, EJB or a Web Service. In this blog I want to show how to use Data Provider to connect to Google Search Web Service to fetch data and display it in a table with proper link to web sites. Every thing is done graphically except for 2 line of code user needs to write in the Java file. Yes, just 2 line - it is not a typo!

This is what you need to do after creating a creating a project in Creator 2. Lets call the project GoogleSearch.

Adding components

  • Add a Text Field
  • Add a button  (text - Google Search)
  • Add a Table component

Adding Web Service

  • Drag and Drop
        Servers -> Web Services -> samples -> GoogleSearch -> doGoogleSearch
        (This adds W/S client googleSearchClient1 & MethodResultTableDataProvider
          googleSearchDoGoogleSearch1)
  • Select googleSearchDoGoogleSearch1 in the out line and modify in the property sheet
          key - <your Google search key>  (Note: You need to register and get a
                    key at http://www.google.com/apis)
          maxResults = 10
          q - Sun Java Studio Creator (Initial search, you can change it
          later in the text field)

Adding Data Provider

  • Drag and Drop an Object Array Data Provider. (id - resultArrayDataProvider) 
  • Add an indexed property called "resultArray" of type webservice.googlesearchservice.ResultElement[]
  • Select resultArrayDataProvider and set its array property to "resultArray"

Setting Data Provider to Table

  • Right click on table and select Table layout and then select Data Provider resultArrayDataProvider
  • Remove all columns except URL, snippet, summary and title
  • Select HyperLink for component type for the column URL
  • In the Outline Select tableColumn1 -> hyperlink and click [...] for the "url" property in the property sheet
  • Deselect "escapt" property of  tableColumn2 -> staticText1, tableColumn3 -> staticText2, tableColumn3 -> staticText2

Setting Text Field Value to googleSearchDoGoogleSearch1

  • Right click on TextField and  select property binding and set the binding to googleSearchDoGoogleSearch1
       (The text should be - Sun Java Studio Creator)

Setting the Search Result to resultArrayDataProvider

  • Double click on "Google Search" button and add code
 resultArray = (ResultElement[]) ((GoogleSearchResult) getGoogleSearchDoGoogleSearch1()
               .getResultObject()).getResultElements();
 resultArrayDataProvider.setArray(resultArray);

Deploy and see the result after clicking on the "Google Search" button.

Google Search result output

Note: Our document team is in the process of writing a more elaborate tutorial on this subject. Stay tuned

Comments:

Hi, can you explain in detail the step Adding Data Provider. I am sorry to ask for this but I tried with no luck :( I drag and drop the objectArrayDataProvider, and created the the indexed property results of the correct type. when select the objectArrayDataProvider, on properties, I cannot select the "results" , actually I cannot select anything, the list for Array is empty. can you help? thanks

Posted by Pedro Farinha on December 15, 2005 at 10:27 PM PST #

"Add an indexed property called "resultArray" of type webservice.googlesearchservice.ResultElement[]" To which Bean in outline? The RequestBean1? The SessionBean1? Or the ApplicationBean1? Please be a little more specific when stating adding anything to which or what component. As many of us do not like venturing into the guessing game or psychic business when it comes to software dev. And as a scientist you should always try to be as explicitly precise as possible. Other than that thanks for a great tutorial, nmatrix9

Posted by nmatrix9 on July 18, 2006 at 12:13 PM PDT #

"I drag and drop the objectArrayDataProvider, and created the the indexed property results of the correct type. when select the objectArrayDataProvider, on properties, I cannot select the "results" , actually I cannot select anything, the list for Array is empty. can you help? thanks" Pedro Farinha Iam having the exact same problem. after I add the ObjectArrayDataProvider and then try to add a indexed property "resultArray" as a selected array of the ObjectArrayDataProvider (resultsArrayDataProvider) I get no selection at all. Is this a bug?

Posted by nmatrix9 on July 18, 2006 at 12:51 PM PDT #

Try to add the resultArray as a "property" not as an "indexed property". It should work.

Posted by Daniel Paranhos on October 23, 2006 at 01:36 PM PDT #

Hi, Winston:
What specific key should i get? The link you provided above is not clear what key should i get. I tried with, Ajax API key, data APi key, etc, all reported (with goolesearch examples for SJSC2) invalid key.
any idea?

thanks

Posted by john on October 10, 2008 at 07:56 AM PDT #

http://www.batteryfast.co.uk/hp/nx8200.htm hp nx8200 battery,
http://www.batteryfast.co.uk/hp/nc8430.htm hp nc8430 battery,
http://www.batteryfast.co.uk/hp/pb992a.htm hp pb992a battery,

Posted by laptop batteries on October 24, 2008 at 12:27 AM PDT #

I bought http://www.shopgogo.ca/hp/nc8430.htm hp nc8430 battery , really great, if everyone has the time, then on the next to see Oh, can not miss this good chance!

Posted by annyhaiyan on February 19, 2009 at 11:46 PM PST #

If you want to know something about laptop betteries,you can see it from http://www.adapterlist.com/hp/nc8200.htm hp nc8200 battery ,It,s very cool.

Posted by laptop bettery on February 26, 2009 at 01:30 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed