Skip to main content

Posts

Showing posts from December, 2009

Using JavaScript to update content in UpdatePanel

One of my recent pages needed to have a client side JavaScript function to select all items in a given multi select box. An event was wired to fire (to submit and update UpdatePanel) when one of these items were selected. This was working fine when selection was done by the end user using a mouse/keyboard. However, when I used a JavaScript function to select all items, the event was not firing. I had to fire it myself which basically meant that I had to submit the form (asynchronously). Here is what I did in my JavaScript function that was selecting all the items in a given select box to submit the form to update the contents in UpdatePanel. function SelectAll(objectId, submit) {     if (objectId) {        var str = '#' + objectId + ' *' ;        $(str).attr( 'selected' , 'selected' );     }     if (submit) {      var prm = Sys.WebForms.PageRequestManager.getInstance();      prm._doPostBack(objectId, '' );     } } This function

Spring.NET exception handling through AOP

Spring has few custom handlers that help application developers with exception handling. Recently, on one of the projects I was working on I had a requirement where I was to log user exception, capture the exception detail, and email the exception details to a set up email address. The first thing I looked at was Spring.Net's ExceptionHandlerAdvice in Spring.Aspects.Exceptions namespace. You can use this predefined advice to handle your exceptions. You can take a look at chapter 14 of Spring.NET documentation to get more details about what this advice does for you. Looking at ExceptionHandlerAdvice, I knew that I had to set up the exceptionHandlers property. I used the following value to set this property. on exception (#e is T(System.Exception)) execute @(customExceptionHandlingAdvice).Handle(#e) The above value using Spring.NET SPeL (Expression Language). You can find out more about the Spring's expression language in the Spring.NET documentation. Exception handler

List of some cool and useful Open Source projects I use

Web is full of wonderful Open Source Projects. It gets sometimes difficult to find what you need and decision making process can be tough between different projects. Here is a small list of projects I worked with in the past that I thought I share: HtmlBox is a WYSIWYG editor built on top of jQuery. It has wonderful set of features, good documentation and is extremely easy to configure. You can find more about HtmlBox here . JMesa is a dynamic table component that allows you to sort, paginate, filter, edit your data. JMesa can also export your data into CSV, EXCEL and PDF. It is API is very easy to extend. It does have some Spring support. You can also use tags in your JSPs to build the table on the view site. You can use the API to fully build your tables in your controllers. Take a look at here to find out more about JMesa.

Asp.NET AJAX client reference

When working with AJAX in .NET environment you may need to at times control UI components at the client side through JavaScript. There are a lot of things you can accomplish on the client side using the provided JavaScript API. Here is a link to the Asp.NET AJAX Client Reference . I recently used AjaxToolKit in one of my applications. I made heavy use of Tabs . In one of my pages, I needed to make sure that users could not click on the second or the third tab without saving a form that was in the first tab. I needed some sort of a validation to enforce this. I handled this on the client side since JavaScript is required for the application. Tabs has an attribute called OnClientActiveTabChanged. This attributes allows you to set up a client side function that gets executed when a tab is clicked. Here is how this function looked in my example: function validateQuestionsAndAnswers(sender, args) { var tabIndex = sender.get_activeTabIndex(); switch(tabIndex) { case 1:

Using jQuery to handle confirmation of navigating away from HTML Forms in edit mode

On my recent project, I had a requirement that stated that I needed to warn the end users when they tried to navigate away from an HTML Form that they started editing. The warning message was to indicate that they were leaving and they forgot to hit the submit button. There are many ways for end users to navigate away from a given HTML Form. They could click a link within the application, they could close the browser, or type in a new URL. This solution focuses on clicking available links on the application they are on. For this solution I used jQuery. I am a big fan of jQuery and I use it whenever I can. The solution basically involves tracking user activity when they are working with an HTML Form. By tracking I mean to capture their actions when they click/focus on HTML form elements such as input, select, textarea, radio, and checkbox. Here is the code that handles all this: var somethingChanged = false; $(document).ready(function() { handleReady(); }); function handleReady() {

Using Spring AOP to create a quick/simple auditing mechanism

These days I have been working in .NET. The project I am on uses Spring.NET and NHibernate for data access. One of the requirements of the project was to capture user activity and log them. There are certainly many different approaches to achieve this goal. There are solutions that you could deploy to your database (triggers etc.) or create application level services that would capture and log user activity. Since the project was already utilizing Spring, I wanted to utilize Spring's AOP features. The first thing I did was to create two database tables that would hold audit data. The first table I called history_log and the second table I called history_log_param . The history_log table has the following columns. CREATE TABLE [dbo].[history_log]( [id] [int] IDENTITY(1,1) NOT NULL, [table_name] [varchar](50) NOT NULL, [method_name] [varchar](50) NOT NULL, [argument_count] [int] NOT NULL, [message] [varchar](500) NOT NULL, [user_name] [varchar](50) NOT NULL, [date] [datetime