Friday 19 October 2012

AJAX Form Submit and jQuery Validation

Submitting a form using jQuery AJAX should be pretty straight forward by using click() on the submit button, then some $.ajax() call. Integrating jQuery validation to it is a little bit tricky. Normal form submit without AJAX seems to call valid() automatically when the button is clicked, but with AJAX, it did not seem to work for me. I had to call this manually for the validations to work by using:
if ($.("#myForm").valid()) {
    // do form submission AJAX call here
}

Wednesday 7 December 2011

CSS Only for Webkit

What? Why would you do that? Well, sometimes cross-browser issues can be a pain, and fixing an issue in one browser could mean causing issues in other browsers. This is the time when you should consider creating CSS only for a certain browser, in my case Chrome and Safari.

Here's what I've done (thanks to this blog):
@media screen and (-webkit-min-device-pixel-ratio:0) {
    #my_id .my_form_row.my_embed_label input[type=password] {
        float: left;
    }
}

It is basically a media query supported by CSS3, which says that for "screen" media type that supports webkit, use the CSS code within the bracket. I would only use this technique if you run out of options, since this is kind of a hack for webkit browsers only.

Thursday 10 November 2011

Set Default Parameters in JavaScript using jQuery

When you create a JavaScript function with multiple parameters, it can get a little bit messy.

Consider this JavaScript function:
init_spinning : function(lines, length, width, radius, colour, speed, trail, shadow) {
  var opts = {
    lines: lines,
    length: length,
    width: width==null? 5,
    radius: radius==null? 8
    etc..
  }
}

Usage example:
init_spinning(8, 4, null, null, '#20CNSE', 1.6, 30, false);

Yuck! Not only do you have to remember which ones are mandatory, but also this is error prone.

Using jQuery's $.extend() function, we could use:
init_spinning : function(options) {
  var opts = $.extend({
    lines: 8,
    length: 5,
    width: 7,
    radius: 7,
    color: '#26BCED',
    speed: 1.3,
    trail: 44,
    shadow: false
  }, options||{});
  etc..
}

Usage example:
init_spinning({
  length: 3,
  width: 3,
  radius: 3
});

Much better! In the above example, the function has default values for all the parameters, and you just assign the ones that you need!

Monday 3 October 2011

Hash Table

Here is a good lecture on Hash Table

Tuesday 20 September 2011

Web Services Questions

Here we go:

  • Explain web services architecture (publish-find-bind).
  • What are the types of web services?
  • What is SOAP? Name two types of SOAP web services used.
  • What are the two approaches to create SOAP web services?
  • What is WSDL? Why would you need it?
  • What is the difference between DOM and SAX in JAXP?
  • Would you say JAXB is the best for performance? If not what is?
  • What is contract first? Where do you start?
  • What options do you have for security in Web Services?
  • In RESTful Web Services, what is the difference between POST and PUT?
  • Can you use GET instead of PUT to perform an update?
  • Name different output format that REST supports.
  • How do you handle errors in RESTful web services? Describe the options, the advantages and disadvantages.

Sunday 18 September 2011

Hibernate Questions

Here we go:

  • What is ORM?
  • What are the main advantages of using Hibernate?
  • How do you configure Hibernate?
  • What causes LazyInitializationException? What steps do you need to prevent this from happening?
  • What is OpenSessionInView pattern in Hibernate and when would you want to use it?
  • What is SessionFactory? Is it thread safe?
  • What is a Session? Can you share session object between threads?
  • What is HQL?
  • Name 3 inheritance mapping strategy and describe the limitations of each.
  • What do you think of using hibernate's own connection pooling algorithm?
  • Name the core interfaces of Hibernate framework.
  • What is the difference between session.load() and session.get()
  • What is the difference between session.saveOrUpdate() and session.merge()
  • What is a detached object? What other instance states does Hibernate have?
  • When would you use inverse in Hibernate?
  • What is the difference between join and select fetch strategy?
  • What are the advantages of using Hibernate vs JDBC?
  • What are the main differences between Hibernate and EJB?

Core Spring Questions

Spring questions:

  • Describe the life cycle of a bean in Spring.
  • What is the difference between singleton and prototype bean? Give an example when you would want to use one or the other.
  • What are the advantages of using Spring?
  • What are the main features of Spring?
  • What is Dependency Injection/IOC?
  • What are the three types of dependency injection? Which ones do Spring support?
  • Name all the 7 modules of Spring and describe what they are.
  • What's Bean Factory? What's Application Context? Describe the differences and when would you want to use one or the other?
  • What is auto wiring? Name all five modes.
  • Name two ways of accessing Hibernate using Spring.
  • What is AOP?
  • What is Aspect?
  • What is JointPoint?
  • What is Advice? Name 5 type of Advice.
  • Why use declarative over programmatic transaction management?
  • What are the main differences between EJB CMT and Spring's declarative transaction management?
  • Does Spring's transaction management support transaction context over remote calls?
  • Describe the main differences between EJB and Spring.
Share |