java-ee-6

Execution Order of @PostConstruct

我怕爱的太早我们不能终老 提交于 2019-12-10 17:48:44
问题 I have 2 singletons in my JEE application that I want to initialize at start up. Something like this: @Singleton @Startup public class ServiceB { @EJB private ServiceA a; @PostConstruct private void init() { .... } } ServiceB doesn't really need ServiceA, I just added the dependency to make sure that ServiceA is fully initialized (read: @PostConstruct-method finished) before ServiceB's init() -Method starts. But it doesn't wait. ServiceB actually starts before ServiceA. Is there any way to

mvc pattern in java ee and migrating from spring to java ee 7

一世执手 提交于 2019-12-10 17:19:04
问题 I used spring MVC in the following manner: @Controller class MyControllerClass { @RequestMapping... method(){ ServiceCall()... //put something to modelAndView object here and redirect to jsp page. return "home"; // this will redirect data to home.jsp } } @Service class MyServiceClass{ @Transactional SomeServiceMethod(){ DaoMethod(); } } @Repository class MyDaoClass{ DaoMethdon(){...} } /view/myjsps.jsp path to view directory set in spring.xml Question: Can any body explain to me (preferably

How do you call List.size() from a JSF 2.0 Facelets Template?

早过忘川 提交于 2019-12-10 12:44:37
问题 What is the syntax for calling list.size() in a JSF 2.0 Facelets template (eg, using an h:outputText element)? 回答1: How about this: <h:outputText value="#{fn:length(someBean.someList)}" /> You'll need to reference the functions taglib in your JSF page (URI: http://java.sun.com/jsp/jstl/functions ). 回答2: Just try #{myBean.myList.size()} 回答3: It's not a problem with JSF 2.0 exactly. The JSF spec still requires a class that conforms to the bean spec. The collection classes don't do that with the

How to change location of ValidationMessages.properties in Bean Validation

二次信任 提交于 2019-12-10 12:39:13
问题 By default, ValidationMessages.properties can be located in root of my classpath. Can I change the location of this file like com.myapp.Anything.properties? 回答1: From the JSR-303 specification: 4.3.1.1. Default message interpolation algorithm The default message interpolator uses the following steps: Message parameters are extracted from the message string and used as keys to search the ResourceBundle named ValidationMessages (often materialized as the property file /ValidationMessages

Glassfish - JEE6 - Use of Interceptor to measure performance

只谈情不闲聊 提交于 2019-12-10 11:29:06
问题 For measuring execution time of methods, I've seen suggestions to use public class PerformanceInterceptor { @AroundInvoke Object measureTime(InvocationContext ctx) throws Exception { long beforeTime = System.currentTimeMillis(); Object obj = null; try { obj = ctx.proceed(); return obj; } finally { time = System.currentTimeMillis() - beforeTime; // Log time } } Then put @Interceptors(PerformanceInterceptor.class) before whatever method you want measured. Anyway I tried this and it seems to

CDI params in @PostConstruct

前提是你 提交于 2019-12-10 11:26:55
问题 I think my question is similar to this but haven't found it to work <f:metadata> <f:viewParam id="id" name="id" value="#{detailsBean.id}"/> </f:metadata> Why can't I do this with @Named and utilize CDI: @Named @RequestScoped public class DetailsBean { private Contacts detailsContact; @EJB ContactsFacade contactsEJB; private int id; public DetailsBean() { System.out.println("details bean called"); } @PostConstruct public void onLoad() { detailsContact = contactsEJB.find(id); } I'm not able to

EJB 3.1 | Error calling remote session bean via JNDI

走远了吗. 提交于 2019-12-10 10:27:49
问题 I'm trying to call a simple stateless session bean from a Java SE (Simple class). Here's my bean import javax.ejb.Stateless; /** * * @author MMRUser */ @Stateless public class CapitalBean implements CapitalBeanRemote { public String greetingsEjb(String name) { return "Hello " + name; } } Remote interface import javax.ejb.Remote; /** * * @author MMRUser */ @Remote public interface CapitalBeanRemote { public String greetingsEjb(String name); } From my client side I used stand-alone java class

Lazy loading exception when using JSF Converter (refering to a collection)

∥☆過路亽.° 提交于 2019-12-10 10:18:38
问题 This is my first post after many research on this problem. This example is running under Jboss 7.1 with seam 3.1 (solder + persistence + faces) with seam managed persistence context I'm facing a problem, the classical failed to lazily initialize a collection, no session or session was closed: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed when using a converter on Entity beans. The aim is to stay 100% Object oriented, by

CDI @TransactionAttribute for bean

若如初见. 提交于 2019-12-10 10:12:28
问题 I am experimenting with CDI on a test application. I have a DAO which injects a container managed JTA persistence context like this: public class TestDAO implements Serializable { @PersistenceContext private EntityManager entityManager; public void insertEntity(Test test) { entityManager.persist(test); } } Now I have a CDI controller bean like this: @Named @SessionScoped public class TestController implements Serializable { @Inject private TestDAO testDAO; public void finishGame() { testDAO

How will I send messages to Activemq

…衆ロ難τιáo~ 提交于 2019-12-10 09:01:54
问题 I never work on JMS . Recently I downloaded Activemq and changed port no from 61616 to 61617 in all conf/activemq-*.xml files.I run the following command from command prompt and open console page on browser. C:\Users\Infratab Bangalore\Desktop\Queueing\apache-activemq-5.8.0\bin>activemq Now I want to send messages from java code using JMS to Activemq .For this I wrote the following code. And run my code using Apache Tomcat server.it's not working This code is implemented in Eclipse. package