Liferay7开发文档_3.4.6整合在一起

您已经从后端创建了一个完整的数据驱动应用程序。现在研究如何整合。

THE ENTRY

首先,在Service Builder的配置文件中定义了您的模型service.xml。主要是Entry对象:

<entity local-service="true" name="Entry" uuid="true">

    <!-- PK fields -->

    <column name="entryId" primary="true" type="long" />

    <!-- Group instance -->

    <column name="groupId" type="long" />

    <!-- Audit fields -->

    <column name="companyId" type="long" />
    <column name="userId" type="long" />
    <column name="userName" type="String" />
    <column name="createDate" type="Date" />
    <column name="modifiedDate" type="Date" />
    <column name="name" type="String" />
    <column name="email" type="String" />
    <column name="message" type="String" />
    <column name="guestbookId" type="long" />

    <finder name="G_G" return-type="Collection">
        <finder-column name="groupId" />
        <finder-column name="guestbookId" />
    </finder>
</entity>

接下来,创建一个服务实现类EntryLocalServiceImpl,定义如何获取和存储条目。 Every field you defined was accounted for in the addEntry method.

public Entry addEntry(long userId, long guestbookId, String name, String email,
        String message, ServiceContext serviceContext)
        throws PortalException {

        long groupId = serviceContext.getScopeGroupId();

        User user = userLocalService.getUserById(userId);

        Date now = new Date();

        validate(name, email, message);

        long entryId = counterLocalService.increment();

        Entry entry = entryPersistence.create(entryId);

        entry.setUuid(serviceContext.getUuid());
        entry.setUserId(userId);
        entry.setGroupId(groupId);
        entry.setCompanyId(user.getCompanyId());
        entry.setUserName(user.getFullName());
        entry.setCreateDate(serviceContext.getCreateDate(now));
        entry.setModifiedDate(serviceContext.getModifiedDate(now));
        entry.setExpandoBridgeAttributes(serviceContext);
        entry.setGuestbookId(guestbookId);
        entry.setName(name);
        entry.setEmail(email);
        entry.setMessage(message);

        entryPersistence.update(entry);

        return entry;
}

请注意,您在Service Builder中描述的所有字段(包括uuid)都在这里保存。

添加获取条目的方法:

    public List<Entry> getEntries(long groupId, long guestbookId) {
        return entryPersistence.findByG_G(groupId, guestbookId);
    }

    public List<Entry> getEntries(
        long groupId, long guestbookId, int start, int end, OrderByComparator<Entry> obc) {

        return entryPersistence.findByG_G(groupId, guestbookId, start, end, obc);
    }

    public List<Entry> getEntries(long groupId, long guestbookId, int start, int end)
        throws SystemException {

        return entryPersistence.findByG_G(groupId, guestbookId, start, end);
    }

service.xml定义groupIdguestbookId作为所述两个finder字段,在这些方法中调用持久层。

在这些工作后,Service Builder会将您的实现类方法反向写入到接口。然后,在portlet类中,创建了对Service Builder生成的服务类的引用,并使用这些引用访问该服务以添加条目:

_entryLocalService.addEntry( serviceContext.getUserId(), guestbookId, 
    userName, email,message, serviceContext);

最后,您将所有这些内容封装在一个用户界面中,用户界面允许用户输入他们想要的信息,并显示他们输入的数据。

现在您已经构建了应用程序,并且了解清楚它是如何工作的,该进行测试了。

部署和测试应用程序

  1. Drag and drop the guestbook-api module onto the server.
  2. Drag and drop the guestbook-service module onto the server.
  3. Look for the STARTED messages from the console.
  4. Go to your Liferay Portal instance at localhost:8080 in your browser to test your updated application.
  5. Click Add Entry.
  6. Enter a Name, Message, and Email Address.
  7. Click Submit.
  8. Verify that your entry appears.

留言 - 入门test.png

图1:新的留言簿和条目。

下一步是什么?

已经创建了一个可用的Web应用程序并将其部署在Liferay Portal上。但是,它缺少一些重要功能:安全性,前端验证,以及创建多个留言簿的管理界面。在下一节中,将开始添加这些(以及更多)功能。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值