Nathan Russell

Ranch Hand
+ Follow
since Aug 18, 2004
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 Nathan Russell

Thanks Mark,

To me someone who asks you What the footprint just doesn't want to use something and tries to ask a vague question so that you can never answer them and they can say, then therefore we can't use it.



Spot on; I think thats exactly why they have asked the question. There is some resistance about us changing anything at the moment, and it feels to me like this is a deliberately un-answerable question so that they can say not knowing the impact of the change is too risky and therefore a reason not to do it

Hey-ho!

Nathan
11 years ago
I'll start off by apologising for what on the surface appears to be a stupid question!

Does anyone know the memory & session footprint of a Spring MVC app?

OK, so there it is, thats the stupid question out of the way; and I know the answer is "How do we know, we haven't seen your app" and "profile it"


OK, so here's the full scenario:

We have an existing web app using a Java framework (not Spring). Part of this web app shouldn't really be there are its not part of the original business domain. The kind of thing that gets 'evolved' into an app over time
We have an opportunity to refactor this component out of the main app into a web app in its own right, and are also looking to use it as an opportunity to start using Spring MVC as our standard framework.

We have been trying to present this idea to the 'solutions architecture team' (yeah, I know ! ) because they caught wind of our plans to use a new technology! and one of the things they've asked is "what will the footprint of a Spring MVC app be?"

As we are only at the drawing board at the moment, we've not developed the app yet, so I cant profile it.
Does anyone know of any stats, benchmarks, or anything else I can quote?

The only other thing I could do is that I have a mostly developed proof of concept Spring MVC app. I could profile that, but its a completely different problem domain that its trying to solve, so I'm wondering what value it might have?

Any thoughts anyone?

Cheers

Nathan
11 years ago
I've kind of fixed this by writing a property editor for int instead of XMLGregorianCalendar:
So, in my controller I do this:

(didn't know you could do int.class - I thought it was a primitive )
And then my property editor looks like this:

This works, but I'm not entirely sure I like it as now all int fields on this page will be using this property editor.
Would be interested to know how anyone else might go about solving this one?

Cheers

Nathan
12 years ago
Hi,
I wonder if anyone can help.
I am putting together a Spring MVC 2.5 app, based around a form backing object which I have no control over (its based on an already established schema)
For the most part this is coming together nicely, but I am now stuck with how to populate a couple of properties. Within the main form backing object (which represents an insurance quote), there is a property for a previous claim. Within this there is a property representing the claim date. This property is a javax.xml.datatype.XMLGregorianCalendar which in turn has int properties for day, month, year etc. I guess it looks something like this:

Within my view JSP I have a couple of html SELECT drop down fields to allow the user to specify the claim month and year. Here is what I do with year (but month is the same):

The list ${claimYears} has id's (ie. the value that is submitted back) of 2006, 2007, 2008, 2009 and 2010

The problem comes when the user does not fill out a claim month and year (they dont have to, they are not required fields). Because of my "Please choose" option, an empty string value is submitted, which spring tries to bind to an int.

This much I understand, and I also think I understand that I need to write a PropertyEditor. I've written this:

which I think will do the job (ie. only attempt to bind if the value is not null and not an empty string); and I've tried to configure it into my controller like this:

but I think this is where its wrong and I'm getting stuck. When the view is requested via a GET (ie. before I attempt to POST it back), I now get this exception:


My gut feel is that its something to do with the way I am registering my custom property editor, in that I am registering it for XMLGregorianCalendar but actually it should be for the int (primitive type) within XMLGregorianCalendar

Or am I barking up the wrong tree??

Any help with this very very much appreciated;
Cheers

Nathan
12 years ago
Hi,
I wonder if anyone can help. With MVC 2.5 I am using some basic validation for my form fields. Each field in the BindingResult may or may not have validation error(s); and these are being displayed properly in my view (jsp) because they are exposed in the errors object when I use spring:bind. IE. I am successfully doing:


No problem. But what I'd now like to do (in addition to the above) is to have a summary of errors (of all fields) at the top of the page. Something like "You have 5 errors, please correct them before proceeding"
Does anyknow know if there is a 'page' level binding that exposes an errors object for all fields on the page? Or something similar?
Or will I have to maintain a counter in my validation code and add that to the model?

Cheers

Nathan
12 years ago
OK, I've found a solution:

First off, I was referring to the wrong interface and class - what I was after was the MessageSource. By making my class implement MessageSourceAware and implementing the setMessageSource method, the MessageSource gets injected. From there its a simple task of calling its getMessage method when I need some message text

Then in my jsp I do this:





12 years ago
Hi,
I'm trying to write an annotation based controller, and within one of its request methods I want to retrieve some text from within my messages resource bundle.
I can see from the Javadocs etc that some of the standard Spring controllers (BaseCommandController for example) have a method getMessageCodesResolver(), and from the returned implementation of MessageCodesResolver I can call one of the resolveMessageCodes methods ..... but I'm not extending any of the standard Spring controllers so I cant do this (can I?)

Below is my basic controller code and the method in question - any ideas as to how I can make the MessageCodesResolver available within my controller?


PS. The above is an over-simplified example of what I want to do. Clearly if all I wanted to do was the above I could write <spring:messages code="helpContent" /> within my JSP. In reality there are a number of help messages defined in the message file, and the controller will get the right one dependant on some other factors and add it to the model.

Cheers
Nathan
12 years ago
As before, thanks for your help Mark.
I wrote an implementation of org.springframework.web.servlet.HandlerExceptionResolver and in the method I wrote
The redirect does exactly what I need - Perfect

Thanks once again,

Nathan
12 years ago
Mark,
Thank you so so much for this - I most definately owe you a beer for this
Its all coming together very nicely.

One further question though (hopefully it'll be my last!) - when a new session comes along and issues a GET to /AboutYourProperty.htm (ie. tries to start in the middle of the process) Spring throws 'org.springframework.web.HttpSessionRequiredException: Session attribute 'quote' required - not found in session'
Looking at the method this makes sense:
But is there a way of catching this nicely. My initial thought was that I'd do something like this:
But I think the exception is thrown before the method even runs.
Any ideas?

Cheers

Nathan
12 years ago
Thanks for your reply Mark.
I've just got to the chapters in the book to do with Web Flow and was initially thinking 'yes, this is what I need'. However, having had a play I've decided its probably not what I need on the grounds that a) the book is outdated and b) it looks flippin' complicated !

