使用JSF的面向服务的UI

在大型软件开发项目中,面向服务的体系结构非常常见,因为它提供了可供不同团队或部门使用的功能接口。 创建用户界面时,应应用相同的原理。
对于具有开票部门和客户管理部门等的大型公司,组织结构图可能如下所示:

如果计费部门要开发一个用于创建发票的新对话框,则可能如下所示:

如您所见,上面的屏幕在上部引用了一个客户。 单击短名称文本字段后面的“ ..”按钮将打开以下对话框,允许用户选择客户:

按“选择”后,客户数据将显示在发票表格中。

也可以通过简单地输入客户编号或在发票屏幕上的文本字段中输入简称来选择客户。 如果输入唯一的短名称,则根本不会出现选择对话框。 而是直接显示客户数据。 只有不明确的简称会导致打开客户选择屏幕。

客户功能将由属于客户管理团队的开发人员提供。 一种典型的方法是由客户管理开发团队提供一些服务,而计费部门的开发人员创建用户界面并调用这些服务。

但是,这种方法涉及到这两个不同部门之间的耦合要强于实际需要。 发票只需要一个唯一的ID即可引用客户数据。 创建发票对话框的开发人员实际上并不想知道如何查询客户数据或在后台使用哪些服务来获取该信息。

客户管理开发人员应提供UI的完整部分,以显示客户ID并处理客户的选择:

使用JSF 2,使用复合组件很容易实现。 客户管理部门和计费部门之间的逻辑接口包括三个部分:

  • 复合组件(XHTML)
  • 复合组件的支持bean
  • 侦听器界面,用于处理选择结果


提供者(客户管理部门)

复合组件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"xmlns:ui="http://java.sun.com/jsf/facelets"xmlns:h="http://java.sun.com/jsf/html"xmlns:f="http://java.sun.com/jsf/core"xmlns:composite="http://java.sun.com/jsf/composite"xmlns:ice="http://www.icesoft.com/icefaces/component"xmlns:ace="http://www.icefaces.org/icefaces/components"xmlns:icecore="http://www.icefaces.org/icefaces/core"><ui:composition><composite:interface name="customerSelectionPanel" displayName="Customer Selection Panel" shortDescription="Select a customer using it's number or short name"><composite:attribute name="model" type="org.fuin.examples.soui.view.CustomerSelectionBean" required="true" />  </composite:interface><composite:implementation><ui:param name="model" value="#{cc.attrs.model}"/><ice:form id="customerSelectionForm"><icecore:singleSubmit submitOnBlur="true" /><h:panelGroup id="table" layout="block"><table><tr><td><h:outputLabel for="customerNumber"value="#{messages.customerNumber}" /></td><td><h:inputText id="customerNumber"value="#{model.id}" required="false" /></td><td>&nbsp;</td><td><h:outputLabel for="customerShortName"value="#{messages.customerShortName}" /></td><td><h:inputText id="customerShortName"value="#{model.shortName}" required="false" /></td><td><h:commandButton action="#{model.select}"value="#{messages.select}" /></td></tr><tr><td><h:outputLabel for="customerName"value="#{messages.customerName}" /></td><td colspan="5"><h:inputText id="customerName"value="#{model.name}" readonly="true" /></td></tr></table></h:panelGroup></ice:form></composite:implementation></ui:composition></html>

复合组件的后备bean:

