Link to home
Start Free TrialLog in
Avatar of sangeetha
sangeetha

asked on

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.
Avatar of girionis
girionis
Flag of Greece image

Just hard code the values, no need to create a dummy class.

String myString = "hey";
int myInt = 10;
...
...
Avatar of sangeetha
sangeetha

ASKER

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.
have ur EJB class as Bean managed instead of container managed.
Only container managed EJB will get the value from DB directly.
SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And BTW I agree with mmuruganandam, it is always cleaner and neater to open a new question for a new problem :)
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.
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :)
:-)

>> 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.
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.