views:

150

answers:

1

I am writing a spring 2.5 application and in my jsp I'm writing my own tags.

It's about a list of objects...when I change the number of rows that list shows(a combobox), I am doing a submit on my form returning back to the view(obviosly with the new number of rows returned).

When listing with my own tags I need to get the properties from my command object. I have access to the pageContext object but I can't figure where the command object is stored.

A: 

By default, the command object is stored under a "command" attribute (request or session scope depending on your configuration of the sessionForm property). You can change that by setting the commandName property on your controller and your command object will be included in the model under this name (and not the default "command").

Once in your tag code, you can use request.getAttribute("command") or, if sessionForm=true, session.getAttribute("command") to get access to your command object (assuming the default name "command"). If you changed the name of the command using the commandName property then use that instead of "command".

Usually you wouldn't care in what scope the command is, so having access to the pageContext object, you can do a pageContext.findAttribute("command") and that will look it up in all scopes.

dpb
Thanks for your reply! I have founded the command object, but now I'm facing another problem. Let's say I have a list of objects, first I display only 10 of them. When the user clicks on 'next' button it will show it the next 10 items(i make a submit on the form). My problem is that when it first enters on the controller I found the command object but on the second time(after submit-into the tags) it doesn't, I receive null. I solved the problem by putting on the request in the controller the command object, so that in the tags I allways find it after submits. Do you know another way?thanks