Dev Cafe

Friday, April 09, 2010

'Extends' in Struts Validation.

In my last post I had over simplified what we as a team were doing. There were lot of constraints in implementation on such constraint was validation. Its well know among struts developers that Struts provides one of the robust and easily configurable validation framework.


Struts validation provides extension and override mechanism. Struts can inherent bunch of properties from any form and you can add additional form property validation. For example If we have form F1 and F2. And If both form F1 and F2 have property X,Y

<form name="/F1">
<field property="X" depends="required,maxlength,mask">
<arg key="Xmsg" position="0">
<arg name="maxlength" key="${var:maxlength}" resource="false" position="1">
<var>
<var-name>maxlength
<var-value>${92float}</var>
</var>


</field>

<field property="Y" depends="required,maxlength,mask">
<arg key="Ymsg" position="0">
<arg name="maxlength" key="${var:maxlength}" resource="false" position="1">
<var>
<var-name>maxlength
<var-value>${92float}</var>
</var>
</field>
</form>

To reuse the validation that is already available in form F1.

<form name="/F2" extends="F1">
</form>

So all the validation properties available in F1 is now available in F2 with extends keyword. Basically we are establishing a hierarchy here.

Now assume if we have a scenario were field X is not a required for form F2 but required to F1. Since we have a inheritance we can as well override Just the X property in F2 only

<form name="/F2" extends="F1">
<field property="X" depends="maxlength,mask">
<arg key="Xmsg" position="0">
<arg name="maxlength" key="${var:maxlength}" resource="false" position="1">
<var>
<var-name>maxlength
<var-value>${92float}</var>
</var>
</field>
</form>

So, struts provides extension mechanism at form level and override option at property level.

Labels:

Thursday, April 08, 2010

Java and HTML dont go together.

In the current project which I am working is an interesting one. We have one gigantic jsp page with close to 100 fields on a average. Out of the 100 fields, 60 of them are constant fields and rest being driven by 6 parameters. And each parameter has 4 possibilities so basically 4*(6!) combination.

So, we started out with creating components that can reused when the combination repeats. For the first couple of releases we had great success, we shrunk the development time; the page that used to take 3 days now took only 1 day or less. We implemented around 100 combination quickly.

After 3 or 4th release now we had a new business requirement that wanted a change... Oops... the business said that these never changes.... (Lesson learned:What ever we develop always changes.. Always have provision for change). Now we had to revisit the components which were assumed to be common are not common any more now.

We started the second iteration. this time around we pushed all the sturts controls in the jsp. We came up with only one taglibrary this time. We separated the Java Code and HTML. Each html component for example Telephone Number component (A label and 3 text field) is wrapped by this custom tag-library. The custom tag's main task is determine whether to doBody or skipBody. The custom tag now uses a Util class's static method which returns a boolean value. Based on the boolean value doBody or skipBody is invoked.

This way we have one generic solution, Adding or removing an existing control in the page is just a change in the xml file. So this enable to do maximum re-use of components and easy to maintain.

Labels:

Wednesday, December 13, 2006

Why not "super" in JavaScript?

Javascript is a scripting language which supports OO. I was supposed to develop a javascript framework in my project and I was using the prototype method for creating javascript classes. Oops, Not classes, create prototypes in Javascript. Prototype is the correct word to describe it. There isnt a straight forward provisioning in javascript to access the super class's method. Why is not "super" a keyword in javascript? Why cant there be an straight forward provisioning in Javascript to access the super prototype? I found this article useful on how to access the same, but still the "Why" is still unanswered.

Monday, October 02, 2006

AJAX too much Hype!
AJAX Asynchornous Javascript and XML. What is it? Google it, you will find a ton of material on it. Every major internet technology seem to embrace AJAX as if it is the next wave. Well the point is, the core of AJAX is the XMLHttpRequest which has been there for quite some time. But how come suddenly everyone is using or talking about it? Find a tutorial on the internet for the AJAX and you will find people will point example to google maps. There isnt much new its the same old technology in a new bottle. It is the application of the this technology to the most approriate place (Google maps) that has made this to be talk of the internet. So the exact use of technology at one place has made the industry turnback and follow it. So I would say Common Sense and application of technology is hype rather than the technology itself.

Tuesday, July 25, 2006

Few Interview Questions.

I just got a mail from one of the job consultant. Which contained a Job opening and a set of screening questions. This is the first of such kind I have got till date. In IT field, I know when people seeking job in thier friend or friend's friend organzations enquiring about the kind of questions and area of concenration for the current opening. But consultant listing out the list of screening questions, reminded me of one of Srini's blog " Trespassers will be recruited". Any way, the good thing in that mail was the questions. I thought I would post it with answers for them.

1. True or False - JSP can be precompiled into a jar file
Answer – True.

2. In a web application protected resources can be differentiated from unprotected ones at deploy time by
a. defining servlet mapping
b. setting security constraint
c. with use of filters
d. all of the above
e. none of the above
Answer – B – Check this URL for more information.

3. Servlet Filters are designed based on which J2EE pattern
a. Business Delegate
b. Front Controller
c. Intercepting Filter
d. Fits into all above patterns
Answer c. Intercepting filter

4. Use of persistence layer (such as Hibernate) is most appropriate betweena. Business delegate and data access objectb. Data access object and databasec. Can be used only directly with a databased. Can be used only instead of a database
Answer b. Data access object and database

5. Link table in a database schema is necessary to
a. resolve one to many relations
b. achieve 3rd normal form
c. resolve many to many
d. all of the above
Answer d. All of the above

6. Does garbage collector directly impact a heap or a stack?
Answer - Heap URL

7. Uncaught errors cause compile errors – True and False
Answer - False - Errors are caused at Runtime.

8. Which of these data structures does not extend collection interface
a. List
b. Map
c. Set
d. None of the above
Answer B.Map

9. These types of instance fields are not serialized
a. volatile
b. static
c. final
d. transient
Answer d.transient

New car or Old Car?
It was 3 months of thinking wether to buy a new car or a old car when at last I decided to buy the new car. When I first landed in US 8 months ago, I was thinking I wouldnt spend more than $ 10K for a car. I started to search cars in the internet that I would get for 10K or less. Most of them had 50k miles or more on them (I had decided to buy Camry When I drove Corolla. It may sound weird, but with the smoothness of corolla ensured that camry would be much more smoother ). When I asked one my friend who bought an old Lexus for $ 5k which had 90K miles on it. It was luring me to go in the same path. But he said, he had put $ 6k within a year to fix couple of issues. Wow! so he has already spent 11k on it. Calculating the resale value I figured out that buying new car would cost $ 3K more than old car under the assumption you wouldnt have any problems with your old one. By buying new car, you have peace of mind, since you have 3 year bumper to bumper warranty.

Monday, July 24, 2006


I am new to blogging so, I thought I would start blogging with my new car which I bought yesterday. Here is the new Car I bought Camry 2007.