Daniel Näslund

+ Follow
since Jul 14, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daniel Näslund

If I have a malformed url I get a MalformedURLException when calling the constructor of java.net.URL. It would be cleaner if there was a method java.net.URL.isValid(). I haven't found one. Does anyone know of a good alternative? Right now I have my own method that encapsulates the exception throwing but perhaps there is an alternative?

David Newton wrote:That's *one* way to do it--is it the "right" way? Depends. I tend to cluster classes by application functionality, which is independent of the view technology.

Thanks for your answer. I can see the advantages in keeping everything associated with one application functionality together.

Another question, but still on the topic. I saw that you were proficient in Struts so maybe this can be generalized to any MVC framework: When using AJAX calls, how do you give feedback for illegal input, that is form:error and such? If it's a simple textbox it's easy but what about input in an complex datagrid for instance? Do you write your own tags for it or use the ones provided by the framework? Perhaps setting my own error attributes is an option, that is, not using the MVC framework for error handling at all. But it seems as a waste of time to reimplement something that already exists.

In short: Is there some general solution to the problem of validating complex AJAX widgets?
12 years ago
I want to write a web 2.0 app, get wealthy and live happily ever after. What stands in my way is some understanding of how to design the Spring controllers for use with my AJAX framework.

I have tried the simple DOJO decorations available through Spring JS (DatePicker and Textbox). They work well with and without Javascript enabled. But I want more! I want 'bread crumb trails', advanced datagrids, dynamic diagrams and such. Does Spring JS expand to more than just client-side validation? I haven't found any good documentation yet.

Perhaps Spring JS is not the right design choise either. I want to have clear separation between the different layers of the app and Spring JS is a glue that makes the view layer dependent of Spring. So I was thinking: I use DOJO and send XML or JSON to my controllers using the RESTful approach that is supported through Spring 3.0. But then I need some controllers that return XML or JSON and some that return views, i.e. JSP-pages. This can get a bit messy. I was thinking of using one package for controllers returning JSP pages and one for controllers returning XML or JSON. Is that the way to do it?
12 years ago

Adam Confino wrote:Hey Java Gurus!

I am trying to learn Spring MVC. I started with their online tutorial at http://static.springsource.org/docs/Spring-MVC-step-by-step/.

Unfortunately my friend told me that Spring's online stuff is very dated (i.e. it doesn't use annotations, etc.) and may be counter-productive to learn.

Does anyone know of a good online tutorial of Spring MVC that demonstrates current practices?

As always, thanks so very much.

p.s. If this topic should be posted elsewhere, please let me know.

Stefan Schmidt has written a good tutorial/example application using the 3.0 draft.

It demonstrates a lot of the new features.
12 years ago

Kengkaj Sathianpantarit wrote:You should have only UserRespository. User is an aggregate root.

Thank you for your quick feedback! That makes sense when I think about it. I'll go with a UserRepository.

12 years ago
I've started on a simple Spring Diary application that uses JPA and Hibernate for ORM.
I have a couple of models that depend on each other. For instance a User can have many Days which can have many Notes. So I created a service-class for each model. But when I want to create a Day I need access to the corresponding User object that must be set. I don't want to have multiple service classes injected in one controller. That feels bad somehow. Is it bad?

My question is basically: What is the best approach when designing service classes for Spring? Should I just put it all in one service class and persist or merge the User when I want to save my changes? That feels so wrong! I want every class to do one thing for ease of maintainability. One big bloated service class is harder to understand and maintain is my opinion. Should I have service classes that call other service classes? Should I start with the models or the use cases or is there some other approach?

I'm surprised that I can't find any examples on how to design this crucial part of the application.
12 years ago

Problem solved. The mappings worked again after I changed some links that didn't use the contextpath correctly. I must have misread the stack trace.

I'm trying to create a simple CRUD-application using Spring 3.0 and it's new RESTful features. But these two mappings conflict:

If I do a call like this...

I end up with this:

Any suggestions? I've tried changing the order of the methods but that does not help. What is the priority ordering of the @ReqestMapping values? I've tried searching but the docs for 3.0 are sparse so far.

12 years ago
I'm wondering if it's even necessary to allow constants. Joshua Bloch dont think so.

Use interfaces only to define types
12 years ago
Use the @Override notation. It saves time and prevents headaches!

There are many legal hashCodes. If you are looking for good performance than as few values as possible should cause collisions (end up with the same hash value.
12 years ago
I have this model:

and this method in my DAO

If I were to supply a Day object with a comment field set to null I would get a RollbackException. What to do? Handle, throw or stop before it reaches the persistence layer?

Throw a NullpointerException or IllegalArgumentException was my first thought but perhaps there is some smart way to use the RollbackException... The question is really, where should the validation take place?
I have used dbunit from my JUnit enviroment. No hazzle creating specific ant targets. I just put the jars in the lib-folder and created a base class for my tests that initialized the database with values from an xml-file.

The supplied link is a good starting point.

Unit testing database code