dummy class in EJB

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.
LVL 2
sangeethaAsked:
Who is Participating?
 
girionisConnect With a Mentor Commented:
>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
 
girionisCommented:
Just hard code the values, no need to create a dummy class.

String myString = "hey";
int myInt = 10;
...
...
0
 
sangeethaAuthor Commented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
mmuruganandamCommented:
have ur EJB class as Bean managed instead of container managed.
Only container managed EJB will get the value from DB directly.
0
 
girionisConnect With a Mentor Commented:
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
 
sangeethaAuthor Commented:
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
 
mmuruganandamCommented:
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
 
girionisCommented:
And BTW I agree with mmuruganandam, it is always cleaner and neater to open a new question for a new problem :)
0
 
sangeethaAuthor Commented:
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
 
sangeethaAuthor Commented:
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
 
mmuruganandamConnect With a Mentor Commented:
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
 
girionisCommented:
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
 
sangeethaAuthor Commented:
:-)

>> 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
 
girionisCommented:
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
 
girionisCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.