【问题标题】:ATG - How to start creating a Hello World component and module example?ATG - 如何开始创建 Hello World 组件和模块示例?
【发布时间】:2014-01-23 11:02:48
【问题描述】:

我是 ATG 新手,我只能使用 JBoss 成功安装 ATG v10.2。
但是,由于在 ATG 中创建组件和模块可以通过不同的方式完成,所以我想知道模块和组件是否有任何“Hello World”示例。

我已经在谷歌上搜索过,但是互联网上出现的不同文章并没有按顺序详细地逐点提及。
因此,如果人们可以为新手详细说明步骤,那就太好了,因为我至少需要从一个示例开始,以后可以将其用作其他复杂示例的基础。

非常感谢大家!

注意:-
我也对 J2EE 和 MVC 有所了解,我可以在其中提交表单并将用户输入的数据保存到 DB,没有任何重大问题。
我现在也在阅读 ATG 页面开发人员指南。

【问题讨论】:

  • 感谢有趣的问题,我对 ATG 也很感兴趣,我想学习和安装这个框架。目前我正在使用 Symfony2.4 和 PHP 5.4。在谷歌中,许多文档可用于此框架,但对于 ATG 没有,您能帮助我或提供任何使用完整的链接吗?我想学习和使用 ATG 工作,我也知道 OOPS 概念,MVC,ORM。

标签: atg


【解决方案1】:

ATG 中有很多概念,这使得提出 Hello World 程序变得不那么困难。您的意思是创建一个 JSP 页面并像商业参考商店一样部署它吗?您想创建一个组件只是为了在 Dyn/Admin 中查看吗?你想创建一个 hello world 存储库吗?根据您想做什么,采取的方法会有所不同。

要使用 ATG,您不必知道如何在数据库中保存值。如果您使用 J2EE 和 MVC 经验来进行 ATG 编程,除非您以全新的思维开始,否则您可能会发现处理它并不困难,因为 ATG 中的情况非常不同。

@radimpe 介绍了如何创建一个 hello world droplet,我将展示如何创建一个简单的组件,以便可以在 Dyn/Admin 中查看它。

创建一个 HelloWorld 组件:它只出现在 DynAdmin 中 创建一个具有以下结构的 Eclipse 项目。

以下是上面截图中显示的每个文件的内容

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!");
    }
}

清单.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,然后单击搜索结果中列出的组件。

点击它进入组件页面,查看我们创建的属性及其在属性文件中给出的值。

您可以像这样观察日志 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() 中的 sysout 而产生的; 也可以给出其他方法,可以通过 dyn/admin 调用或者与其他组件交互。祝你好运。

来源:Creating a component in Oracle Commerce Platform

【讨论】:

  • 永远不要在您的代码中使用 sysout。始终酌情使用 logDebug/logInfo/logWarning/logError。
【解决方案2】:

检查http://www.asknsay.com/creating-new-atg-project-in-eclipse.html 以使用 Eclipse 从头开始​​在 atg 中创建新应用程序。它还介绍了如何在 JBOSS 6.1 中部署它。

【讨论】:

    【解决方案3】:

    你也可以看看下面的页面。它很好地解释了 What Actualy 是一个组件的概念以及我们如何使用它。 http://learnoracleatg.blogspot.in/2014/10/art108-extending-out-of-box-components.html

    您也可以通过按导航栏上的“基础知识”按钮从基础开始。它很好地解释了这些概念..

    【讨论】:

    • 你可以稍微解释一下并添加参考,而不只是提及参考!
    【解决方案4】:

    这是一个相当广泛的话题,一般来说,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 页面和 CLASS 文件之间映射的属性文件(即,您在液滴名称中引用它)

    文件:/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);
            }
    }
    

    希望这足以让您入门。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 2023-04-11
      • 2012-08-03
      • 2014-07-24
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多