- This topic has 15 replies, 5 voices, and was last updated 17 years, 1 month ago by gauravspyke.
-
AuthorPosts
-
Jeremy SteinMemberI’m using a fresh install of MyEclipse 5.0.1 on Eclipse 3.2 with Tomcat 5.5.17 on XP Pro SP2.
When I create a new web project and add Spring and JSF capabilities, I don’t automatically get access to Spring objects in JSF. The Spring/Hibernate integration made me expect something similar with JSF and Spring.
[rant]
JSF’s managed beans need access to the business objects, which are controlled by Spring. This situation is begging for Spring dependency injection. Yet there are many who struggle with this integration.- Here is a MyEclipse user who couldn’t get them to work together – http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-11234.html
- Here is a JavaWorld author who created an elaborate work-around in his architecture – http://www.javaworld.com/javaworld/jw-07-2004/jw-0719-jsf.html
- We have a client who is using JSF and Spring, but follows a (ridiculous) architecture like that from the JavaWorld article.
- And then there’s me. It me took two solid days to figure out why JSF wouldn’t load Spring objects. There were 3 issues, all of which I’ll address in this post.
Why doesn’t this work “out of the box” with MyEclipse? It could. It should!
[/rant]When both JSF and Spring capabilities are added to a project, MyEclipse should automatically add Spring’s JSF variable resolver to faces-config.xml.
<application> <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver> </application>
Also, when Spring capabilities are added to a web project, MyEclipse should automatically add Spring’s context loader to web.xml.
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
I noticed that Spring expects to find applicationContext.xml in the root WEB-INF directory. By default, MyEclipse puts it in src (which gets copied to WEB-INF/classes). Wouldn’t it be better to follow the Spring default? I suppose that’s not a big deal, but it did cause me a great deal of frustration when Tomcat gave me terse error messages when trying to load Spring. (I had to specify the config directory.)
In any case, it seems like it would be helpful to throw in a default log4j.properties file. If this file turned on Spring warnings, many common Spring errors (like needing to specify the Spring configuration directory) would be easier to solve.
For all of the above, I realize that it’s my responsibility as a developer to figure all this stuff out. I don’t really want MyEclipse just to magically take care of it all for me, but I like the way MyEclipse asks me a bunch of questions with reasonable defaults when I add a “capability” to my project. A couple more steps in this process to handle the above concerns would have made my life much easier.
MyEclipse is a great product. I hope my suggestions help you to make it even better. Thanks!
Riyad KallaMemberJeremy,
We want to thank you for taking the time to write up your findings and provide us with such detail. I’ve filed two issues in our issue tracker from this post:
1) Improve the default location of applicationContext.xml when used in a web application
2) Improve Spring/JSF/Web integration#1 has been brought up before so I think the sooner that gets done the better, #2 hasn’t come up yet, but with JSF and Spring use on the rise this functionality is inevitable and highly desired. I’m going to try and push that through at the next meeting.
bansiMemberJeremy,
I am in the same situation as you were sometime back. Also i am using similar set of tools viz. MyEclipse 5.0.1 GA on Eclipse 3.2, JSF 1.1_01, Spring 1.2.6, Tomcat 5.0.28 on XP Pro SP2. I have posted the integration problem on almost all the forums including this forum.I am getting following error
javax.servlet.jsp.JspException: javax.faces.FacesException: javax.faces.el.EvaluationException: Expression Error: Named Object: ‘springBean’ not found.
The root cause for the error is “<managed-property>” under <managed-bean> from JSF which references Spring Bean. It is not able to evaluate JSF Expression Language. Then i tried various permutations and combinations. One of them is
-> instead of using JSF EL, i hardcoded the property value and it worked
Any pointers/suggestions will be highly appreciate. I am working on this for more than a week
If possible could you please share your sample application integrating JSF/Spring or take a moment to look at my code. I hope to benefit from your experience
Thanks for your time in advance
Regards
Bansi
bansiMemberJeremy,
Here are the snippets of codeweb.xml : <context-param> <param-name>javax.faces.CONFIG_FILES</param-name> <param-value>/WEB-INF/faces-config.xml</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
faces-config.xml <application> <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver> </application> <managed-bean> <description>JSF managed bean referencing a spring bean</description> <managed-bean-name>JsfBean</managed-bean-name> <managed-bean-class>test.JsfBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>springBean</property-name> <value>#{springBean}</value> </managed-property> </managed-bean>
application-context.xml : <bean id="springBean" class="test.SpringBean"> <property name="text"><value>some example text</value></property> </bean>
The weird thing i notice about MyEclipse 5.0 is when i reopen it after some time it puts a red cross mark and says test.JsfBean not found
The JSP Page
<h:outputText value="#{JsfBean.springBean.text}" />
package test; public class JsfBean { private SpringBean springBean; public JsfBean() { super(); } public SpringBean getSpringBean() { return springBean; } public void setSpringBean(SpringBean paramSpringBean) { springBean = paramSpringBean; } }
package test; public class SpringBean { String text; public SpringBean() { super(); } public String getText() { return text; } public void setText(String paramText) { text = paramText; } }
Jeremy SteinMember(Bansi sent me his code off-forum.)
Bansi, I can’t recreate the error you’re seeing. I think it may have something to do with using Sun’s reference implementation. I created a simple example web application to get you started. http://stein.everybody.org/brain/simple-jsf-spring-example/
bansiMemberJeremy
Thank you so much for posting your Hello World application. I am sure it will be helpful to people who have gone thru similar experiences of you & mine. Few Clarifications-> Looks Like you are using MyFaces 1.1.1
-> I downloaded you application but couldn’t find JAR files in WEB_INF/lib directory. Could you please let me know what JAR files i need to use as you suggest not to use the JAR files from MyEclipse in the above posting
->I am not familar with Maven. It would be great if you explain how to use with ANt
-> I suspect the root cause for my el.EvaluationException error is the JAR files imported by MyEclipse OR it maybe also that i am not using MyFaces. Do i need to use MyFaces . I know its implementation of JSF. But is it reqdPl mail me at [email protected]
Regards
Bansi
bansiMemberJeremy
Thanks for sharing your sample application it works for me. Still wondering do i really need MyFaces to make it work. Cant it work with just Spring and JSF i mean without MyFacesI once again thank you for your help and would like to know if you have any similar sample barbones application extending the Integration to Hibernate. When i tried extending the integration to Hibernate it results in following errors on Tomcat 5.0.28
Sep 13, 2006 5:34:57 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Sep 13, 2006 5:34:57 PM org.apache.catalina.core.StandardContext start
SEVERE: Context startup failed due to previous errorsCould you please share your sample application JSF+Spring+Hibernate
Thanks for your time in advance
Regards
Bansi
Jeremy SteinMember@bansi wrote:
Still wondering do i really need MyFaces to make it work. Cant it work with just Spring and JSF i mean without MyFaces
I’m sure it works fine with Sun’s reference implementation also. I suspected that you might have copied the configuration for MyFaces and used it with JSF RI; that’s why I suggested you switch to MyFaces.
@bansi wrote:
…would like to know if you have any similar sample barbones application extending the Integration to Hibernate.
I do not have an example with Hibernate, but AppFuse uses Hibernate. Also, there are many examples on the web showing how to integrate Hibernate with Spring, and MyEclipse does a pretty good job of integrating them when you use it to add Spring and Hibernate capabilities.
@bansi wrote:
SEVERE: Error listenerStart
You will find your listenerStart error easier to debug if you turn up the logging level.
bansiMemberI have turned up my logging level to DEBUG still i am not able to figure out what the Error is. Here is my log4.properties file
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[ar] %p %c.%M:%L | %m%nlog4j.rootCategory=DEBUG, stdout
log4j.logger.org.apache.commons=ERROR
log4j.logger.org.apache.myfaces=WARN
# Avoid MyFaces error message http://bugs.sakaiproject.org/jira/browse/SAK-4645
log4j.logger.org.apache.myfaces.util.LocaleUtils=FATAL
log4j.logger.org.springframework=WARN# Suppress the tomcat logging in case DEBUG is switched on at the root
log4j.logger.org.apache.catalina.core=ERROR
log4j.logger.org.apache.catalina.session=ERROR
log4j.logger.org.apache.jasper.compiler=ERRORlog4j.logger.com.mycompany=DEBUG
The Stack trace
Sep 19, 2006 5:35:11 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Sep 19, 2006 5:35:11 PM org.apache.catalina.core.StandardContext start
SEVERE: Context startup failed due to previous errors
Jeremy SteinMemberLook at your web.xml. You’ve got Spring and MyFaces listeners, so you need to turn on debugging for Spring or MyFaces.
bansiMemberIt still doesnt work. Infact whatever you do it doesnt work with Tomcat 5.0 /5.5 . The good news is same war file works on Oracle 10g AS. Any pointers
amir55Participantdear all
I think I have problem with added library so I get the error of object not found and jas can not access spring been.
on spring site t asks for downloading srpign 2,0 and jas-spring 4.
how can I add these to my MyEclipse as a libray that can be selected when adding spring capabilities.
if someone manages to run jsf spring integration, to tell me then I am overwhelemed with thanks to his/her support.
I do feel sad that MyEclipse releases mentions the integration with no tutorials on it. this is the weakest point in this product that has no many tutorial examples.
I do like to see MyEclipse examples run on integrations like :
1- jsf spring
2 – spring -hibernate
3 -struts -spring
4 – jsf -strutsso many thanks for any guide.I will then hold his fevour for any returns even finencially to buy the examples
many thnaks
Amir
amir55Participanthi all
i get this error at running the JCatelog programjava.lang.NoClassDefFoundError: net/sf/cglib/core/KeyFactory
and where can I download the jar files for it?
many thanks
Amir
amir55ParticipantThis message has not been recovered.
gauravspykeMemberThis message has not been recovered.
-
AuthorPosts