[JBoss Seam] - Testing without EJB
by jcruise
Hi
Does anybody know how to bootstrap the microcontainer in a test class or console app? I am using pojo/hibernate/tomcat so I don't want to use the embedded ejb-3. I tried simply extending SeamTest, using code a bit like this:
| public class Administration extends SeamTest {
|
| EntityManager em() {
| EntityManagerFactory emf = Persistence
| .createEntityManagerFactory("myDatabase");
| EntityManager em = emf.createEntityManager();
| return em;
| }
|
| public static void main(String[] args) throws Exception {
| Administration app = new Administration();
| app.execute();
| }
|
| private void execute() throws Exception {
|
| EntityManager em = em();
|
| em.getTransaction().begin();
|
| Log log = (Log) getInstance("log");
| log.info("Starting Administration Console");
|
|
| ... stuff with my components ...
|
|
| em.getTransaction().commit();
| }
|
but I get the following error:
| 15:55:15,967 ERROR [NamingHelper] Could not obtain initial context
| javax.naming.NamingException: Local server is not initialized
| at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:30)
| at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
| at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
| at javax.naming.InitialContext.init(Unknown Source)
| at javax.naming.InitialContext.<init>(Unknown Source)
| at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
|
Any ideas?
Cheers
J
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4048807#4048807
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4048807
18 years, 11 months
[JBoss Seam] - Re: Versatile component : component binding, facelets or new
by matt.drees
I'm doing something similar in my project.
I use a few Facelets TagHandlers based on Rick Hightower's articles (http://www.ibm.com/developerworks/java/library/j-facelets2.html). My page looks something like this:
| <h:panelGrid id="questionPanel" columns="3">
|
| <crs:customQuestions
| registrationType="#{registrationType}"
| questionTextVar="questionText"
| questionNumberVar="i"
| requiredVar="required">
|
|
| <h:outputLabel for="answerInput#{i}" value="#{i}" id="questionNumber#{i}"/>
|
| <s:formattedText value="#{questionText}" id="questionText#{i}"/>
|
| <h:panelGroup>
| <s:decorate>
| <f:facet name="aroundInvalidField">
| <s:span styleClass="errors"/>
| </f:facet>
| <crs:isText>
| <h:inputText id="answerInput#{i}"
| value="#{registrationProcess.pageAnswers[i ].valueString}"
| required="#{required}">
| <a:support event="onblur" reRender="questionErrors#{i}"/>
| <crs:validateQuestion/>
| </h:inputText>
| </crs:isText>
|
| <crs:isDate>
| <h:inputText id="answerInput#{i}"
| value="#{registrationProcess.pageAnswers[i ].valueDate}"
| required="#{required}">
| <crs:validateQuestion/>
| <s:convertDateTime pattern="MM/dd/yyyy"/>
| <a:support event="onblur" reRender="questionErrors#{i}"/>
| </h:inputText>
| <s:selectDate for="answerInput#{i}">
| <h:graphicImage url="img/dtpick.gif" style="margin-left:5px"/>
| </s:selectDate>
| </crs:isDate>
|
| <crs:isBoolean>
| <h:selectBooleanCheckbox
| id="answerInput#{i}"
| value="#{registrationProcess.pageAnswers[i ].valueBoolean}"
| required="${required}">
| <crs:validateQuestion/>
| </h:selectBooleanCheckbox>
| </crs:isBoolean>
|
| <br clear="none"/>
| <a:outputPanel id="questionErrors#{i}">
| <s:message/>
| </a:outputPanel>
| </s:decorate>
| </h:panelGroup>
|
| </crs:customQuestions>
| </h:panelGrid>
|
Note that I haven't updated this to use the newer s:decorate methodology, but you get the idea.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4048799#4048799
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4048799
18 years, 11 months