Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 326629 - Annotations (@ManagedBean) and serve modules without publishing
Summary: Annotations (@ManagedBean) and serve modules without publishing
Status: RESOLVED FIXED
Alias: None
Product: WTP ServerTools
Classification: WebTools
Component: wst.server (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.2.3   Edit
Assignee: Larry Isaacs CLA
QA Contact: Angel Vera CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-30 02:56 EDT by Hanspeter Klapf CLA
Modified: 2011-04-28 09:26 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hanspeter Klapf CLA 2010-09-30 02:56:29 EDT
Build Identifier: 20100917-0705

After upgrading my Helios to SR1, "Serve modules without publishing" doesn't work for me. While resources (html, css, js, etc.) and classes seems to be published (I tried that with simple JSP's), it looks like Annotations (@ManagedBean, @SessionScoped) don't work.

Reproducible: Always

Steps to Reproduce:
1. Create a new Dynamic Web Project without special configuration (only target runtime, I take my apache-tomcat 6.0.29)

2. Add JSF and JSTL Libraries to WEB-INF/lib (jsf-api.jar, jsf-impl.jar, jstl-api-1.2.jar, jstl-impl-1.2.jar and log4j-1.2.12.jar)

3. At properties/Project Facets add "JavaServer Faces 2.0"

4. Write a simple Bean
package test;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="testbean")
@SessionScoped
public class TestBean {

	private String property;
	
	public TestBean() {
		this.property = "initial-value";
	}
	
	public String getProperty() {
		return property;
	}
	public void setProperty(String property) {
		this.property = property;
	}
}

5. Write an JSF-Page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html">
    <f:view contentType="text/html"/>
    <h:head>
        <title>test</title>
    	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    </h:head>
    <h:body bgcolor="white">
		<h:form id="test" prependId="false">	
			<h:messages styleClass="error" showDetail="true" showSummary="false" tooltip="false" />
	        <fieldset class="form_block">
	           	<div align="center">
	           		<h1><h:outputText value="#{testbean.property}" /></h1>
		        </div>
		    </fieldset>
	    </h:form>		
	</h:body>
</html>

6. When adding this project to a server, the property is listed when "Serve modules without publishing" isn't checked, elsewise it doesn't
Comment 1 Missing name Mising name CLA 2011-02-15 13:42:17 EST
I'm using mojarra 2.0.4-b09 and I'm having a similar problem with @FacesConverter.  Doing a little digging I found that com.sun.faces.config.AnnotationScanner scans /WEB-INF/classes/, but since these classes aren't found there with the "serve modules without publishing" option, they never get scanned.
Comment 2 Missing name Mising name CLA 2011-02-15 13:46:35 EST
JSF supports specifying these in faces-config.xml, so this is a workaround for the moment, but obviously not ideal.
Comment 3 Raghunathan Srinivasan CLA 2011-02-15 13:55:19 EST
(In reply to comment #1)
> I'm using mojarra 2.0.4-b09 and I'm having a similar problem with
> @FacesConverter.  Doing a little digging I found that
> com.sun.faces.config.AnnotationScanner scans /WEB-INF/classes/, but since these
> classes aren't found there with the "serve modules without publishing" option,
> they never get scanned.

Moving this to the Server Tool component based on the above comment. Please reassign to JSF if this is an issue with the JSF Tools.
Comment 4 Larry Isaacs CLA 2011-04-28 09:26:02 EDT
Sorry to take so long to address this.  This behavior stems from the same basic issue in "Server modules without publishing" as the one in Bug 318449.  There were other negative side effects of breaking Class.getResource() when ServletContext.getResource() was allowed to work.  Unfortunately, it appears that JSF annotation processing is also lost along with ServletContext.getResource() (and ServletContext.getResourceAsStream()).  Fortunately, as documented in Bug 333102 Comment #3, Tomcat 7 has improvements that allow ServletContext.getResource() and ServletContext.getResourceAsStream() functionally to be restored without impacting Class.GetResource().  Trying the test case above with Tomcat 7 shows that it continues to work with "Serve modules without publishing" enabled.

Since the problem behavior was fixed for Tomcat 7, I'm marking this bug as also FIXED (in WTP 3.2.3 via Bug 333102).  It's not currently possible to fix this for Tomcat 6 without breaking use cases where Class.getResource() is in use.  Also, changing the current behavior may introduce more problems than it solves.

If one is adventurous, you can examine the simple patch in Bug 318449 and restore what was changed for Tomcat 6 and see what happens.  Annotations should resume working, but there may be other important behavior that will stop working.