Tuesday, April 29, 2008

Ruby Ajax.Autocompleter with callback


To implement dynamic autocomplete with additional parameter


1. Include


                <%= javascript_include_tag :defaults%>
                    <script src="/include/prototype.js" type="text/javascript"></script>
                        <script src="/include/scriptaculous.js" type="text/javascript"></script>

     prototype.js & scriptaculous.js are available on http://wiki.script.aculo.us/


2.
        <input type="text" id="autocomplete" name="attribute_lookup"/>
        <div class="autocomplete" id="attribute_lookup_auto_complete"></div>
        <%= javascript_tag("new Ajax.Autocompleter('autocomplete', 'attribute_lookup_auto_complete','/server/url', { fullSearch: true, frequency: 0, minChars: 1, callback: eventDateCallback});")%>


3.


Write javascript to handle callback

<SCRIPT language=javascript>

function eventDateCallback(element, entry) {

return entry + "&additionalParam=" + document.myForm.additionalparam.value;
}

</SCRIPT>


4. 

Add autocomplete CSS

  div.autocomplete {
      position:absolute;
      width:250px;
      background-color:white;
      border:1px solid #888;
      margin:0px;
      padding:0px;
    }
    div.autocomplete ul {
      list-style-type:none;
      margin:0px;
      padding:0px;
    }
    div.autocomplete ul li.selected { background-color: #ffb;}
    div.autocomplete ul li {
      list-style-type:none;
      display:block;
      margin:0;
      padding:2px;
      height:32px;
      cursor:pointer;
    }


5.

Add method in controller which returns array of string

6.

Implement view for returned items. Return list should looks like e.g.

<ul>
   <li>Item1</li>
   <li>Item2</li>
</ul>



       

Saturday, April 26, 2008

Soccer day for 3 year old

Its hard to handle one kid in open ground but this coach is really handling bunch of little monkeys very easily.

Friday, April 25, 2008

Are you using FriendFeed ?

My FriendFeed address is http://friendfeed.com/jigneshshah

Send Attachment over SOAP - Passing files to WebService ( Steps for JDeveloper )

Pre-req: Create Workspace and a project inside that workspace with index.html

1. Write an implementation class with method which takes AttachmentPart as an input

public String processAttachment(int id,
AttachmentPart attachment) throws RemoteException {

try {


Object attachmentObj = attachment.getContent();

//Add code to process input attachment

} catch (Exception se) {
//Exception handling
}


return "Test";

}

2. Go to File->New->Business Tier->Web Services and select Java Web Services (J2EE 1.4 or 1.3 version) and click OK

3. Go to Next

4. Give "Web Service Name" e.g MyTestWebService

5. Select your implementation class

6. Click Next

7. Click Next

8. Click Next

9. Click Next

10. Select your method e.g processAttachment to expose as webservice.

11. Finish ( This will generate WSDL and all related classes )

12. Now go to your WebService in "System Navigator"

13. Right Click on WebService (MyTestWebService) and click on Generate WebService Proxy

14. Select "Run against a service deployed to an external server" radio button and click OK.

15. Run your project

16. Go to ....SoapHttpPortClient.java and add following method

public AttachmentPart getAttachmentPart() throws RemoteException {

AttachmentPart impl = null;
try {
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
//change file://c:\\a.txt to a file you want to attach
impl =
message.createAttachmentPart(new DataHandler(new URL("file:\\C:\\a.txt")));
// add attachment to message
message.addAttachmentPart(impl);

} catch (SOAPException ex) {
return null;
} catch (Exception ex) {
return null;
}
return impl;
}

and call that method from main(). It will look like

public static void main(String[] args) {
try {
MyTestWebServiceSoapHttpPortClient myPort =
new MyTestWebServiceSoapHttpPortClient();

myPort.processAttachment(0, myPort.getAttachmentPart());
// Add your own code here

} catch (Exception ex) {
ex.printStackTrace();
}
}

17. Run Your Client to test your webservice

Note: JDeveloper is generating .wsdl and ..Stub.java with port 8888. If your embedded oc4j is running on different port then you will have to modify .wsdl and ..Stub.java

Give a try. Good Luck!

Thursday, April 24, 2008

SLC Apt view


View Larger Map

My First job in the US was in Salt Lake City. I was staying in this apt. complex.

Deal with desi news sites

We All desi likes to read news very regularly. But sites like timesofindia.com and rediff.com are just a junk. Best way to deal with those popups is to install firefox

1. Go to http://www.mozilla.com/en-US/firefox/ and download
2. Download Adblock Plus https://addons.mozilla.org/en-US/firefox/addon/1865
3. Subscribe to any one adblock plus default list..

Hope that helps :)

Shril's Picture

Posted via email.

Testing : Fitnesse - Selenium

Read Anubhav's blog for fitnesse with selenium

http://anubhavas.blogspot.com/2008/03/jump-start-fitnesse-with-selenium.html

Many to Many relations in Ruby

http://jrhicks.net/Projects/rails/has_many_and_belongs_to_many.pdf explains how to handle many to many relations between two models.

But if you want to store more information into your relational table then you have to use has_many through..
http://wiki.rubyonrails.org/rails/pages/Beginner+Howto+on+has_many+:through

Maven Internal Repository Management

1. Setup Apache and change httpd.conf to point to .m2 repository location

2. To manage local repository - Download http://www.jfrog.org/sites/artifactory/latest/ and Deploy artifcatory on Tomcat

3. Modify user's setting.xml ( under .m2/repository..) to point to local repository rather than external repository

Anti Virus

If you don't wanna buy anti virus then best free one is

Go to http://www.free-av.com/en/download/index.html and download (Avira AntiVir Personal - FREE Antivirus)

I am using it for sometime and so far I am happy with it.

Maven With JDeveloper

By default Maven doesn't work with JDeveloper but there are few ways to make it work.

Steps

Follow http://www.oracle.com/technology/products/jdev/howtos/1013/maven/maven.html

1. Create Maven Project

2. Run

mvn org.apache.myfaces.trinidadbuild:maven-jdev-plugin:jdev

to generate .jpr file

3. Go to JDeveloper and create new workspace

4. Add maven project .jpr into workspace

5. If you have ejb in your project then go to project properties (right click on your project and select project properties)

6. Select EJB Module option and set ejb-jar.xml path

Startup Motivation Fuel.

http://www.foundersatwork.com/joel-spolksy.html
Livingston: What advice would you give to a programmer who's thinking about starting a company?

Spolsky: I've got a lot: [laughs] Don't do it. It's going to suck. You're going to hate it. Can I steal one from Paul? Don't start a company unless you can convince one other person to go along with you. If you don't have two people (or I would even say three) that you've convinced to devote their lives to doing this, it's just going to be a different thing. There are a lot of programmers that are very tentative about starting their own companies. There are a lot of working programmers doing something they hate, with some company that they hate, but they need money to pay the mortgage. So they figure, "I'll develop something in my spare time. I'll put in 1 hour every night and 2 hours on the weekends and I'll start selling it by downloads." And you say to them, "Who's your cofounder?" And they say, "My significant other—husband or wife. My cat." But because they never really take the leap and quit their job, they can give up their dream at any time. And 99.9 percent of them will actually give up their dream. If they take the leap, quit their job, go do it full-time—no matter how much it sucks—and convince one other person to do the same thing with them, they're going to have a much, much higher chance of actually getting somewhere. Because they either have to succeed or get a job. Sometimes "succeed" seems like the easier path than actually getting a job, which is depressing. So quit your day job. Have one other founder, at least. I'd say that's the minimum bar to getting anywhere.