开发者

Get command object

开发者 https://www.devze.com 2023-01-01 08:10 出处:网络
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 f

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消