1 Reply Latest reply on Sep 12, 2006 4:39 AM by Andreas Franke

    Missing comprehension in EJB3 and JBoss in Elcipse

    Andreas Franke Apprentice

      I have installed the JBoss AS (jboss-4.0.4.GA) with EJB3 support(option: all). The EJB3Trail.ear works fine. Now I have try to build my first simple EJB3 Webapplication with Stateless SessionBean like the first EJB3Trail example.

      The java files from EJB3Trail source are present: Calculator.java, StatelessCalculator.java, RemoteCalculator.java and StatelessCalculator2.java
      The calculate.jsp as well.

      What I have to do, running this example in JBoss Eclipse IDE 2.0

      Hope anybody can help me


        • 1. Re: Missing comprehension in EJB3 and JBoss in Elcipse
          Andreas Franke Apprentice

          her is my solution tot he problem above, solved with JBoss Seam and Facelets
          1.) First I follow the discription http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossSeamGettingStartedGuide and installed JBoss IDE and SEAM as described.

          2.) Now the steps in Eclipse for an new ?Enterprise Application Project?
          Project Name: statelessSb
          J2EE Modules -> New Module: statelessSbEJB, statelessSbWeb
          The Workspace is defined as V:\seam-workspace

          Under Win CMD type as follow: (the same like 1.)
          V:\seam-workspace\jboss-seam-1.0.1.GA\seam-gen>seam new-wtp-project statelessSb
          V:\seam-workspace\jboss-seam-1.0.1.GA\seam-gen>seam new-stateless-action statelessSb StatelessCalculator
          V:\seam-workspace\jboss-seam-1.0.1.GA\seam-gen>seam new-action-page statelessSb home StatelessCalculator

          Now Refresh statelssSb, statelessSbEJB and statelessWeb in Eclipse and set ?Configure Buildpath? from statelessSbEJB (also see in 1.)

          Code for home.xhtml:

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          <html xmlns="http://www.w3.org/1999/xhtml"
          <ui:composition template="/WEB-INF/layout/template.xhtml">
           <ui:define name="body">
           <h1>Seam Generated Page named: "Calculator"</h1>
           <div><h:outputLabel for="start">Start age: </h:outputLabel></div>
           <div><h:inputText value="#{StatelessCalculator.start}"/><br /></div>
           <div><h:outputLabel>End age: </h:outputLabel></div>
           <div><h:inputText value="#{StatelessCalculator.end}"/><br /></div>
           <div><h:outputLabel>Growth Rate: </h:outputLabel></div>
           <div><h:inputText value="#{StatelessCalculator.growthrate}"/><br /></div>
           <div><h:outputLabel>saving: </h:outputLabel></div>
           <div><h:inputText value="#{StatelessCalculator.saving}"/><br /></div>
           <div><h:commandButton type="submit" value="Calculate" action="#{StatelessCalculator.calculate}"/></div>
           <div><h:outputText>Result: "#{StatelessCalculator.resultString}"</h:outputText></div>

          Code for StatelessCalculator.java:
          package org.jboss.business;
          import javax.ejb.Local;
          public interface StatelessCalculator {
           //seam-gen method
           public String doAction();
           //add additional interface methods here
           public String calculate ();
           public double calculate(int start, int end, double growth, double saving);
           public int getEnd();
           public void setEnd(int end);
           public double getGrowthrate();
           public void setGrowthrate(double growthrate);
           public double getSaving();
           public void setSaving(double saving);
           public int getStart();
           public void setStart(int start);
           public double getResult();
           public void setResult(double result);
           public String getResultString();
           public void setResultString(String resultString);

          Code for StatelessCalculatorAction.java:
          package org.jboss.business;
          import static org.jboss.seam.ScopeType.SESSION;
          import java.io.Serializable;
          import java.text.NumberFormat;
          import javax.ejb.Stateless;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Scope;
          public class StatelessCalculatorAction implements StatelessCalculator,
           Serializable {
           private int start = 25;
           private int end = 65;
           private double growthrate = 0.08;
           private double saving = 300.0;
           private double result = 0;
           private String resultString = null;
           private static final long serialVersionUID = 1L;
           // seam-gen method
           public String doAction() {
           return "success";
           // add additional action methods
           public double calculate(int start, int end, double growth, double saving){
           double tmp = Math.pow(1. + growthrate / 12., 12. * (end - start) + 1);
           return saving * 12. * (tmp - 1) / growth;
           public String calculate() {
           NumberFormat nf = NumberFormat.getInstance();
           result = calculate(start, end, growthrate, saving);
           resultString = nf.format(result);
           return "success";
           public int getEnd() {
           return end;
           public void setEnd(int end) {
           this.end = end;
           public double getGrowthrate() {
           return growthrate;
           public void setGrowthrate(double growthrate) {
           this.growthrate = growthrate;
           public double getSaving() {
           return saving;
           public void setSaving(double saving) {
           this.saving = saving;
           public int getStart() {
           return start;
           public void setStart(int start) {
           this.start = start;
           public double getResult() {
           return result;
           public void setResult(double result) {
           this.result = result;
           public String getResultString() {
           return resultString;
           public void setResultString(String resultString) {
           this.resultString = resultString;

          Finally ADD the Project to JBoss Server, start and see the result by typing http://localhost:8080/statelessSb in browser

          Have fun