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

Slides:



Advertisements
Similar presentations
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
Advertisements

JSP and web applications
Apache Tiles.
Struts Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Servlets, JSP and JavaBeans Joshua Scotton.  Getting Started  Servlets  JSP  JavaBeans  MVC  Conclusion.
Web Services Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
JSF Portlet Backing Beans and UI Components Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in.
Short Portlet Programming Guide in P-Grade (Gridsphere) environment G. Hermann.
JLab Lattice Portal – Data Grid Web Service Ying Chen, Chip Watson Thomas Jefferson National Accelerator Facility.
Development Configuration Guide Using NetBeans IDE
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Java Server Pages (JSP)
Apache Struts Technology
A Blackboard Building Block™ Crash Course for Web Developers
 2003 Prentice Hall, Inc. All rights reserved. Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
Liferay, SSO and LDAP - Integration Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without.
Struts1 Apache Struts Dr Jim Briggs. Struts2 What is Struts? Struts is an open source framework for building Java web applications Supports MVC/Model.
Objectives:1. Investigate the Web application deployment descriptor 2. Install and deploy Tomcat and struts 3. Design and deploy a struts application Struts.
Apache Struts Technology A MVC Framework for Java Web Applications.
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.
Struts Portlet Database Interaction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without.
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.
Struts 2.0 an Overview ( )
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Ext Environment Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Transforming the e-Concordiensis Edward Maas Senior Capstone Design Project Advisor: Professor Cass.
Struts Portlet Redirect Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Introducing.
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,
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
Ext Environment Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission.
JSF Introduction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
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.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
1 ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 1 Building Portlets with ColdFusion Pete Freitag Foundeo, Inc.
How to Build a Struts Application with JBuilder 9.
LDAP Authentication Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Topic Java EE installation (Eclipse, glassfish, etc.) Eclipse configuration for EE Creating a Java Web Dynamic Project Creating your first servlet.
Application Specific Module Tutorial Akos Balasko 02/07/
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
J2EE Struts 1 3 Struts: Introduction 1 4 Once you’ve coded a lot of JSP applications, you find yourself doing a lot of repetitive things. Also,
Content Management System Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission.
JSP Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
Database Connection Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
11 Copyright © 2004, Oracle. All rights reserved. Customizing Actions.
Basic Portlet Copyright © 2000 – 2007 Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Struts Framework Day-2 Ashok Chakravarti. DataSource Usage Sample Struts-config.xml …
Required Tools Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
12 Copyright © 2004, Oracle. All rights reserved. Using ADF Struts Components.
Apache Struts Technology A MVC Framework for Java Web Applications.
V Web Tier Architecture MVC and Struts. v First, there were servlets And things were good Faster than CGI programs More scalable with built-in.
Required Tools Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission from.
Tutorial on Science Gateways, Roma, Riccardo Rotondo Web Application Development Introduction to application servers, web applications and portlets.
Introduction to portlet development Carla Carrubba INFN Dpt. Of Catania Giuseppina Inserra
Copyright © Liferay, Inc.
Copyright © Liferay, Inc.
Unit 6-Chapter 2 Struts.
JSF Portlet Message Bundles
Presentation transcript:

Struts Portlet Adding an Action 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 an Action Class to the Struts Portlet and to display an success page 1.Define the Action –struts-config.xml –tiles-defs.xml 2.Update existing JSP files –view.jsp –init.jsp 3.Create success and error JSP files –error.jsp –Success.jsp 4.Create Action Class to process submit –AddBookAction.java

Review Key Concepts What are the main differences between a JSP Portlet and a Struts Portlet? –JSP Portlet goes directly to a JSP –Struts Portlet has an page flow Where does the page flow get defined? struts-config.xml – define the page flow tiles-defs.xml – define the page layout

struts-config.xml struts-config.xml defines the page flow Lets add another path to the page flow? What is type? It is a Struts defined way of passing control to the AddBookAction class

struts-config.xml Lets look at the forward nodes What is name? It the unique identifier for that forward node What is path? This is your link to the tiles-def.xml

tiles-defs.xml tiles-defs.xml defines the page layout Lets add the error and success paths

init.jsp Update init.jsp in the library directory …\ext\ext-web\docroot\html\portlet\ext\library\init.jsp Remove the following Add commonly used variables and declarations here! init.jsp should only contain this line: Review: What does including this file give us? …\portal\portal-web\docroot\html\common\init.jsp This will gives us access to the Liferay tag libraries.

view.jsp Add a book entry to the Library: "> " method="post" name=" fm"> Book Title: book_title" size="20" type="text" value=""> fm);">

view.jsp What does struts_action do? Struts_action is the ActionMapping to the struts-config.xml path value="/ext/library/add_book –This is the link to the to the ActionPath Review –What does struts_action connect us to? –It connects us to the struts-config.xml

error.jsp error.jsp Path: ext-web/docroot/html/portlet/ext/library/error.jsp error.jsp Contents: ERROR!

success.jsp success.jsp Path: ext-web/docroot/html/portlet/ext/library/success.jsp success.jsp Contents: SUCCESS!

