RE: RequestHeaderAware in Struts 2?

2010-10-27 Thread Jose Luis Martinez Avial
Well, that's an option. Another thing I would need to get is the Remote Address. That can be complicated, since sometimes -specially when you are behind a proxy, or something like that- the IP address you get is not correct. In those cases with a proxy usually the IP is in a header in the reques

Re: RequestHeaderAware in Struts 2?

2010-10-27 Thread Dave Newton
What's wrong with the ideas you've been given? Ying's is exactly what you asked for, Chris's might be more suitable if you want to set one or two action properties based on one or two header values. Another thing to consider is how the values will actually be used: the application-specific "contex

Re: RequestHeaderAware in Struts 2?

2010-10-27 Thread Li Ying
I would implement this function as a Utility Class, and call it from the Action class. In the Utility Class you can get the HttpServletRequest instance by [ServletActionContext.getRequest()]. In this case, you even don't need RequestHeaderInterceptor to inject Headers into your action, because th

Re: RequestHeaderAware in Struts 2?

2010-10-27 Thread Dave Newton
Setting the value into the action is both cleaner, and more expressive, and unless you inject a utility class instance, easier to test. On Wednesday, October 27, 2010, Li Ying wrote: > I would implement this function as a Utility Class, > and call it from the Action class. > > In the Utility Clas

Reg: Issue with Struts 2 Data Binding

2010-10-27 Thread Sathish Kumar
Hi Group, I have a below issue with Data Binding. Consider we have below code //Model Class Public Class User { Private *Date* dateOfBirth; // Setter and Getter } // Action Class Public Class MyActionClass{ Private *User* user ; // Setter and Getter } In My HTML

Re: Reg: Issue with Struts 2 Data Binding

2010-10-27 Thread Li Ying
Your data is declared as HashMap So Struts2 don't know what data type the parameter should be converted to. My suggestion: Change your Action class likes: Public Class ActionClass{ private *HashMap* userPropsAsDate; private *HashMap* userPropsAsInt; private *HashMap* userPropsAsStr; // Setter

Re: Reg: Issue with Struts 2 Data Binding

2010-10-27 Thread Sathish Kumar
Hi Li, Thanks ... Unfortunately, In my case, Map represents various java model classes at run time ( User, Employee etc ). So I will get the values in a Single Hash Map ( Using BeanUtils.describe ).. But Yes... as you said, By default struts 2 determine the Object Type using Type of the attribute

Re: Reg: Issue with Struts 2 Data Binding

2010-10-27 Thread Maurizio Cucchiara
Since you have entities that share *date of birth *, Why don't you consider using interface power? You could modify your code in order to manage DOB, by implementing a simple (f.e.) HumanBeing interface. public interface HumanBeing{ Date getDateOfBirth(); void setDateOfBirth(Date); } } Then you co

Re: Reg: Issue with Struts 2 Data Binding

2010-10-27 Thread Li Ying
May be you can copy all the properties from a map to an instance of your model class. You can implement this by (1)[BeanUtils.populate] of Apache Commons BeanUtils See: http://commons.apache.org/beanutils/apidocs/org/apache/commons/beanutils/BeanUtils.html#populate%28java.lang.Object,%20java.util.

Re: Reg: Issue with Struts 2 Data Binding

2010-10-27 Thread Sathish Kumar
Hi, Thanks for the response ... I will try this ... Regards, Sathish Kumar T On Wed, Oct 27, 2010 at 3:05 PM, Li Ying wrote: > May be you can copy all the properties from a map > to an instance of your model class. > > You can implement this by > (1)[BeanUtils.populate] > of Apache Commons Bea

RE: RequestHeaderAware in Struts 2?

2010-10-27 Thread Jose Luis Martinez Avial
Gello Dave, There is nothing wrong with the ideas you gave me. I particulary like Li's idea. What I'm saying is that to get the IP address is a different story, since there maybe some logic involved that depends on the context. I'm thinking which is the most orthodox and clean way to do

Re: RequestHeaderAware in Struts 2?

2010-10-27 Thread Dave Newton
Like I said--in my mind it depends on how much of your application requires this logic. If it covers a lot of the app, I think an interceptor makes sense. If it's only tiny little bits, I'd inject a utility class and call it directly. Dave On Wed, Oct 27, 2010 at 6:22 AM, Jose Luis Martinez Avial

Get s:url in action

2010-10-27 Thread Altenhof, David Aron
Hi ... I need to create a URL, like one would get from , but in an action. Are there any easy ways to do this Struts2, or should I try to fiddle aroung getting a url from ServletContext?

Struts nested and tags

2010-10-27 Thread Dave Westerman
I am trying to use the tag to allow uploading a file to the server. However, this tag has to be within a larger overall form. ... ... However, whenever I use the above code, I get the following error when I click on the 'Upload File' button: Invalid field value for field "up

Re: Struts nested and tags

2010-10-27 Thread Dave Newton
It's not legal to nest form tags; that's bogus HTML. I don't understand what you mean by "the rest of the page doesn't work"; a file tag is part of a form. You don't submit just part of a form, you submit all of it. If you're trying to do something like an Ajax upload, you'd need to do it differen

Re: Struts nested and tags

2010-10-27 Thread Maurizio Cucchiara
The first form doesn't contains enctype attribute. Did you try to set it to multipart/form-data? 2010/10/28 Dave Westerman : > I am trying to use the tag to allow uploading a file to the > server. However, this tag has to be within a larger overall form. > > > ... >     >     action="%{siteId}/a

Re: Get s:url in action

2010-10-27 Thread Li Ying
Not sure which part of this misson is bothering you. Basically, you need: (1)Get the context path of your web app, by invoking [ServletContext.getContextPath()] (2)Build the relative path (3)Build the query parameters what you want And then combine all of them. Most time you can implement this b