Shawn Vader

Greenhorn
+ Follow
since Mar 31, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shawn Vader

Hi, Mudassir

Valentin is correct about splitting up your files, but dont go mad and have lots of xml files, it is as bad as having one big one.
To follow on there are some other ways of splitting your files,
If you are using spring mvc then in your web.xml you need to do what Valentin said to let the controling servlet know about all your xml files.


You can also use a form of xml inheritance.

<import resource="myOtherXmlFile.xml"/>

Hope this helps,
Shawn
http://www.whatjar.co.uk
Hi Lisa, I had the same problem on my site.

Basically when the page loads it will look for the property on the command object, so the property that you are binding to has to be in that command. Because that property is in the header and used by all pages you can safely say that it is part of each command so create a common command class with that property and extend it with each of your command classes.

The second problem is that of naming. If you give your command a name then you need to access it by its name

<spring:bind path="myCommand.propertyName">
if you don't you can access it using the default name
<spring:bind path="command.propertyName">

So don't name your command and let all your pages bind using the default name 'command'.

I hope this makes sense.

One other thing, in Spring 2 which is fully backward compatible you don't need to use the bind anymore, they have given you a heap of tags which make life a lot easier and reduce the amount of lines in your jsp code tremendously.

Eg, going by the above example:
<c:out value="${command.propertyName}"/> no binding needed.

Have a look:
http://static.springframework.org/spring/docs/2.0.x/reference/mvc.html#mvc-formtaglib

Hope this helps.

Shawn
http://www.whatjar.co.uk
Months and dates in Java can be quite tricky. My advice is to make sure you have the java docs or source code attached to your ide. Make a habit of looking at the API when deciding what classes and methods to use it is the fastest way of improving your code..
I have updated your example, I hope this helps.

String stringDate = "March,2007";

SimpleDateFormat fullMonthFormat = new SimpleDateFormat("MMMMM,yyyy");
//parse the date to create a date. Look at the api for Date
Date date = fullMonthFormat.parse(stringDate);

System.out.println(date.toString());
//you can pass a Locale if needed
Calendar cdr = new GregorianCalendar();
cdr.setTime(date);
// System.out.println("month is=====>"+cdr.MONTH);
//With this line all you are doing is printing the static variable from //Calendar
//public final static int MONTH = 2;
//It is convention to access static variables as Class.static variable and //not instance.varialbe
// Calendar.MONTH = ok cdr.MONTH = wrong..
int month = cdr.get(Calendar.MONTH);
System.out.println("month is=====>" + month);

int year = cdr.get(Calendar.YEAR);
System.out.println("year is=====>" + year);
16 years ago
To add my 2 cents to the debate, I work in Investment banking in the UK and we are mostly re-writing our enterprise applications to smaller light weight frameworks like Spring which have had such good success with over the last two years.

I would advise you to think about what industry you want to work in and find out what the trend in the industry is with regards to Enterprise/EJB. I would say do your SCJD and then start working (if you are not) and then decide on your SCBCD. The more the better but there is nothing like experience!

Shawn
[ April 08, 2007: Message edited by: Shawn Vader ]
Two things,
1) Your implementation of the singleton pattern although correct is not 100% guaranteed to produce one instance, there is a small chance that there could be more than one instance created. This version on the singleton is preferred.

public class Singleton {

public static final Singleton INSTANCE = new Singleton();
//private constructor
private Singleton() {
//do some construction
}

public Singleton getInstance() {
return INSTANCE;
}
}

//you can then access it by using
Singleton.INSTANCE;
or
Singleton.getInstance()
[/LIST]

Secondly if you wanted to serialize this class you would need to implement serialization, if you don't know much about serialization read this short article on Sun website
http://java.sun.com/developer/technicalArticles/Programming/serialization/
There is a lot more to serialization than people assume so make sure you fully understand serialization before just implementing. One example is the the virtual machine will add a public constructor to this singleton class!


