07 April 2008

NetBeans6.1+EJB3+Struts [PART 3]

Now right click on MyApp-war, choose Properties->Frameworks->Add->Struts and press Ok and then Ok one more time.

If you right click MyApp-war, choose Properties and click on Frameworks you are going to notice that Struts Framework was added to the list of Used Frameworks.

Now in MyApp-war, Right Click->New->Other... and choose Struts in the Categories list.
And in
File Types list choose Struts Action.



Click Next > and enter the following information:
In
Class Name: BookForm
In
package: action

Click Finish and the FormBean will be created and the information will be written in the struts-config.xml

One more time in MyApp-war, Right Click->New->Other... and choose Struts in the Categories list.
And in
File Types list choose Struts Action.


Click Next > and enter the following information:

Class Name: BookCRUDAction
Package: action
Superclass: select in the dropdown MappingDispatchAction
Action Path
: /book.do
Click
Next >

In the second part of the Action Wizard type the following information:

Scope: Request
ActionFormBean Name: BookForm
Parameter: create



And hit the Finish button.

The BookCRUDAction is then opened in your editor window. The mapping for the newly created Action is also added in struts-config.xml.

Now change the signature of the method from:

public ActionForward customMethod(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception

to:

public ActionForward create(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception


This is done to be aligned with the information that was typed in the Parameter box while creating the Action class.

Copy and paste the entire method THREE more times so you will have the read, update and delete methods.

No comments: