Struts Portlet Database Interaction Copyright © 2000-2006 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Struts Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Struts Portlet Adding an Action Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without.
Chapter 1 Getting Started with Access Databases. Objectives Identify Good Database Design Create a Table and Define Fields in a New Blank Database Change.
JSF Portlet Backing Beans and UI Components Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Liferay, SSO and LDAP - Integration Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
CONTENTS  ABSTRACT  INTRODUCTION  HARDWARE & SOFTWARE REQUIREMENTS  PROBLEM ANALYSIS  MODULES DESCRIPTION  TABLE DESIGN  ER DIAGRAM  SCREEN SHOTS.
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson,
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
Introduction to Liferay Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written.
Basic Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
JSF Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Themes & Layout Tutorial Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. M I C R O S O F T ® Preparing for Electronic Distribution Lesson 14.
1 Working with MS SQL Server. 2 Objectives You will be able to Use Visual Studio for GUI based interactive access to a Microsoft SQL Server database.
Ext Environment Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Transforming the e-Concordiensis Edward Maas Senior Capstone Design Project Advisor: Professor Cass.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith.
Struts Portlet Redirect Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written.
Your Name Here See Page Notes for Info about Hyperlinks.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
Copyright  Oracle Corporation, All rights reserved. 4 CMIS Powell Oracle Designer: Creating the Database Design CMIS Powell.
Ext Environment Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
JSF Introduction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Basic Setup Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 2 – Viewing and.
LDAP Authentication Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Application Specific Module Tutorial Akos Balasko 02/07/
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
Content Management System Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
JSP Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
MySQL Getting Started BCIS 3680 Enterprise Programming.
1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith Mast, and Mary Anne.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Three Instructor:
By Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson, Linda Lau, Jerri Williams Chapter 6 Action and Specialized Queries 1.
Modal Dialogs. What is a Modal Dialog? A modal dialog is a separate window that remains in focus until it is closed by the user. During this time the.
Database Connection Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
MySQL, JavaBeans and File Upload
What is MySQL? MySQL is a relational database management system (RDBMS) based on SQL (Structured Query Language). First released in January, Many.
1 Manufacturing Operations Center 16. Demo Data Customization Scripts APAC Training, Feb-Mar, 2010.
Android - SQLite Database 12/10/2015. Introduction SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with.
Managing Database With Oracle Replacement for Ch10 COP 4708.
Basic Portlet Copyright © 2000 – 2007 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Required Tools Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Java Object-Relational Layer Sharon Diskin GUS 3.0 Workshop June 18-21, 2002.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Required Tools Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission from.
3 A Guide to MySQL.
Y.-H. Chen International College Ming-Chuan University Fall, 2004
Copyright © Liferay, Inc.
Copyright © Liferay, Inc.
4Schools Adding a Web Page.
JSF Portlet Message Bundles
Completing the Primary Reference portion of the Student Profile
Presentation transcript:

Struts Portlet Database Interaction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission from Liferay, Inc.

Objective The goal of this tutorial is to add Database interaction to the Struts Portlet. 1.Create a database structure –service.xml 2.Auto generating the Service Layer code and SQL –build.xml – build-service 3.Modifying MySQL to include new table –portal-tables.sql 4.Create method to add record to the database –BookLocalServiceImpl.java 5.Update existing files –AddBookAction.java –Init.jsp –success.jsp 6.Retrieve Records from the Database for display –success.jsp

service.xml Locate the current service.xml file in the C:\training\liferay\ext\ext-ejb\ directory Move service.xml to the reports directory: …\ext\ext-ejb\src\com\ext\portlet\reports Go back to the \ext\ext-ejb\ directory Create a new service.xml file in …\ext\ext-ejb\

service.xml contents

Overview of service.xml package-path="com.ext.portlet“ is the path that the class will generate to C:\Training\liferay\ext\ext-ejb\src\com\ext\portlet is used to generate a new package called “com.ext.portlet.library” in your source directory C:\Training\liferay\ext\ext-ejb\src\ is the Database table you want to create and then link up to in the code

Checkpoint The generation of the service layer code is all automated. Navigate to the …\ext\ext-ejb\ directory Make sure your service.xml file is formatted correctly

Generate Service Layer Code 1.Click Start  Run… 2.Type cmd and press Enter 3.Navigate to C:\Training\liferay\ext\ext-ejb\ 4.Type ant build-service in the command prompt.

Generated Service Layer Results

portal-tables.sql Updated As part of the auto generation, portal-tables.sql was updated to include our new Book table portal-tables.sql is located here: …\ext\sql\portal-tables.sql This was added to portal-tables.sql: create table Book ( bookId VARCHAR(75) not null primary key, title VARCHAR(75) null ); Remember to click Refresh on the “ext” directory after running build-service to see the newly generated files!

