Emili Calonge

Ranch Hand
+ Follow
since May 17, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Emili Calonge

Well, I finally found a way to do that, but I just don't get why my solution didn't work.

Turns out there's a PreResultListener http://struts.apache.org/2.x/docs/can-we-access-an-actions-result.html that allows me to do that. My interceptor with the PreResultListener is:


Which is very similar to the code I had before, that was:


The InputAware is an interface I've declared which just makes sure that the action has a prepareInput method.

So if I use my implementation I can't access my lists in the jsp, but if I use the befroResult one, everything works just fine. Anyone has an explanation for that? I'd love to understand why mine didn't work so I can fix it, or at least get know better Struts2.

Thanks for your help!
14 years ago
I knew this would happen...
Thanks Ankit Garg, but I just mentioned that at my post.

Emili Calonge wrote:
I know I cloud use the preparable interface, but I want to avoid that.



The prepare interceptor runs the prepare method every time you invoke the action, and I don't want that. When I have my form loaded and I submit, it's a waste of time to execute the prepare method if the action is going to succeed. As you can't know that before executing the action, the prepare interceptor is not what I'm looking for.

As the page you linked states:

http://struts.apache.org/2.0.14/docs/prepare-interceptor.html wrote:
This interceptor is very useful for any situation where you need to ensure some logic runs before the actual execute method runs.



So what I want, is to execute a method only when the validation fails. Well, I think it's quite well explained in my first post.
14 years ago
Hi!
I'm using Struts 2 with tiles, and zero configuration setup. I'm performing validation on my actions (with annotations), but I have a problem. I need a series a values of my jsp's, basically lists. So I need to load them before getting to the jsp.

What I do is I have a fetch action that gets called and then this redirects to the jsp that renders the form. So I have my lists in the form. But when I submit the form, if there's a validation error, and I get back to the form, the lists aren't there so my form doesn't work.

I know I cloud use the preparable interface, but I want to avoid that, as I have multiple methods on my action, and the prepare method would have to perform quite a few list fetches on the db, and I want to do that as few times as possible. Ideally I would only have to perform those fetches if the result is "input".

So the solution I've come up with is implementing an interceptor that checks the result, and if it is "input", then execute the method that fetches everything from the db. But that doesn't work. The interceptor works fine, and it does what it's supposed to, and even if I check the valueStack with:

the lists are there, but they don't appear on my jsp.

So, the fetching action is:


This gets me to the jsp with the form. Then the form submits to the action with the validation:

And the action is:


And when this is the result, I get back to the form, but my lists don't get loaded.

Any suggestions? Thanks!
14 years ago
I'm using aspectj to inject my dao into my domain objects, so I can have only a persist method for every domain object and call it from different actions. The thing is that it was working perfectly until I wanted to delete an object.
If I want to create an object I just use:

and in my Car.class I have:

And this works perfecty. The car object attributes are being filled in the form and then I submit to the action. But now I've created my deleteCar method, and it's not working.

and in the Car.class the method is just a cal to dao.delete(). The thing is that the dao is null. So if instead of the car object being created by Struts, I fetch it from the database, the Car object doesn't get a Dao ovject injected. I thought AspectJ injected the dao on every instance being created, but it's not working on this instance that I fetch from the database. Am I doing something wrong? Is this supposed to work?
Thanks!
14 years ago
@David Newton: Yes, I'm using ajax submit with the struts2-jquery library. The submit looks like this:

14 years ago
I have a simple application, a form for creating users. The .java has two methods, the execute and an action for fetching a list of poblations.
So first I call to the fetch method wich gets the list and redirects to the form. The when I submit the form, the validation works perfectly, but when either an error happens or the action succeeds, nothing happens. I just get the destination page as an ajax message when the expected result would be a redirection.
So my configuration is as follows:

So first I call the registreUsuariPrepare action, then I get redirected to ublic/registreUsuari.jsp which contains the form, and when I submit the form, if the success or the error results are returned, I don't get redirected, I just get the contents of index.jsp or error.jsp as an Ajax response.
How can I avoid that and get redirected, what am I doing wrong?

My java is this:


I've tried adding

