The last part of JBoss Seam: A deep integration framework.

Source: Internet
Author: User
Tags jbpm

Author Profile:Michael yuan, technical expert, JBoss
Seam: simplicity and power beyond Java EE, lightweight Java Web
Author of application development and other books, software consultant, currently working on JBoss.

Abstract:This article describes how JBoss Seam integrates business processes, uses itext and task scheduling, and summarizes the key elements in the seam programming model.

This article is the last part of "JBoss Seam: A deep integration framework.

Integrate business processes in Web Applications

Most enterprise applications have many business processes and rules. For example, on a simple e-commerce website (taking "online shopping" as an example), the customer logs on to the website to perform the shopping process.
The approval process is carried out, and the warehouse staff will log on to the delivery process. Different personnel perform different tasks from different perspectives. However, they work together to complete the same business scenario.

In enterprise applications, business analysts usually define business processes and rules. They use professional business process software to Plot these processes and rules, and then application developers implement these designs.

However, because most web application frameworks do not integrate popular business processes and rules engines, developers can only integrate business processes in their own ways. This will inevitably lead to a disconnection between developers and business analysts, making it difficult for business analysts to review and verify their work.

Seam provides excellent support for the integration of business processes and rules through jbpm and JBoss rules (previous drools.

In the seam application, you can specify the UI action (for example, click a button) to trigger the business flow. You only need to mark the UI event handling method through the @ CreateProcess annotation. Industry
A service flow is a series of tasks completed by different users in the corresponding order. You can use @ begintask and @ endtask to mark the start and end of a task. Jbpm engine at the end of the current task
The process is automatically moved forward to the next task.

@ Name ("ticketsystem ")

Public class ticketsystemaction {

@ CreateProcess (definition = "ticketprocess ")

Public String newticket (){

Return "home ";

}

@ Begintask

Public String reply (){

Return "reply ";

}

@ Endtask

Public String sendanswer (){

System. Out. println ("answered ");

Return "home ";

}

}

Seam allows each user to view his/her current task list and the next action to complete the task. These task lists are generated based on the currently logged-on user roles and are tightly integrated into the seam security framework through user authentication and authorization.

<H1> assigned tickets-# {login. User. Username}

<H: datatable value = "# {taskinstancelist}" Var = "task">

<H: column >#{ task. Description}

<H: column> title :#{ ticket. Title}

<H: column>

<H: commandlink action = "# {ticketsystem. Reply}">

<H: commandbutton value = "reply"/>

<F: Param name = "taskid" value = "# {task. ID}"/>

</H: commandlink>

</H: column>

</H: datatable>

In Seam applications integrated with jbpm/JBoss rules, developers can directly use seam annotations and components to drive business processes and rules engines, instead of having to master the Java APIs of specific jbpm and JBoss Rules separately.

Use itext to generate different views

The itext library is an open source Java library widely used to generate PDF documents. However, using the itext API to create PDF documents is time consuming (think about the experience of using Dom to create XML documents or using swing to write the UI ).

Seam neatly integrates itext, JSF, and facelets. developers can generate dynamic PDF pages in the same simple way as JSF pages, you can even use a template on the pdf page.

Seam creates a special XHTML tag library for the PDF element and transparently calls itext when generating the page. The following example shows how to generate a pdf page with digital signatures supported in the seam application.

<P: document... Title = "Why seam" KEYWORDS = "mykeyword"

Subject = "seam" author = "seam team" creator = "seam PDF example app">

<P: Image Alignment = "right" Wrap = "true" value = "/jboss.jpg"/>

<P: font size = "24"> <P: paragraph spacingbefore = "16" spacingafter = "40">

Order # {currentorder. orderid}

</P: paragraph> </P: font>

<P: paragraph> dear # {currentorder. customername}, </P: paragraph>

<P: paragraph>... </P: paragraph>

<P: barcode type = "code128" code = "my barcode"/>

<P: Signature field = "my signature" size = "200 200 400"/>

</P: document>

Through the code, we can see that integration is seamless, and the page does not depend on itext. In fact, replacing itext with other commercial PDF libraries can still work on pages, which is the charm of seam integration.

Advanced Task Scheduler

In many enterprise applications, support for automatic repetitive tasks is very important. In standard ejbs, you can use the EJB timer API to schedule repeated events at a fixed interval. However, in practical applications, we need to trigger more advanced scheduling services than at a fixed interval.

Currently, the popular open-source Java scheduling library is the quartz library. However, to use quartz, developers still need to write "glue" code to integrate the specific APIs and Object Model of quartz.

Seam integrates quartz to schedule asynchronous repetitive tasks. You only need to add the @ asynchronous annotation to the method of repetitive work. You can input the start/end of the task.
Time, interval, or Kelon expression (Cron
String), you can also annotate these specific parameters in the method definition. The specified method returns the quartztriggerhandler object.
And then use the quartztriggerhandler object to pause or cancel the task. You can also save the quartztriggerhandler object to the database
For later use.

@ Asynchronous

Public quartztriggerhandle schedulepayment (

@ Expiration date when,

@ Intervalcron string Cron,

@ Finalexpiration date stoptime

... Any other call parameters ...) {

// Do the repeating or long running task

}

In the following example, the schedulepayment () method is set to run at 02:10 P.M. and 02:44 P.M. on every Wednesday, January 1, March. You can add the called code in the Web UI event processing method, so that when the button is pressed, repeated events will be scheduled to the scheduler.

Quartztriggerhandle handle =

Processor. schedulepayment (payment. getpaymentdate (),

"0 10, 44 14? 3 wed ",

Payment. getpaymentenddate (),

Payment );

Payment. setquartztriggerhandle (handle );

// Save payment to DB

// Later...

// Retrieve payment from DB

// Cancel the remaining scheduled tasks

Payment. getquartztriggerhandle (). Cancel ();

The example shows that developers do not need to manually start the quartz scheduler, create a quartz trigger and task, but only need to use the seam annotation pojos.

Unified Programming Model

So far, we have introduced many examples of integrating different frameworks by using consistent programming models. In addition to the above, there are many other frameworks. However, due to space limitations, we cannot introduce all the frameworks. The following describes how seam integrates these frameworks. The key three elements of the seam programming model are:

Pojos Annotation: All Java components in the seam application are annotated pojo classes. Seam manages interactions between them through bidirectional dependency injection. In addition, there are no other component models in seam.

XHTMLDisplay page: All view (UI) pages are displayed through the XHTML file. Apart from the standard JSF tag, seam also defines many of its own UI tags, including pdf ui tags. Seam also adds the Ajax JSF library, such as ajax4jsf, richfaces, and icefaces.

Expression Language: The XHTML page uses the JSF Expression Language (EL) to reference Java components in seam. Seam enhances the standard El syntax to support method parameters, and enables El to be used in all xml configuration files and test scripts.

With these cool features, seam's programming model will become exceptionally simple. As long as you have some JSF basics, your learning curve will be very flat.

Download seam, check the instance, and write the seam code happily. Everything is so simple!

 

From: http://www.dojochina.com/index.php? Q = blog/8377

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.