Solved

dummy class in EJB

Posted on 2004-08-17
16
439 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
  • 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
 
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
3 Use Cases for Connected Systems

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

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now