Solved

dummy class in EJB

Posted on 2004-08-17
16
449 Views
Last Modified: 2013-11-24
How to create a dummy class in EJB, instead of getting the values from database?

I need it to input the data's into my struts Forms.

Any ideas/examples ?

thanks.
0
Comment
Question by:sangeetha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 3
16 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11819130
Just hard code the values, no need to create a dummy class.

String myString = "hey";
int myInt = 10;
...
...
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11819147
Mmmm.. Later, i have to use DB, thats why i asked for dummy class.

How can i create a dummy class in EJB and use it in my struts JSP.

Thanks for your reply.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 11819157
have ur EJB class as Bean managed instead of container managed.
Only container managed EJB will get the value from DB directly.
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 35

Assisted Solution

by:girionis
girionis earned 200 total points
ID: 11819174
Just create any class:

public class MyClass
{
    String myString;
    int myInt;
    public MyClass(String myString, int myInt)
    {
        this.myString = myString;
        this.myInt = myint;
    }

    public void setString(String myString)
    {
        this.myString = myString;
    }

    public String getString()
    {
        return myString;
    }

    ....
    ....
}

Then use it in your EJB like any other normal class:

MyClass clazz = new MyClass("hello", 10);
...
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11819307
Fine.... I think instead of asking a new Question, i will ask here itself. (I increased the points to 250).

I have ShowList.jsp as follows:

                             
 ----------------------            ----------------------
| SearchInList.jsp   |         |    AddToList.jsp     |
|                           |         |                            |
 ----------------------            ----------------------
  -----------------------------------------------------
|                                                                   |
|            show the list here                              |
|                                                                   |
|                                                                   |
  -----------------------------------------------------

As the JSP name describes, each has different operations and the two JSP's are included in ShowList.jsp. I have seperate Form-Bean and Form-Action for SearchInList Form and AddToList Form.

For displaying the ShowList, I need that *dummy* class.

I did nothing but to set and get the fields in Form-Bean and redirecting in my Form-Action.

Am i proceeding in the right direction ? Any corrections/suggestions to improve.

Thanks for your patience.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 11819332
if you are including the SearchInList.jsp and AddToList.jsp in the ShowList.jsp, then why do you need the *dummy* class.

It is always a better idea to have a different question opened for every new question.  just a suggestion.


Regards,
Muruga
0
 
LVL 35

Accepted Solution

by:
girionis earned 200 total points
ID: 11819357
>I did nothing but to set and get the fields in Form-Bean and redirecting in my Form-Action.
>
>Am i proceeding in the right direction ?

I guess the Form-Bean represents the HTML form presented to the user. Then yes, this is the right way to do it. In the Form-Action you read all the values from the form and then create the dummy classes with this data.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11819367
And BTW I agree with mmuruganandam, it is always cleaner and neater to open a new question for a new problem :)
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11819430
SearchInList.jsp and AddToList.jsp contains just 2 text fields and 2 drop-down boxes.

Consider i have no DB. I want to show 'something' in the ShowList.jsp ( in 'show the list here' place of my diagram ).

What procedure (methods, actions, re-direction, etc) should i follow to make SearchInList.jsp and AddToList.jsp work properly in my ShowList.jsp ?

>> I guess the Form-Bean represents the HTML form presented to the user.

Form-Bean represents getter, setter methods and validate() method for the FORM fields.

Thanks for your responses - girinois and muruganandam.
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11819437
I will post new Questions from next time. :-)

Please bare with me if my questions sounds stupid. I am quite new for struts and ejb concepts.
0
 
LVL 9

Assisted Solution

by:mmuruganandam
mmuruganandam earned 50 total points
ID: 11819478
Just hard code the getter value for time being in order to get your list populated.
validate() method is to validate all your inputs in the server (validator framework)

>>I will post new Questions from next time. :-)
Great

>>Please bare with me if my questions sounds stupid. I am quite new for struts and ejb concepts.
You can post any kind of question.  EE is meant to help you people resolving their problems
But you should not expect full code (though you are not, just an alert)
0
 
LVL 35

Expert Comment

by:girionis
ID: 11819479
How do you pass the values of the form? And how do you create your dummy class? In the place where you read the values you should also be creating your dummy classes.

Ps. Do not worry about the questions you ask. I used to ask loads of "obvious" questions when I started learning java :)
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11820063
:-)

>> How do you pass the values of the form? And how do you create your dummy class?

I am not passing the values anywhere till now. I need it to pass to a class (right?) that displays the *List* according to the input given in the SearchInList.jsp or AddToList.jsp

i will post a new Q for this.

Meanwhile, could you please tell me why i get this error:

javax.servlet.jsp.JspException: Cannot find bean error in any scope

in this place:

<html:messages id="error">
  <tr><bean:write name="error"/></tr>
</html:messages>

I try to print the error, if any. (It worked previously, after i rename some files, i am getting this error.) What could be the reason.

Thanks.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11820119
I haven't used Struts for a while so I am not sure I remember everything correctly. The concept is that in your validator you validate and then you pass control in your action class (or controller in Spring). In there you read the values from the form and then you create the objects you want (your dummy classes). Then add them all in a hashtable and pass this hashtable along with the request to your jsp page. Then in your jsp page read this hashtable (are you using any taglig?) extract the values and show the list.

>javax.servlet.jsp.JspException: Cannot find bean error in any scope
>
>in this place:
>
><html:messages id="error">
>  <tr><bean:write name="error"/></tr>
></html:messages>

I am not sure... It is probably trying to look for a bean named "error" but it can't find it. Check if the syntax you are using is correct. Also check if you have defined a bean named "error" in your servlet config file.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11820128
:)
0
 
LVL 2

Author Comment

by:sangeetha
ID: 11820176
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question