OK, so going back to your original suggestion (using annotation driven controllers to define methods to handle the submit from each page), could you elaborate a little on that please? The book doesn't describe using annotations in controllers (and yes, I am using Spring 2.5 or higher - 2.5.6 SEC02 to be precise )
Roughly how would you go about setting up a project like mine? (3 pages where an object is passed between the pages and progressively populated with the data from each page). I'm imagining something like this:

web.xml
spring-servlet.xml
But I cant picture how I would instantiate my Quote object once and pass it into each controller??
I'm also a bit confused with some of the terminology (which probably explains why I'm finding this so hard!) Is my POJO (my Quote object) my domain object? or my command object? or a bean? And where do services fit into this? - I imagine that I need to write some business logic methods somewhere, at a minimum I would need a doQuoteCalculation() (but extending the app into something more useful I would need doPostcodeLookup(), soSaveQuote() etc etc)

Any pointers you can offer would be very very much appreciated;
Best regards

Nathan

12 years ago
Hi,
A bit of a newbie question I'm afraid, which I wonder if anyone can help with.
I'm a complete newbie to Spring, and am tring to get to grips with Spring MVC. I've been reading 'Expert Spring MVC and Web Flow', but to be honest its serving to confuse more than educate
I've put together the basic airline flight booking app in Chapter 4. Whilst its a bit better than a HelloWorld app, it still leaves me with unanswered questions, so I'm trying to put together something a bit more substantial.

The app I want to put together is a simple home insurance quote application. I have my domain classes already defined as a series of POJOs, and I want to present 3 screens - About You, About Your Home and Your Quote where fields on the screens are properties of the various POJO classes.
My main domain class is Quote which has properties of type Proposer, Property, CoverOptions, Premium. Proposer has properties to describe the policy proposer, Property describes the property to insure, etc.

