Solved

dummy class in EJB

Posted on 2004-08-17
16
437 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What is JNDI datasource in spring 1 38
pairs challenge 5 44
Free Alternative to JIRA 4 55
compre toata in where clue oracle 4 41
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

705 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

15 Experts available now in Live!

Get 1:1 Help Now