2014-01-06 30 views
4

我是ATG的新手,我只能用JBoss成功安裝ATG v10.2。
但是,由於在ATG中創建組件和模塊可以用不同的方式完成,所以我想知道是否有模塊和組件都有「Hello World」示例。ATG - 如何開始創建Hello World組件和模塊示例?

我已經在Google中搜索過,但互聯網上出現的不同文章並沒有按照順序的方式詳細提及點的細節。
因此,如果人們可以詳細說明新手的步驟,那將會很棒,因爲我至少需要開始使用一個示例,稍後可以將其用作其他複雜示例的基礎。

非常感謝每一個在那裏!

注: -
我也知道J2EE和MVC在一定程度上,在那裏我可以提交表單,並保存用戶輸入數據到數據庫,沒有任何顯著的問題。
我現在也在瀏覽ATG Page Developer Guide。

+0

感謝有趣的問題,我對ATG也很有興趣,我想學習和安裝這個框架。目前我正在使用Symfony2.4和PHP 5.4。在谷歌許多文件可用於這個框架,但對於ATG什麼都沒有,你能幫我或爲我提供任何使用完整的鏈接?我想學習和使用ATG,我也知道OOPS概念,MVC,ORM。 – Sid

回答

5

ATG中有這麼多的概念,使得提出Hello World程序有點困難。你的意思是創建一個JSP頁面並將其部署爲商業參考存儲?你想創建一個組件,只需在Dyn/Admin中查看?你想創建一個hello世界知識庫嗎?取決於你想做什麼,採取的方法會有所不同。

要使用ATG,您不必知道在數據庫中保存值。如果您使用J2EE & MVC體驗來開發ATG編程,除非您開始思路清新,否則您可能會發現很難應付它,因爲ATG中的事情非常不同。

正如@radimpe介紹了創建一個hello世界的液滴,我將展示如何創建一個簡單的組件,以便它可以在Dyn/Admin中查看。

創建HelloWorld組件:剛剛出現在DynAdmin中 使用以下結構創建Eclipse項目。

Elipse project structure

以下是對每個在上述屏幕截圖所示

HelloWorldComponent.java
package com.buddha.components; 

import atg.nucleus.GenericService; 
import atg.nucleus.ServiceException; 

public class HelloWorldComponent extends GenericService { 

    public String firstStr = "Dummy Value"; /* This value will be overwritten */ 

    public String getFirstStr() { 
     return firstStr; 
    } 

    public void setFirstStr(String firstStr) { 
     this.firstStr = firstStr; 
    } 

    @Override 
    public void doStartService() throws ServiceException { 
     super.doStartService(); 
     System.out.println("Hello ATG Component!"); 
    } 

    @Override 
    public void doStopService() throws ServiceException { 
     super.doStopService(); 
     System.out.println("Hello ATG Component! Stops now!"); 
    } 
} 

的Manifest.MF
Manifest-Version: 1.0 
ATG-Required: DafEar.Admin 
ATG-Config-Path: config/ 
ATG-Class-Path: ./bin/ 

HelloWorldComponent.properties該文件的內容

$class=com.buddha.components.HelloWorldComponent 
firstStr=HelloWorld 

構建項目並將項目文件夾複製到$ {DYNAMO_ROOT}並運行以下命令以生成項目的ear文件並將其部署到您的jboss服務器中。

runAssembler.bat -jboss HelloWorld.ear -m EXP_HelloATGComponentWorld 

導航至Dyn/Admin和搜索組件HelloWorldComponent和點擊搜索結果中列出的組件。

SearchResults of the component we have just created

點擊它去組件頁面,看看我們已經創建了屬性和屬性給定文件的價值。 Component Property we have created

您可以觀察到日誌中這樣的事情 21:53:00,485 INFO [stdout] (http-/0.0.0.0:8080-1:ipaddr=127.0.0.1;path=/dyn/admin/nucleus//com/buddha/components/HelloWorldComponent;sessionid=gT4bmHj5WKs1Rf85GN0Z+9Qu) Hello ATG Component!因爲在我們doStartService)的系統輸出(的產生這條線; 你也可以給其他方法,可以通過dyn/admin或與其他組件交互。好運。

來源:Creating a component in Oracle Commerce Platform

+0

從來沒有我們sysout在你的代碼。根據情況始終使用logDebug/logInfo/logWarning/logError。 – radimpe

5

這是一個相當廣泛的話題,一般來說,Hello World的例子只會讓你開始在屏幕上顯示一些文本。您的大部分前端互動都會發生在FormHandlersDroplets之間,其中Droplet會讓您在屏幕上顯示Hello World文字。所以讓我們從這個開始。

<%-- JSTL --%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 

<%-- DSP --%> 
<%-- This tag library represents the ATG tags --%> 
<%@ taglib prefix="dsp" uri="http://www.atg.com/taglibs/daf/dspjspTaglib1_0" %> 

<%-- All, non-static includes will have a wrapping page tag --%> 
<dsp:page> 
    <%-- A droplet is almost like a servlet, and here you include the name of the droplet you want to call --%> 
    <dsp:droplet name="/com/acme/droplet/HelloWorldDroplet"> 
    <%-- An 'output parameter' matches the name of the 'service parameter' in your droplet. You can have multiple of these --%> 
    <dsp:oparam name="output"> 
     <%-- The 'param' matches the name of the 'setParameter' in your droplet and can also be assigned to a jstl variable below --%> 
     Hello <dsp:valueof param="toWhom" /> 
    </dsp:oparam> 
    </dsp:droplet> 
</dsp:page> 

現在創建一個'組件'。這是屬性文件,將JSP頁面和類文件之間的映射(即你在液滴名稱引用此。)

文件:/com/acme/droplet/HelloWorldDroplet.properties

$class=com.acme.droplet.HelloWorldDroplet 
$scope=global 

現在創建您的Java文件:(/com/acme/droplet/HelloWorldDroplet.java)

public class HelloWorldDroplet extends DynamoServlet { 

    public void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws ServletException, IOException { 
      //This will allow you to pass a parameter to the droplet eg: hello.jsp?who=Peter 
     String who = pRequest.getParameter("who"); 

     //Do a check on whether to display the default value or the one passed in 
     if (StringUtils.isEmpty(who)) { 
      //'toWhom' is the name of the param on the JSP page 
      pRequest.setParameter("toWhom", "World"); 
     } else { 
      pRequest.setParameter("toWhom", who); 
     } 
     //'output' is the name of the 'oparam' on the JSP page. 
     pRequest.serviceParameter("output", pRequest, pResponse); 
     } 
} 

希望這將足以讓你開始。