Caucho Forums  

This forum is permanently closed because of spam. For free community support, please visit Google Groups:


Go Back   Caucho Forums > Resin

Reply
 
Thread Tools Display Modes
  #1  
Old 06-02-2012, 08:01 PM
antoine_sd antoine_sd is offline
Junior Member
 
Join Date: Jun 2012
Location: Paris, France
Posts: 3
Default Producer method not triggered by EL

I'm new to Resin and have an issue with producer method in Candi on Resin 4.0.27.

I have a bean like that

Code:
@SessionScoped
@Stateful
public class UserGroupListProducer implements Serializable {
	
          @PersistenceContext  
	   private EntityManager em;

	private List<UserGroup> userGroups;
	
	@Produces
	@Named
	public List<UserGroup> getUserGroups() {
		return userGroups;
	}



	@PostConstruct
	public void retrieveAllUserGroupsOrderedByName() {
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<UserGroup> criteria = cb.createQuery(UserGroup.class);
		Root<UserGroup> userGroup = criteria.from(UserGroup.class);
		criteria.select(userGroup).orderBy(cb.asc(userGroup.get("name")));
		userGroups = em.createQuery(criteria).getResultList();
	}
}
This bean is not directly used in the application, I only need the producer method.

In my JSF page, when I call #{userGroups} to display the list in a datatable, nothing happens : the code in the postConstruct or getUserGroups are not called.

When I add a @Named to the EJB and use #{UserGroupListProducer.userGroups} in my JSF everything works as expected.

According to the section 5.3 of CDI spec the @Named on the producer should expose the produced bean (the list) and EL should trigger the call.
Reply With Quote
  #2  
Old 06-05-2012, 11:41 PM
RICK RICK is offline
Member
 
Join Date: Mar 2012
Location: New York
Posts: 30
Default Unable to reproduce this.

I attempted to reproduce this, but cannot yet.

Code:
/qa/WEB-INF/classes/META-INF/beans.xml

<beans xmlns="http://java.sun.com/xml/ns/javaee">
</beans>

Code:
/qa/WEB-INF/classes/qa/MyBean.java

package qa;

public class MyBean {
  private String _dummy;

  public MyBean() 
  {
  }  
  public MyBean(String dummy)
  {
    _dummy = dummy;
  }

  public String toString()
  {
    return getClass().getSimpleName() + "[" + _dummy + "]";
  }
}

Code:
/qa/WEB-INF/classes/qa/MyProducer.java

package qa;

import javax.inject.*;
import javax.enterprise.inject.*;
import javax.inject.*;
import javax.ejb.*;
import javax.enterprise.context.*;
import javax.annotation.*;

@Stateful
@SessionScoped
@Named
public class MyProducer {

  private MyBean myBean = null;

  @Produces @Named @ApplicationScoped
  public MyBean getMyBean()
  {
    return myBean;
  }

  @PostConstruct
  public void postCreate() 
  {
     this.myBean = new MyBean(getClass().getName());
  }
}

Code:
/qa/test.jsp

myBean : ${myBean}
myProducer : ${myProducer.myBean}
empty? : ${empty myProducer}
empty? : ${empty myBean}

</file>

Loading test.jsp yields.....

myBean : MyBean[qa.MyProducer]
myProducer : MyBean[qa.MyProducer]
empty? : false
empty? : false


Are you sure that you are using the right @ApplicationScoped? Maybe you are using the one by JSF by accident?
Reply With Quote
  #3  
Old 06-06-2012, 12:12 AM
RICK RICK is offline
Member
 
Join Date: Mar 2012
Location: New York
Posts: 30
Default Also tried it with List, it just does not fail...

Code:
/qa/WEB-INF/classes/META-INF/beans.xml
<beans xmlns="http://java.sun.com/xml/ns/javaee">
</beans>


Code:
/qa/WEB-INF/classes/qa/MyBean.java
package qa;

public class MyBean {
  private String _dummy;

  public MyBean() 
  {
  }  
  public MyBean(String dummy)
  {
    _dummy = dummy;
  }

  public String toString()
  {
    return getClass().getSimpleName() + "[" + _dummy + "]";
  }
 
}

Code:
/qa/WEB-INF/classes/qa/MyProducer.java

package qa;

import javax.inject.*;
import javax.enterprise.inject.*;
import javax.inject.*;
import javax.ejb.*;
import javax.enterprise.context.*;
import javax.annotation.*;
import java.util.*;

@Stateful
@SessionScoped
@Named
public class MyProducer {

  private MyBean myBean = null;
  private List<MyBean> myBeans = null;

  @Produces @Named 
  public MyBean getMyBean()
  {
    return myBean;
  }

  @Produces @Named @ApplicationScoped
  public List<MyBean> getMyBeans()
  {
    return myBeans;
  }

  @PostConstruct
  public void postCreate() 
  {  
     this.myBeans = new ArrayList<MyBean>();
     this.myBean = new MyBean(getClass().getName());
     this.myBeans.add(this.myBean);
  }
}
Code:
/qa/test.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix ="c" %>
myBean : ${myBean}
myBeans : ${myBeans[0]}
myProducer : ${myProducer.myBean}
empty? : ${empty myProducer}
empty? : ${empty myBean}
empty? : ${empty myBeans}
<c:forEach var="bean" items="${myBeans}">
bean : ${bean}
</c:forEach>

Code:
OUTPUT
myBean : MyBean[qa.MyProducer]
myBeans : MyBean[qa.MyProducer]
myProducer : MyBean[qa.MyProducer]
empty? : false
empty? : false
empty? : false

bean : MyBean[qa.MyProducer]
I tried it with and w/o ApplicationScoped. It works both ways. (In the email you sent me, you sent with ApplicationScoped).
Reply With Quote
  #4  
Old 06-06-2012, 03:39 AM
antoine_sd antoine_sd is offline
Junior Member
 
Join Date: Jun 2012
Location: Paris, France
Posts: 3
Default

Thanks Rick for your answer.
I was preparing a more simple version of my test project to send on this forum but was unable to reproduce my issue

My first project was still buggy so I decided to test is out of eclipse by building it in command line and deploy by hand. And it worked (no more bug)...

I'm a bit confuse and think I experienced an eclipse or eclipse wtp bug.

Sorry I made your lost time on this. I'm going to investigate this eclipse issue, but it's obviously not related to Resin.
Reply With Quote
  #5  
Old 06-06-2012, 05:17 AM
RICK RICK is offline
Member
 
Join Date: Mar 2012
Location: New York
Posts: 30
Default No worries

No worries. I was glad to help. Let me know if you have any more problems.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.