user1900662
user1900662

Reputation: 299

How to send a Struts Action Form object to EJB session's bean method?

I have Struts action form Object called register i need to send the action form object to a session bean method as parameter so I done the following

public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception 
{
    Register register = (Register)form;
    home.registerUser(register);
    return mapping.findForward("success");
}

Where home is the stub to access session bean and registerUser is the session bean method.

Now the problem is i am not able to reference the Register class in the session bean.

Please help me how to send the register object to the session bean.

Upvotes: 0

Views: 1049

Answers (2)

OCJP
OCJP

Reputation: 1033

First create Entity class object related to your register data and add the form data onto the received object and send it back to EJB for storing at the database.

    Register register = (Register)form;        
    Customer customer = new Customer();        
    customer.setUsername(register.getName());
    customer.setPassword(register.getPassword());
    customer.setEmail_id(register.getEmailid());
    String result = home.registerUser(customer);

register - It is the ActionForm Object.

customer - Entity class object for the registration table.

home - It is the Home Interface reference object.

registerUser - It is the method in the session bean which contain code to perist the data onto the database.

Upvotes: 1

Ravindra Gullapalli
Ravindra Gullapalli

Reputation: 9158

In Register form, create a method registerUser and from there you call your SessionBean method home.registerUser(this). Now, In action's execute method call register.registerUser().

Upvotes: 0

Related Questions