AddBookAction.java AddBookAction Class Path: ext/ext-ejb/src/com/ext/portlet/library/action/AddBookAction.java AddBookAction Class Contents: package com.ext.portlet.library.action; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.liferay.portal.struts.PortletAction;

AddBookAction.java 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 ( null == bookTitle || "".equals(bookTitle) ) { setForward(req, "portlet.ext.library.error"); } else { setForward(req, "portlet.ext.library.success"); } public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest req, RenderResponse res) throws Exception { if (getForward(req) != null && !getForward(req).equals("")) { return mapping.findForward(getForward(req)); } else { return mapping.findForward("portlet.ext.library.view"); }

AddBookAction.java Main code: String bookTitle = req.getParameter("book_title"); if ( null == bookTitle || "".equals(bookTitle) ) { setForward(req, "portlet.ext.library.error"); } else { setForward(req, "portlet.ext.library.success"); } Where does book_title come from? It comes from to the view.jsp form What is the if/else statement doing? It is detecting if the book title was submitted According to the detected state, it sets the forward path

AddBookAction.java Error forward path: if ( null == bookTitle || "".equals(bookTitle) ) { setForward(req, "portlet.ext.library.error"); } else { setForward(req, "portlet.ext.library.success"); } Success forward path: if ( null == bookTitle || "".equals(bookTitle) ) { setForward(req, "portlet.ext.library.error"); } else { setForward(req, "portlet.ext.library.success"); } Error and Success forward path is linked to the the path in struts-config.xml

Struts Action Mapping struts-config.xml path=/ext/library/add_book type=…AddBookAction AddBookAction setForward=...library.success success.jsp /portlet/ext/library/success.jsp error.jsp /portlet/ext/library/error.jsp view.jsp Submit to struts_action= /ext/library/add_book

Deploy the Files to Tomcat Once you have finished modifying all of the files, deploy them to Tomcat 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

Check the Tomcat Directory Verify that the files were deployed to Tomcat Go to …\tomcat\webapps\ROOT\WEB-INF and open portlet-ext.xml, liferay-portlet-ext.xml, struts-config-ext.xml and tiles-defs-ext.xml and check to see that the files were deployed correctly. Next, go to …\tomcat\webapps\ROOT\html\portlet\ext\library and open up view.jsp to see that it was deployed correctly

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

Key Concepts portlet-ext.xml struts-config.xml tiles-defs.xml view.jsp AddBookAction struts-config.xml tiles-defs.xml success.jsp struts-config.xml

portlet-ext.xml view-action /ext/library/view struts-config.xml path=/ext/library/view forward=portlet.ext.library.view tiles-defs.xml name=portlet.ext.library.view value=/portlet/ext/library/view.jsp view.jsp /portlet/ext/library/view.jsp

struts-config.xml path=/ext/library/add_book type=com.ext.portlet.library.action.AddBookAction tiles-defs.xml name=portlet.ext.library.sucess value=/portlet/ext/library/sucess.jsp sucess.jsp /portlet/ext/library/success.jsp struts-config.xml forward name = portlet.ext.library.success path=portlet.ext.library.success AddBookAction setForward(req, portlet.ext.library.success);

Objectives Now that weve finished redirecting with an action. Lets make the success page display the submitted value. Update success.jsp to display the submitted value

success.jsp success.jsp Path: ext-web/docroot/html/portlet/ext/library/success.jsp success.jsp Contents: <% String bookTitle = request.getParameter("book_title"); %> Book Title:

success.jsp Add init.jsp This will give us access to the init.jsp located here: …\ext\ext-web\docroot\html\portlet\ext\library\init.jsp Get the submitted value String bookTitle = request.getParameter("book_title"); Display the submitted value in success.jsp

Deploy the Files to Tomcat Once you have finished modifying success.jsp, deploy it to Tomcat 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

Review of Key Concepts portlet-ext.xml struts-config.xml tiles-defs.xml view.jsp AddBookAction struts-config.xml tiles-defs.xml success.jsp struts-config.xml

portlet-ext.xml view-action /ext/library/view struts-config.xml path=/ext/library/view forward=portlet.ext.library.view tiles-defs.xml name=portlet.ext.library.view value=/portlet/ext/library/view.jsp view.jsp /portlet/ext/library/view.jsp

struts-config.xml path=/ext/library/add_book type=com.ext.portlet.library.action.AddBookAction tiles-defs.xml name=portlet.ext.library.sucess value=/portlet/ext/library/sucess.jsp sucess.jsp /portlet/ext/library/success.jsp struts-config.xml forward name = portlet.ext.library.success path=portlet.ext.library.success AddBookAction setForward(req, portlet.ext.library.success);

Review of struts-config.xml struts-config.xml defines the page flow Lets add another path to the page flow? What is type? It is a Struts defined way of passing control to the AddBookAction class

Revision History Jerry Niu9/7/2006-9/8/2006 Slide create and updates Jerry Niu9/27/2006 Updated tomcat path Jerry Niu9/28/2006 Updated AddBookAction with back arrow fix, added forward to render Jerry Niu10/4/2006 Update imports on AddBookAction