Mole Moore

Greenhorn
+ Follow
since Apr 03, 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 Mole Moore

Alright, so what I am hearing is two things:

1) It is NOT possible to integrate JSF/Spring in respect to PhaseListeners.

2) The integration that I have done between JSF/Spring in respect to the FacesContext and my BackingBean, while technically working, is dangerous for threading reasons.

Does that sound accurate?
14 years ago
JSF
Hi Tim, thanks for the response.

I guess I am not understanding your comment about Spring not being able to manage non-static objects. Spring allows for the management of virtually any object that you want, provided you know how to configure it, correct? The solution above is working brilliantly. I understand that this will only work within the "walled garden" of JSF, but that is all that is needed.

The crux of the issue is, can the same thing that I am doing with the FacesContext and my BackingBean (leveraging IoC by integrating Spring and JSF), be done with a PhaseListener? I have a solution working, using the code below. My goal is to get to a point where the FacesContext.getCurrentInstance() is injected into a property in my PhaseListener class, which will allow for easy out-of-container unit testing and will follow the pattern I am using in my backing beans, lending intself to easier support.


I am not set on using Spring/JSF to inject the depencency as the way I am currently doing this is working and is testable outside of a container. Just exploring the limits of the technologies.

I would also be interested in other ways to do the same thing.

Mark
14 years ago
JSF
Hello reubin,
I am new to JSF, so please take this with a grain of salt. I am kind of hoping that those more experienced in JSF will let me know of a better way to do this.

I had a need to perform some first-time logic before any code in my backing bean was ran. This seems to be kind of what you are needing to do? Lookup a value from a database and place it in session before some other code is ran?

Assuming that is correct, I used a PhaseListener that gets fired before any processing in my backing bean is done.

Two things are needed to use a PhaseListener, first a class that implement the JSF PhaseListener interface and an entry in faces-config.xml to register your listener with JSF.

Your PhaseListener class:



Register your listener with JSF.

faces-config.xml:


This probably is not the best solution out there, but it does the job very well.

Mark
14 years ago
JSF
Hello,
I have a PhaseListener that uses FacesContext to help me perform some first time logic. I would like to use dependency injection (DI) with Spring to inject the FacesContext into a property in the PhaseListener object. I am able to do the same thing using Spring and a managed backing bean, but I do not see an integration point between Spring and JSF for allowing a PhaseListener to be a managed bean.
I am fairly new to JSF and Spring, so in addition to answering this question I would also be interested in hearing of different/better ways to do the same thing. I am using JSF 1.2 and Spring 2.0.

This setup injects FacesContext into my backing bean, which has an appropriate property and getter/setter to recieve the object.

From my spring config file:


From my faces-config file:


The idea would be to do the same thing but with a PhaseListener, which would also contain a property and getter/setter to hold the FacesContext.
14 years ago
JSF
That is what I thought. I will just do the validation server side.

FYI: I tried using wildcards with no success.

Thank you very much for the input!

mole
15 years ago
Hello,
I have ran into a wall on this problem: I have a form that has several properties that are an array of Strings.




In my JSP I am creating controls associated with each element of the array by looping through the array.



I am trying to use validation.xml to check that the fields all have values.



When I try to submit the form and the validation runs I am getting: "Error 500: The field named 'customerCity[]' was not defined for form 'CustomerForm' in the validation configuration. "

If I define each element of the array in validation.xml it works fine.



I am trying to keep the number of customers that a user can enter dynamic so that he/she can choose how many to work per submission. I realize that I can do all of this validation easily in the forms validate method, but I was hoping to take advantage of the client side validation that is provided when using struts validation.

Any help that can be offered is greately apprecited, even if it is simply telling me that this can not be done.

Thanks in advance,
mole
15 years ago