As I see it at the moment I need 3 SimpleFormController controllers - one for each of the screens; and that I need to create a new Quote object and pass it between screens as the controller progressively populates more of the properties within. And that I also need to ensure that if a new session starts midway through the process - perhaps on the About Your Property controller - this is detected and they are sent back to the beginning where a new Quote object can be created for them.

My current thoughts are that I actually need 4 controllers - Init, About You, About Your Property and Your Quote; and the Quote object will be stored within the http session. In the constructor of About You, About Your Property and Your Quote I need to get the Quote object from the session. If it does not exist I need to issue a redirect: prefix to the Init controller whose contrstructor will create and store in the session a new Quote object and then issue a redirect: to the About You controller.

But this does not sound very 'DI' - especially the creation of the Quote object.

Any pointers to help clear up my understanding would be very much appreciated;

Cheers

Nathan


12 years ago
Hi,
A bit of a newbie question I'm afraid

I have a web application built using a proprietary framework (sorry, I cant tell you which one, but it is essentially driven by a single servlet defined in web.xml). Anyway, there is a desire to migrate the application away to Spring 3 MVC. Such a migration would be a gradual move, rather than a 'big bang' replacement.

With this in mind I have already done some proof of concept work and have successfully replaced some of the application's business logic with Spring 3 beans and IoC classes (is that the right terminology?). To do this I put the following in my web.xml

so that my bean classes could access the http session and from there get the values from the submitted form that the proprietary framework stores. Anyway, business logic successfully replaced and working, so thats a good thing.

The next thing I'd like to be able to do is to define all of my messages (field labels etc) as Spring managed messages in messages.properties. I can find lots of reference on the web about how to do this when using the Spring DispatcherServlet, but I still need my frameworks servlet doing the work at the moment. What I'm imagining is something like some other Spring servlet or filter which just loads the message bundle. From that I'll then see how I can 'hack' the current framework to use the messages (current thoughts are something like ognl like you can with struts)

The idea of course is that little by little I replace bits of the proprietary framework with standard Spring implementations, with the view that eventually the whole lot gets replaced

Anyway, the current challenge is just to get the message bundle loaded without handing the whole request/response mechanism over to Spring.

Any ideas? (or am I barking up the wrong tree)

Cheers

Nathan

12 years ago
Thanks for your reply David, but no, ${parameters.value.day} does not work - I get the following stack trace:

but if I simply use ${parameters.value} it returns mypackage.Date@805af4

So, as I see it, my object is being stored in the parameters map under the key 'value', and it is being returned correctly. Its just that for some reason I cant work out how to invoke the getDay() method?

Back to google I think !

Cheers

Nathan
12 years ago
I wonder if anyone can help.
I'm trying to create a new struts2 tag to render and operate as a 3 field date control. IE. a single jsp tag which results in 3 html input controls nicely laid out. Ignoring the complications of individual field validations (eg: month field is Feb, day field cant be > 28 unless year field is a leap year in which case it can be 29!). Anyway, ignoring that ..... I'm struggling with populating the value attribute.

I have a class which I'll use to store dates - its basically a wrapper around java.util.Date (I might use GregorianCalandar instead) which has getters and setters for day, month and year. In my action class I have a member variable whose type is my Date class, and I have a getter and setter for the field dob which gets and sets this member variable:

I reference my tag like this:

And my ftl looks like this:

The bit I'm having a problem with is the value attribute of each of the fields (where in the code above I've written it as value="problem area!")
What I think I want to do is in the jsp pass an ognl reference to the action class's member variable:

This I guess calls the action class's getDob method which will return the Date object. So then within the ftl I would want to do something like this:


But I cant get this (or similar syntax) to work.
As usual, any pointers very much appreciated !

Cheers

Nathan

12 years ago
Thanks Frits, but I dont think the type attribute is what I want (I think it is for when you allow expressions as values for your custom attribute you can say what object type the expression return should be)

There is an interesting line in the page I originally posted - in the section Attribute Validation, the first line reads:

The documentation for a tag library should describe valid values for tag attributes. When a JSP page is translated, a JSP container will enforce any constraints contained in the TLD element for each attribute.


Does anyone know what documentation they refer to? The way I am reading this is that there are some documentation tags which I should include in my TLD which (amongst other things) can describe the valid option values for an attribute?

Cheers

Nathan
12 years ago
JSP