Pavel Kazlou

Ranch Hand
+ Follow
since Sep 07, 2009
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 Pavel Kazlou

Found corresponding issue in struts JIRA: https://issues.apache.org/jira/browse/WW-3268

2.3 is specified as fix version.
12 years ago
I have a base class ReportElement which has type property:



ReportElementType is just an enum with specified code and i18nKey properties for each element. I have a couple of subclasses of ReportElement, each of them introducing their own properties. One of them is Plot:


On some page I needed to display a collection of different ReportElement instances, so I just used struts2 select tag:



This worked like a charm for every element except for Plot instaces. Instead of invoking getType().getCode() or getType().getI18nKey() plain toString() was invoked on every instance of Plot! After several hours of fun debugging I noticed that during tag evaluation Plot's getParameters() method is called! So it seems struts was trying to evaluate type.code and type.i18nKey using getParameters() method! Failing to do that it ignored the existence of the properties, that I have clearly specified for usage!

After renaming getParameters to a kind of odd name like getParamms the problem gone. Also the problem with evaluating ognl wasn't spotted when using iterator tag together with property tag.

Does anyone have an idea WHY struts uses parameters property of my bean, when I have clearly specified what property should be used? Is it some "cool" feature or a bug?

P.S. I use struts 2.2.3.1
12 years ago
Thank you, Peter.
I think sql plugin is not suited for testing, so I ended up writing test part of my case in classes using jdbc and measuring the time of their execution.
13 years ago
Hi!

I'm using maven 2.2

With it I am able to run code-based tests and get both their success/failure result AND the time of execution in surefire reports. So I can perform a kind of benchmarking for my tests.

Now I'm using maven sql plugin http://mojo.codehaus.org/sql-maven-plugin/
With it I don't have to write any jdbc code and can perform sql queries right from *.sql files. I have a set of queries to create schema, populate tables with data and queries to perform some selects which I want to benchmark. Even though I put sql plugin goal "execute" into "test" phase I don't have any reports being generated, all sql-s are performed without any reports (like they are just used for preparation).

As you may understand there is no java code involved into this test, just plain sql queries. But I want to incorporate database testing into my project, controlled by maven.
So do you know any way to implement time measuring of my sql goals, so I can see that one select query took X seconds and the other Y seconds.
13 years ago
Pavel, thank you very much for the help, I appreciate it.
13 years ago
You can try the following solution:
1. insert custom filter into spring security filter chain
2. inside this filter obtain http session and store there the value of request parameter

As we change the login form (adding another parameter) we need to customize spring representation of login form and spring login processing filter.
Here is the configuration:



MyAuthenticationProcessingFilter extends spring's org.springframework.security.ui.webapp.AuthenticationProcessingFilter, wraps attemptAuthentication method obtaining request parameter and storing it inside http session. This class is written just to show the idea, for better practice browse AuthenticationProcessingFilter code for username and password parameters.


You may notice that "myFilter" and "entryPoint" beans together define parameters that are otherwise defined by <form-login> element inside <http>. You use <form-login> when you want the default behavior. But in our case we use custom beans, so you should remove <form-login> element completely.
Now we need to tell <http> use our beans. "myFilter" bean is passed to spring chain by using <custom-filter> element inside bean definition:


"entryPoint" is passed to <http> using attribute:


13 years ago
You should read about spring security.
You will end up with some xml configuration files added and you don't have to mess with classes. Your problem is very common so don't try to reinvent the wheel.
http://static.springsource.org/spring-security/site/start-here.html
14 years ago
All right, let's omit struts 2. How can I pass parameter to the request which is made after a successful authentication?
That's almost the same as modifying my configuration:



but myValue is a dynamic value, I can't hardcode it.
14 years ago
The struts 2 action is bound to successful login using spring security configuration:

14 years ago
Hi.
In my application the first page the user gets is the login form. I handle the login action using spring 2 security. After the successful login user is directed to struts 2 action.
In this struts 2 action I have property which I would like to populate with user input (additional field inside login form).
To be able to populate this property of struts 2 action I need to set request parameter. The problem is that the request is controlled by spring security. I've tried adding input field to login form, but spring doesn't forward its value to struts action.

How can I solve this problem?
14 years ago
Thanks, James.
Actually I'm using spring for my JPA transactions. So I've put @Transactional annotation on the method which performs queries and YES, it works! No object duplication for the same database entity.

Thank you very much.
Hi.

In my web application I use several different JPA queries to retrieve objects from database and populate my http session data structure. This includes list of cars, list of groups of cars and some other structures containing cars.

Any car can be included in several different structures. For example the same car can be included in group G (as the first car in this group) and be the property of Driver D. So that D.getCar() and G.getCars().get(0) refer to the same database entity (correspond to the same database row). But not the same object instance. That's because I'm retrieving groups of cars and drivers in separate queries. But I want the same database entitites in my structure be the same objects. So that for example I will be able to change transient data of D.getCar() and the changes will be reflected in G.getCars().get(0).

Is there any way to implement this transparently using JPA? I perform only reading operations on database, so I don't care about whether the entitites in my structure are managed or not. I'm changing only transient data.

Of course the possible solution is to manually traverse through my objects structure looking for Car instances with the same id property and replacing duplicates with the same object instance but this is really a headache.
Hi.
I use spring 2.5 and in my application I need to create object which depends on some runtime parameters.
The problem is that I can't use constructor

because MyObject uses spring bean to perform some actions.

So MyObject should be aware of both runtime parameters and spring bean.
Of course it is possible to solve the problem by using the extended constructor

but in this case i need to inject mySpringBean in the bean which creates MyObject. A kind of "dirty" solution...

Is there a way to instantiate MyObject so that it knows both runtime parameters and bean ?
14 years ago
David, thanks for the reply.
Here is my attempt

...and the result

So, as you see "()" doesn't work at all. Also, note that when using "[]" I was able to display indexed property when using the whole path "beans[1].indexData[1]".
14 years ago
Hi.
During the development I faced a very strange struts 2 behavior. Here is the simplified example of the problem.
In my action class I define a collection or a map of beans that have indexed properties:

Then in my jsp I try to access the properties of beans in two ways - using the whole path and using push tag (I try to do this for both Map (beans) and List (beanList)) :

As the result, when using push tag indexed property is not displayed while simple property is displayed:


I've thought that push tag makes no difference when accessing properties, just shortening the path.
Is it a bug in struts 2 that prevents indexed property from displaying or I'm doing something wrong?
The example may seem a bit synthetic but in my real application it brings me some troubles because I can't replace those indexed properties with some collection - there is some logic behind them.
I tried the example on both struts 2.0.14 and 2.1.8 - the results are the same.
14 years ago