Update our database called “training” 1.Click Start  Run… 2.Type cmd and press Enter 3.Type mysql and press Enter 4.Type use training; and press Enter 5.Type show tables; and press Enter Confirm that the “Book” table does not exist yet

Updating Our Database Copy the generate SQL code: create table Book ( bookId VARCHAR(75) not null primary key, title VARCHAR(75) null ); Paste it into the Cmd prompt

Confirm the Update Type show tables; and press Enter Confirm that the “Book” table exist now

Creating the Service Layer Class Navigate to: C:\Training\liferay\ext\ext-ejb\src\com\ext\portlet\library\service\impl\ Open BookLocalServiceImpl.java We are going to add the database insert method to this service layer class.

BookLocalServiceImpl.java Content package com.ext.portlet.library.service.impl; import com.ext.portlet.library.model.Book; import com.ext.portlet.library.service.persistence.BookUtil; import com.ext.portlet.library.service.spring.BookLocalService; import com.liferay.counter.service.spring.CounterServiceUtil; import com.liferay.portal.PortalException; import com.liferay.portal.SystemException; public class BookLocalServiceImpl implements BookLocalService { public Book addBook(String userId, String title) throws PortalException, SystemException { Book book = BookUtil.create(Long.toString(CounterServiceUtil.increment(Book.class.getName()))); book.setTitle(title); return BookUtil.update(book); }

Regenerate Service Layer Code 1.Click Start  Run… 2.Type cmd and press Enter 3.Navigate to C:\Training\liferay\ext\ext-ejb\ 4.Type ant build-service in the command prompt. 5.The wrapper classes have been generated.

Regenerated Service Layer Results

Update Existing Files AddBookAction.java package com.ext.portlet.library.action; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import com.ext.portlet.library.service.spring.BookLocalServiceUtil; import com.liferay.portal.struts.PortletAction; public class AddBookAction extends PortletAction { public void processAction( ActionMapping mapping, ActionForm form, PortletConfig config, ActionRequest req, ActionResponse res) throws Exception { String bookTitle = req.getParameter("book_title"); if ( "".equals(bookTitle) || bookTitle == null ) { setForward(req, "portlet.ext.library.error"); } else { BookLocalServiceUtil.addBook(req.getRemoteUser(),bookTitle); setForward(req, "portlet.ext.library.success"); }

Update Existing Files init.jsp Adding these imports give any of the extended JSP files such as view.jsp and success.jsp access to the generated service layer classes. The ArrayList and Iterator classes will be used later.

Deploy the Files to Tomcat Deploy files to Tomcat once you are finished Open up a cmd prompt –Click “Start”, “Run” and then type “cmd” Navigate to your ext directory and then type “ant deploy” …\ext>ant deploy

Final Steps 1.Restart Tomcat 2.Open up a new browser and type LOGIN: PASSWORD: test

Verify the data in the database 1.Click Start  Run… 2.Type cmd and press Enter 3.Type mysql and press Enter 4.Type use training; and press Enter 5.Type select * from book; and press Enter

Checkpoint Update the existing JSP files to use the generated Service and Persistence Layer Classes Added a book title in the Struts Portlet Confirmed that the book title was added successfully in to the database

Retrieving Records Retrieving records from the data base will include updating a Service Layer Class and regenerating the wrapper classes We will add a getAll() method to BookLocalServiceImpl.java Regenerate the Service and Persistence Layer classes We will update success.jsp to retrieve and display the book title records

BookLocalServiceImpl.java Add an getAll() method public List getAll() throws PortalException, SystemException { return BookUtil.findAll(); } import java.util.List; Regenerate the Service Layer to create a wrapper class for getAll()

Regenerated Service Layer Results

sucess.jsp updates Add code to display all book titles ArrayList books = (ArrayList)BookLocalServiceUtil.getAll(); Book book = new Book(); Loop through the book titles and display

success.jsp HTML code "> Book Listings Book Id Book Title "> <% Iterator itr = books.iterator(); while (itr.hasNext()) { book = (Book)itr.next(); %> <% } %>

Deploy the Files to Tomcat Deploy files to Tomcat once you are finished Open up a cmd prompt –Click “Start”, “Run” and then type “cmd” Navigate to your ext directory and then type “ant deploy” …\ext>ant deploy

Final Steps 1.Restart Tomcat 2.Open up a new browser and type LOGIN: PASSWORD: test

Review Key Concepts Create your table structure in service.xml Generate Service and Persistence Layer Classes with Ant’s Build-Service Add methods to the Impl Service Class to generate a wrapper method in the Util Class Add code in your JSP file to display data

Revision History Jerry Niu9/7/2006-9/11/2006 Slide create and updates