SyntaxHighlighter

Tuesday, July 25, 2006

Reusing JSTL tags

We're using jsp and tag libraries pretty heavily in the enterprise application at Jobster. I had a chance to rewrite the application front-end code a few months ago, and came away with an infrastructure and architecture that is pretty nice for reusing components and 'widgets' on the front end.

For example, the list of jobs, and the list of prospects might have many similarities in HTML and CSS. Having these two pages use the same tag to render the parts that are similar is a win - reducing code, making it easier to maintain and update.

In our case, we have many lists (recruiters, prospects, contacts, employees, jobs, sources, messages to name a few) that have similarities.

I ended up with a mini-MVC architecture in the tag libraries. Where some tags took on Model properties, some took on Controller properties, and some acted more like Views.

The model type tags were needed to get the data in a very predictable consistent format. Lists of Maps was the preferred approach. If the data for one job list was slightly different than another job list, I used the model tags to convert and standardize. If I was handed a list of "Job" objects, I would convert to lists and maps.

The controller tags were application/use specific - they were used to combine the right data with the right view. For example, the recruiter list and the contact list are both lists of people, but they displayed different properties for each person in the list. The controller tag in this case accepts the data for the recruiter (a java.util.List object), calls the correct table row tag for each item in the list to generate the recruiter specific row, and passes these results to the view tag for final rendering.

The view tags are application agnostic. They accept strings and output them. This is a nice split, as the view tags can be reused easily. CSS becomes the only way to create different looks, the HTML is always consistent and predictable. There are view tags for the different parts of the page. Each is a wrapper that may include the results of another tag.

Most of my tags ended up being controller tags. Most of the changes occur in Layout tags. Code size reduced by 25%. Page weight reduced by 50%.

Once this infrastructure was in place, we were able to go through a complete redesign of 230 screens in the recruiter enterprise application - implementing a new brand in about 5 days (front-end coding). Most of modification occured in the wrapper view tags, and the CSS files. Past redesigns would take significantly longer.

2 comments:

  1. Nice work, Mark. I am impressed.

    ReplyDelete
    Replies


    1. - Ha ha ha ha.

      Tất cả người của Thanh Long bang đều cười lên ha hả, phảng phất như nt muốn tìm đến mình vậy.

      - A.... đồng tâm
      game mu
      cho thuê phòng trọ
      cho thuê phòng trọ
      nhac san cuc manh
      tư vấn pháp luật qua điện thoại
      văn phòng luật
      số điện thoại tư vấn luật
      dịch vụ thành lập doanh nghiệpa

      Ngay đúng lúc người của Thanh Long bang tươi cười, thân ảnh của Nhạc Thành biến mất ngay tại chỗ, sau đó lập tức tam tinh đấu vương bay lên trên không, cuối cùng hung hăng ngã xuống mặt đất không thể nhúc nhích, trên mặt đất chảy ra một vết máu.

      - Có chuyện như vậy sao.

      Tất cả mọi người khôi phục lại tinh thần, nhìn thấy Kiều Thập Tam ở trên mặt đất, vô cùng kinh ngạc nhìn Nhạc Thành.

      Tô Hân Nhi và Đỗ Mật Nhi nhìn Nhạc Thành nghi hoặc, vô cùng kinh ngạc, một chiêu vừa rồi đã đánh nhị tinh Đấu vương không biết là sống hay chết, loại thực lực này thật là hung hãn.

      Delete