cdi

Why different persistence units with separated data sources query the same data source?

匆匆过客 提交于 2019-12-18 10:20:13
问题 I'm developing a webapp which needs access to two different database servers (H2 and Oracle). The container is an Apache Tomee 1.5.1 and I'm using the Java EE stack with libraries provided in it (JSF, JPA, CDI, EJB, etc.). I'm trying to use two entity managers inside an XA transaction to extract data from the Oracle database and persist it in the H2 after transforming it, BUT all the queries are executed against the H2 database no matter the entity manager I use. Any help? EDIT : I found that

How to get transactions to a @PostConstruct CDI bean method

℡╲_俬逩灬. 提交于 2019-12-18 09:03:37
问题 I'm experimenting with Java EE 7, CDI, JPA and JSF. When the webapp starts, I would like to run an initialization method in my CDI bean (marked with @PostConstruct) that does some work with the database (inserts some rows etc..). For this I need a transaction, but this wasn't as easy as I expected. I have tried adding @Transactional annotation to my method, but apparently it only works with EJB. I actually tried converting my bean to EJB instead of CDI bean, but I still didn't get transaction

JSF/Mojarra “flash scope” problems

扶醉桌前 提交于 2019-12-18 08:55:28
问题 I've got an app running on Mojarra 2.1.1 / Glassfish 3.1 which has now grown to 150,000+ lines of code. The app uses ajax extensively with ViewScoped managed beans and the page-redirect-get pattern (i.e. faces-redirect=true). One thing that is continually annoying me is the apparent lack of ease of passing parameters from page to page, and bean to bean (every page has it's own backing bean). I've not been able to get the flash working. I typically need to access the data I've written to the

Custom bean validation does not `@inject` CDI beans and does not interpolate message?

做~自己de王妃 提交于 2019-12-18 07:24:41
问题 I am using GF4 with bean validation. I am trying to @Inject a service bean in my custom validator but I get a null value. public class TestValidator implements ConstraintValidator<>{ @Inject Service myService; } Isn't this suppose to be working with JEE7? Also, I am trying to find built-in dynamic message interpolation (Without writing my own MessageInterpolator ). I did see some examples but they are not very clear. What I am looking for is to pass dynamic parameters from the

Inject PersistenceContext with CDI

99封情书 提交于 2019-12-18 07:01:57
问题 Currently, I'm using PersistenceContext to inject an EntityManager. The EM is injected perfectly. @Stateless public StatelessSessionBean implements StatelessSessionBeanLocal { @PersistenceContext(unitName = "MyPersistenceUnit") private EntityManager em; @Override public Collection<MyObject> getAllObjects(){ CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriqQuery<MyObject> query = cb.createQuery(MyObject.class); query.from(MyObject); return em.createQuery(query).getResultList(); } } Now I

Inject PersistenceContext with CDI

拜拜、爱过 提交于 2019-12-18 07:01:53
问题 Currently, I'm using PersistenceContext to inject an EntityManager. The EM is injected perfectly. @Stateless public StatelessSessionBean implements StatelessSessionBeanLocal { @PersistenceContext(unitName = "MyPersistenceUnit") private EntityManager em; @Override public Collection<MyObject> getAllObjects(){ CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriqQuery<MyObject> query = cb.createQuery(MyObject.class); query.from(MyObject); return em.createQuery(query).getResultList(); } } Now I

How to @Inject in a PhaseListener

雨燕双飞 提交于 2019-12-18 04:08:34
问题 I have added a PhaseListener to faces-config.xml : <lifecycle> <phase-listener>com.project.NotificationListener</phase-listener> </lifecycle> The class seems to be otherwise correct as it is pretty simple. public class NotificationListener implements PhaseListener { @Inject private MyCDIStuff stuff; @Override public PhaseId getPhaseId() { return PhaseId.RENDER_RESPONSE; } @Override public void beforePhase(PhaseEvent event) { this.stuff.doStuff(); } } The 'beforePhase' method gets called

How to integrate JAX-RS with CDI in a Servlet 3.0 container

六月ゝ 毕业季﹏ 提交于 2019-12-18 04:08:29
问题 I have a web application running on a Servlet 3.0 container (Jetty 9.0.4) using JSF 2.2 (Mojorra 2.1.3) & CDI 1.1 (Weld 2.0.3). No full-fledged application server is used. In this application I also have a JAX-RS 2.0 (Jersey 2.2) resource class serving REST requests. I have integrated JAXB binding and also JSON marshalling (Jackson 2.2). I use Maven 3.0.5 for the build management. These are the relevant parts of my project setup: Maven pom.xml: ... <dependencies> <!-- Servlet 3.0 API -->

How to cleanly end a CDI @ConversationScoped

与世无争的帅哥 提交于 2019-12-18 03:48:24
问题 My Project is using JSF2.0 and CDI. For one page, I want my backing bean to match the lifespan of the page. @ViewScoped seems a perfect fit but it's not part of CDI and then make our solution not consistent. Then my next option would be the CDI @ConversationScoped. Seems to me the only way to mark the boundary of a conversation is the program way via conversation.begin and conversation.end (I have used Seam 2.x, there you can use annotations to mark conversation boundary). My page is sitting

Injecting Beans in JSF 2.0

南笙酒味 提交于 2019-12-18 03:45:58
问题 I have a Session scoped bean import javax.faces.bean.SessionScoped; import javax.inject.Named; @Named @SessionScoped public class SessionBean implements Serializable{ I inyect the object in one Filter... public class FiltroSeguridad implements Filter{ @Inject private SessionBean sessionBean; @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request;