to the jsonValidationWorkflowStack, but it also doesn't work. I think it has to be something with this stack, but all the examples I've seen seem to work fine just like this.
Thanks!
14 years ago
You're absolutely right. I just wasn't looking in the right place when I first tried it. I was tying to put some message directly to the HtmlMessage object. It has to be done through getFacesContext().addMessage(HtmlMessage.id, FacesMessage), where the first attribute is the Htmlmessage id and the second one a facesMessage.
I just post this in case someone is looking for this too.

Thanks a lot Tim!
14 years ago
JSF
Hi,

I am wondering, if it is possible to set error messages to a <h:message> field from a custom function, that is not a validator function. So if in my register function I do some checks and realize that there is a problem with the data in the form, then set an error message to the form field with the error.
So I thought that if I have different inputs with their associated <h:message> the I can bind the message field to the backing bean, and then use some method on the HtmlMessage class to set a custom message. But I've been doing some tests and no message shows up.

Can anyone tell me if this is possible and how to do it? I want to do it without creating validators, I know I could do it with validators, but I'm just wondering if it is possible to do it in a different way.

Thanks!
14 years ago
JSF
Hi,

I have a form that I use for creating and editing users. So the form fields are all getting their values from #{users.user.*}. When I want to create a user I set user = new User(); and when I want to edit a user I simple fetch the db ans set user to the user on the db.

All of the form fields are required, and most of them have a validator for length with a minimum of 3 characters. The form also has a cancel button, that clears the form (user = new User()).

So, if a user chooses to edit a user (all the form fields get filled with the user info correctly), and then cancels, and then selects to create a new user, the form fields don't validate. It doesn't validate even that the required fields are filled.

Does anyone have any clue on what may be happening?

Thanks!
14 years ago
JSF
Hi!

I need to develop a web application that does the user login using client certificates. Also I need this application to use different roles for every user. So I've been reading and I'm a little confused on what should I do. I've read about acegi (I'm using Spring) but I've also read that it's quite difficult to use, I d'ont know if it's really the good path to follow.
My main questions are:

1 - Which application server is best for doing this? I'm curently using glassfish but I've senn almost no documentation regarding this kind of user system.
2 - How can I link a certificate login to its system roles?
3 - Should I use some library like acegi or should I mainly relay on the application server config?

Any kind of suggestion is welcome.

Thanks a lot!
15 years ago
I completely understand what you're saying, but I could'nt find a way to access my DAO's form anywhere but the servlet, because I'm using

to acces the DAO's. So that's why I kept the DAO acces on the servlets.
Hi Mark,

Thanks for your reply. I kind of hate to have the configuration correct, because I still can see that the living generations never stop growing on the profiler. The good news is that after tweaking a little the app server the memory consumption has lowered quite a bit. Which I also hate because know I won't take this problem that seriosuly now.

The difference when I didn't have Spring is that I didn't have a DAO and a DAO Interface for every domain class, I had just one Generic DAO.

Now that I've been thinking a lot about this I've realized that maybe this problem existed before and I just didn't notice it.

I think it's very interesting what you say about the service layer but I don't know exactly how you would implement that, can you give me some hints?

Thanks a lot!
I just got confused. Of course I manage the session, and I invalidate it when the user leaves. I tracked it with the profiler and it has nothing to do with my memory consumption problems.

I don't know if I said it but the applications worked perfeclty and then I decided to use Spring, that's when my memory consumption problems started. So I just assume I have a misconfiguration problem, probably related to transaction mamangement.

As of the Web ApplicationContext, the typical use in my application is :



And then use the DAO classes to create, find, delete, etc objects from the database.
I apply lazy-loading based on relationships with annotations. Most of them are set to lazy but I need some others to be eager. The managing of the httpSession is what I don't know how do I have to manage. I've got the applicationContext defined and then on every servlet I invoke



Is that what you refer to?

As I said before, I use the netbeans profiler, but I don't manage to get clear results from it. I can see that every time I invoke a servlet I get an extra living generations, which is bad and I suppose that is what is causing my problems, but I can't manage to track down where exactly this living generation comes from.
I forgot to post my DAO structure. Here it is:

For every domain class I've got a DAO and an interface:



And all these DAO's extend from 2 generic ones:


That's all I've got. I don't have any filter to control Hibernate sessions or anything because as I understood it, this should be taken care of automatically. I don't know where I read that or if that makes any sense. I really hope I misunderstood that and someone can point me how should I do it.

Tnahks a lot!