If you correctly serialize this object the state of the object will be maintained so if you deserialize it the getInstance() would not call the constructor again.

Shawn
16 years ago
Another way of getting an accurate size is to Serialize the HashMap as it is Serializable and you say they contain Strings which are also serializable
and then look at the size OutputStream. I have found this to be the most accurate way of finding out the size of an object

Sun as a good article http://java.sun.com/developer/technicalArticles/Programming/serialization/

Or if you have the time Effective Java by Joshua Bloch has a fantastic chapter on Serialization http://java.sun.com/docs/books/effective/

Shawn
16 years ago
Is the webserver a hosted server or under your control? I know that if you are running on a hosted server which is using the myphpadmin then in your jdbc connection url the server name has to be localhost

i.e jdbc:mysql://localhost/your_database_name?autoReconnect=true

Shawn
When Bear checked my site my i18n properties were not resolving for his us locale. I am using spring mvc and was using the ResourceBundleMessageSource to load the locale properties but have changed it to use the ReloadableResourceBundleMessageSource.

Since I have to reboot this windows box to change the locale I would appreciate if anyone who has a locale other than gb can just see if the properties are loading for them.
the site is http://www.whatjar.co.uk if the title is not ???title then it has worked...

I need to find a way to unit test it

Thanks
Shawn
To update those that are interested. I have managed to resolve the problem of the div elements lining up sometimes and not others and especially in Firefox when the webserver is under load.
I took the advice or validating the html which I would recommend to anyone learning html as it gives you a clear indication of what is wrong and why.
The second thing I did was donwload the firefox developers tool bar which is amazing, it allows you to see all you div elements and the order in which they load. Form this I found out that I had a div in the wrong place and after that the site is fine...

Adios
Signing off for Easter..
Thanks for the advice, not sure why there were property lookup failures but that would cause the div to be out of line.
I think running it through a html validator is a good first step.


Thanks
Shawn
Hi, I am a server side developer trying my hand at some front end code.
I have this site that displays results in a table format using divs. My problem is that when I do a search sometimes the div elements are all screwed up but if I do a refresh they are fine. If the site is under load the screen also loads with some div elements not lined up or displaying on the next row, but again a refresh corrects the problem.
It is as if the screen paints before the style sheet has finished loading.
When I run locally on the same version as the hosted tomcat it works fine.

Any suggestions will be welcome.

If you want to see the error in action you can do a search on http:/www.whatjar.co.uk


Thanks in advance..
Shawn
As the previous post mentioned, Thinking in Java is a good start although I don't think it is necessary to start with edition 4. If you are in a hurry to get started edition 3 is free at http://www.mindview.net/Books/TIJ/ you can then order 4 at your convenience. Fourth edition has new java 1.5 features like generics which you dont need to get started.
Don't ignore all the online resources on Sun's site: Have a look at http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/compile.html

Hope this helps
Shawn
16 years ago
Environment variables and setting the classpath have a similar effect i.e. the compiler and the virtual machine (vm) look in these areas for classes that your code is referencing. When you are working in an ide like eclipse for example you add your third party libraries normally jar files to the libraries in the path settings tab. This has the same effect as adding them to your classpath. This is helpful but can be confusing when you want to run your application outside of your ide as you will have to set the classpath yourself. Tip: When you run you class in your idea the first line in the output window will be the execute command for the class you are running with the full �classpath so you can see the full classpath that the ide is using to execute your class.

Try to use environment settings as little as possible as they are specific to the machine that you are running on. If you get ClassNotFoundExceptions for code you have not written it means that some classes can�t be found in the classpath or the environment variables. You will have to find the jars and download them and add them to your classpath, if you are in an idea this will be to the libraries tab. If you don�t know what jars the classes are in you can get an idea using some of the jar search sites like jarhoo.com costs or a free one http://www.whatjar.co.uk where you search on the missing class and they tell you what jar file the class is in.

Hope this helps in some way:
16 years ago