How to capture an element in jQuery / Locating element in jQuery

Capturing an element of a web page means to get a reference to an element (or simply getting the element) so that actions may be performed over the element. Actions cover hiding / showing the element, removing it from the page, getting its value, getting its text, modifying its value / text etc. Examples of elements on a web page are text box, button, drop down, checkbox, radio button, span, div etc.

There are 4 ways to get an element in jQuery: (more…)

Continue Reading

How to soft delete a record in Hibernate or JPA / Soft deletion of Entities in Hibernate or JPA

Soft Delete !!! What the heck ?

Soft delete means that the record is not removed from the database table but a flag is set to a value which indicates that this record should not be fetched while fetching the records from this table. The flag shall be a value of a column in the table itself.

For example, there is a deleted column in a table which has a value of false for a record which is newly inserted in the table but when a record is deleted, it is not removed from the table but the value of deleted column for this record is set to true. Now when fetching records from the table, only those records should be fetched which have a false in deleted column. (more…)

Continue Reading

How to load property file in java / How to load property file inside a package in java / Various methods to load a property file in java

A typical java application uses some values which are not suitable to be given in code such as log generation path, output location, configuration file path, timeout values etc. Since these values vary from system to system and user to user, their values can not be pre-fixed. One user may want his logs to be generated in “myLogs” folder, another user may want the logs to be generated in “appLogs” folder. If given in code, they cannot be changed without developer intervention. Further, this change would require a re-build of code. (more…)

Continue Reading

How to send form data to Spring controller using ajax / How to Submit Form using ajax

There are scenarios where you want to silently post a form to server or submit a form without a page refresh. Typical example is a Facebook page where you comment on a post. When you comment, the page is not refreshed but the comment is saved somewhere on the server which means that a save request is sent without entire page submit.
This involves the use of ajax. As soon as we decide to use ajax, a question arises as to how we would send form data from jsp to server without page submit and there would be a big hassle involved in form data transmission. Well!!! After reading this post, you won’t feel the same. (more…)

Continue Reading

How to send form fields from jsp to server in Spring MVC / How to submit a form to Spring Controller

Suppose we have a jsp page which has a form whose data should be sent to the server. The form has fields which are directly related to the fields of an entity on the server. An entity is a simple java class which has some fields and their getter and setter methods.
Let’s say the entity is a User (which means we have a User class on the server and each field of the jsp form is linked to a field of User class. When we say linked, it simply means that the name attribute of the form element is the same as the name of the corresponding entity field. (more…)

Continue Reading

How to perform custom initialization of beans in Spring / How to call a method before bean creation in Spring / Callback methods in Spring Beans

There are scenarios where we want to take some actions before a bean is fully constructed and put into service such as

  • giving a specific name to the bean other than that given in the configuration,
  • setting the application context into a bean property,
  • making a log entry immediately after bean initialization etc.
  • (more…)

Continue Reading

How to override hashcode() and equals() method in java

hashcode() and equals() : Overview

hashcode() and equals() methods are defined in java.lang.Object class which is the super class of all classes in java and hence may be overridden in any class.

    • The signature of hashcode() method is public int hashCode() which means it should return an integer, and
    • The signature of equals() method looks like public boolean equals(Object obj) which means it returns a boolean value indicating whether the object which called it is equal to the object which is passed as an argument to it or not.

(more…)

Continue Reading

How to calculate next working day in java / How to increment date excluding weekend in java

It may happen that you need to add some days to a particular date and the resultant date is falling on either Saturday or Sunday. So you have to calculate the next working date.

Practical Application : This is usually required in payments industry where the dates are written to files and these files are then uploaded to server but the server rejects the file if the date is a holiday. In such cases the date should be checked to be a holiday before writing it to file and incremented to a working day and then written to the file so that it is not rejected. (more…)

Continue Reading
Close Menu