package org.fuin.examples.soui.view;import java.io.Serializable;import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import javax.inject.Named;import org.apache.commons.lang.ObjectUtils;
import org.fuin.examples.soui.model.Customer;
import org.fuin.examples.soui.services.CustomerService;
import org.fuin.examples.soui.services.CustomerShortNameNotUniqueException;
import org.fuin.examples.soui.services.UnknownCustomerException;@Named
@Dependent
public class CustomerSelectionBean implements Serializable {private static final long serialVersionUID = 1L;private Long id;private String shortName;private String name;private CustomerSelectionListener listener;@Injectprivate CustomerService service;public CustomerSelectionBean() {super();listener = new DefaultCustomerSelectionListener();}public Long getId() {return id;}public void setId(final Long id) {if (ObjectUtils.equals(this.id, id)) {return;}if (id == null) {clear();} else {clear();this.id = id;try {final Customer customer = service.findById(this.id);changed(customer);} catch (final UnknownCustomerException ex) {FacesUtils.addErrorMessage(ex.getMessage());}}}public String getShortName() {return shortName;}public void setShortName(final String shortNameX) {final String shortName = (shortNameX == "") ? null : shortNameX;if (ObjectUtils.equals(this.shortName, shortName)) {return;}if (shortName == null) {clear();} else {if (this.id != null) {clear();}this.shortName = shortName;try {final Customer customer = service.findByShortName(this.shortName);changed(customer);} catch (final CustomerShortNameNotUniqueException ex) {select();} catch (final UnknownCustomerException ex) {FacesUtils.addErrorMessage(ex.getMessage());}}}public String getName() {return name;}public CustomerSelectionListener getConnector() {return listener;}public void select() {// TODO Implement...}public void clear() {changed(null);}private void changed(final Customer customer) {if (customer == null) {this.id = null;this.shortName = null;this.name = null;listener.customerChanged(null, null);} else {this.id = customer.getId();this.shortName = customer.getShortName();this.name = customer.getName();listener.customerChanged(this.id, this.name);}}public void setListener(final CustomerSelectionListener listener) {if (listener == null) {this.listener = new DefaultCustomerSelectionListener();} else {this.listener = listener;}}public void setCustomerId(final Long id) throws UnknownCustomerException {clear();if (id != null) {clear();this.id = id;changed(service.findById(this.id));}}private static final class DefaultCustomerSelectionListener implementsCustomerSelectionListener {@Overridepublic final void customerChanged(final Long id, final String name) {// Do nothing...}}}

用于处理结果的侦听器接口:

package org.fuin.examples.soui.view;/*** Gets informed if customer selection changed.*/
public interface CustomerSelectionListener {/*** Customer selection changed.** @param id New unique customer identifier - May be NULL.* @param name New customer name - May be NULL.*/public void customerChanged(Long id, String name);}

用户(计费部门)

发票Bean只是通过注入来使用客户选择Bean,并使用侦听器接口连接到它:

package org.fuin.examples.soui.view;import java.io.Serializable;import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.New;
import javax.inject.Inject;
import javax.inject.Named;@Named("invoiceBean")
@SessionScoped
public class InvoiceBean implements Serializable {private static final long serialVersionUID = 1L;@Inject @Newprivate CustomerSelectionBean customerSelectionBean;private Long customerId;private String customerName;@PostConstructpublic void init() {customerSelectionBean.setListener(new CustomerSelectionListener() {@Overridepublic final void customerChanged(final Long id, final String name) {customerId = id;customerName = name;}});}public CustomerSelectionBean getCustomerSelectionBean() {return customerSelectionBean;}public String getCustomerName() {return customerName;}}

最后,在发票XHTML中,使用了复合组件并将其链接到注入的支持bean:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"xmlns:ui="http://java.sun.com/jsf/facelets"xmlns:h="http://java.sun.com/jsf/html"xmlns:f="http://java.sun.com/jsf/core"xmlns:fuin="http://fuin.org/examples/soui/facelets"xmlns:customer="http://java.sun.com/jsf/composite/customer"><ui:composition template="/WEB-INF/templates/template.xhtml"><ui:param name="title" value="#{messages.invoiceTitle}" /><ui:define name="header"></ui:define><ui:define name="content"><customer:selection-panel model="#{invoiceBean.customerSelectionBean}" /></ui:define><ui:define name="footer"></ui:define></ui:composition></html>

摘要
总之,用户界面中引用其他部门数据的部分应由提供数据的部门负责。 然后,可以很容易地对提供的代码进行任何更改,而无需对使用代码进行任何更改。 此方法的另一个重要好处是可以统一应用程序的用户界面。 显示相同数据的控件和面板始终看起来相同。 每个部门还可以为其提供的用户界面组件创建一个存储库,从而使设计新对话框的过程像将正确的组件放在一起一样容易。

参考: A Java Developer's Life博客上的JCG合作伙伴 Michael Schnell提供的面向服务的UI 。


翻译自: https://www.javacodegeeks.com/2012/09/service-oriented-ui-with-jsf.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/371289.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

pocib模板流程图_各单据流程POCIB

POCIB各阶段流程报关流程从广义上讲&#xff0c;报关是指进出境运输工具负责人、进出境口货物收发货人、进出境物品的所有人或者他们的代理人向海关办理运输工具、货物、物品进出境手续及相关手续的全过程。其中&#xff0c;进出境运输工具负责人、进出口货物收发货人、进出境物…

WinDbg 查看静态变量

有如下Class。若想查看静态变量内容。因为静态变量和类绑定&#xff0c;仅需要查看类即可。 namespace ConsoleApplication13 {class Program{public static string public_string "pubstr_static";public static string private_string "pristr_static"…

vue 固定div 滚动_vue.js-div滚动条隐藏但有滚动效果的实现方法

组件被包在一个高度固定的divmounted () {var boDiv document.getElementById(this.id);if(boDiv undefined){return;}var isFirefoxnavigator.userAgent.indexOf("Firefox")if(isFirefox>0){boDiv.addEventListener(DOMMouseScroll, function(event) { //火狐v…

JBoss核心Java Web服务

这篇博客文章涉及Web服务。 好吧&#xff0c;更确切地说&#xff0c;它处理JBoss上的“普通” java Web服务。 这意味着我们将创建一个没有任何其他框架&#xff08;如CXF&#xff0c;Axis等&#xff09;的Web服务。 JBoss它自己提供对Web服务的支持。 因此&#xff0c;如果您真…

JavaSE--for each

参考&#xff1a;http://blog.csdn.net/yasi_xi/article/details/25482173 学习多线程的时候实例化线程数组而挖掘出来的一直以来的理解误区 之前一直以为for each 本质上和for循环以及迭代器没什么区别 1 package foreach;2 3 public class ForeachDemo1 {4 5 public …

[BZOJ1726][Usaco2006 Nov]Roadblocks第二短路

1726: [Usaco2006 Nov]Roadblocks第二短路 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1277 Solved: 607 [Submit][Status][Discuss]Description 贝茜把家搬到了一个小农场&#xff0c;但她常常回到FJ的农场去拜访她的朋友。贝茜很喜欢路边的风景&#xff0c;不想那么快…

mysql 5.1.62_MySQL 5.5.62 安装方法(标准配置版)

1.此安装方法适用于绝大多数MySQL版本&#xff0c;首先在MySQL官网上下载好所需版本。2.(官网可能不太好找)在我的博客列表中有一篇是MySQL官网下载链接&#xff0c;直达下载界面&#xff0c;方便。3.下载。(安装版 MSI Installer)4.下载安装包然后双击开始安装选择同意协议并…

简化Java内存分析

作为一名典型的Java开发人员&#xff0c;除了遵循关闭连接&#xff0c;流等典型的最佳实践外&#xff0c;我从未监视过应用程序的内存使用情况。最近&#xff0c;我们在JBoss服务器中遇到了一些问题&#xff0c;不得不深入研究内存管理Java中最好的事情之一是&#xff0c;创建对…

nyoj 1129 Salvation 模拟

思路&#xff1a;每个坐标有四种状态&#xff0c;每个点对应的每种状态只能走一个方向&#xff0c;如果走到一个重复的状态说明根本不能走到终点&#xff0c;否则继续走即可。 坑点&#xff1a;有可能初始坐标四周都是墙壁&#xff0c;如果不判断下可能会陷入是死循环。 贴上测…

详解mysql数据库的启动与终止_详解MySQL数据库的启动与终止(一)

由于MySQL服务器具有多种安装分发&#xff0c;而且能够运行在多种操作平台之上&#xff0c;因此它的启动与停止的方法也多种多样。你可以根据实际情况使用其中的一种。在你安装、升级或者维护系统时&#xff0c;你可能需要多次启动和终止服务器&#xff0c;你需要了解启动和终止…

easyui 插入中间行

function inserrow() {var index_dx 0;var index_lt 0;var rows $(#dg).datagrid(getRows)//获取当前的数据行前期数据准备for (var i 0; i < rows.length; i) {if (rows[i][运营商] 电信) {index_dx i;dxptjss_dx parseInt(rows[i][短信平台接收数]);} else {index_…

使用JNA的透明JFrame

在“ 使JFrame透明”中&#xff0c;我展示了一种使用AWTUtilities类使框架透明的方法。 但是使用该类会导致访问限制编译时错误&#xff0c;该文章中还显示了Eclipse中的解析。 现在&#xff0c;这里是使用Java本机的版本。 我使用Java本机访问&#xff08;JNA&#xff09;库来…

Problem: Query on the tree(二分+划分树)

题目链接&#xff1a; Problem: Query on the tree Time limit: 1s Mem limit: 64 MB Problem DescriptionThere is a tree with n node, labeled from 1 to n, and the root of the tree is 1. For every node i, if its father is j, its value vivj*i%20161119, the…

day04_09 while循环03

练习题: 3.如何输入一个如下的直角三角形,用户指定输出行数:(如果上下反转,右如何实现?) ********** 以下是自己的思路,没有按照上课老师的思路,反正经过不断的测试改进得出的算法 num int(input("请输入行数")) line 1 while line < num1:lie 1 while lie &l…

idal 创建springboot 项目_手把手的SpringBoot教程,SpringBoot创建web项目(四)

在实际的开发过程中&#xff0c;我们需要前端页面向Java端提交请求&#xff0c;这些请求一般分为get方式和post方式&#xff0c;不管是哪一种方式&#xff0c;一般都会携带一些参数。这一节&#xff0c;我们来演示一下如何给Controller传递参数。代码&#xff1a;RestControlle…

JavaOne 2012:Lambda之路

我最热切期待的JavaOne 2012演讲之一是Brian Goetz的“通往Lambda的道路”。 昨晚的技术主题演讲中的Lambda味道仅增加了预期。 这是在希尔顿广场A / B举行的&#xff0c;距离我上次在金门大桥A / B / C参加的演讲仅几步之遥。 我原本希望打包相对较大的Plaza A / B&#xff08…

沉浸式go-cache源码阅读!

大家好&#xff0c;我是豆小匠。 这期来阅读go-cache的源码&#xff0c;了解本地缓存的实现方式&#xff0c;同时掌握一些阅读源码的技巧~ 1. 源码获取 git clone https://github.com/patrickmn/go-cache.git用Goland打开可以看到真正实现功能的也就两个go文件&#xff0c;ca…

CoreAnimation 变换

CoreAnimation 变换 CoreAnimation 目录 博客园MakeDown支持不佳,如有需要请进GitHub 本片博客主要内容: 仿射变换 - CGAffineTransform3D变换 - CATransform3D仿射变换 - CGAffineTransform CGAffineTransform 是用于二维空间的旋转,缩放和平移的属性.首先展示一个简单的样例,…

20170907wdVBA_GetCellsContentToExcel

WORD 加载项 代码模板 Dim cmdBar As CommandBar, cmdBtn As CommandBarControl Const cmdBtnCap As String "批量提取操作步骤"Sub AutoExec()Call DelCmdBtnCall AddCmdBtnEnd Sub Sub AutoExit()Call DelCmdBtn End SubSub AddCmdBtn()Set cmdBar Application.C…

mysql 5.7 mirror_Centos7 Docker离线部署Mysql5.7

1 环境信息查看系统内核[rootlocalhost /]# cat /etc/redhat-releaseCentOS Linux release 7.5.1804 (Core)2 虚拟机拉取镜像此处资源获取在虚拟机中进行&#xff0c;完成后上传到服务器安装2.1 拉取mysql5.7镜像[rootlocalhost /]# docker pull mysql:5.72.2 导出镜像[rootloc…