旅游网站建设系统,北京网页制作,网站登记查询,营销型网站有哪些特点jsf服务在大型软件开发项目中#xff0c;面向服务的体系结构非常常见#xff0c;因为它提供了可供不同团队或部门使用的功能接口。 创建用户界面时#xff0c;应应用相同的原理。 对于具有开票部门和客户管理部门等的大型公司#xff0c;组织结构图可能如下所示#xff1a… jsf服务 在大型软件开发项目中面向服务的体系结构非常常见因为它提供了可供不同团队或部门使用的功能接口。 创建用户界面时应应用相同的原理。 对于具有开票部门和客户管理部门等的大型公司组织结构图可能如下所示 如果计费部门要开发一个用于创建发票的新对话框则可能如下所示 如您所见上面的屏幕在上部引用了一个客户。 单击短名称文本字段后面的“ ..”按钮将打开以下对话框允许用户选择客户 按“选择”后客户数据将显示在发票表格中。 也可以通过简单地输入客户编号或在发票屏幕上的文本字段中输入简称来选择客户。 如果输入了唯一的短名称则根本不会出现选择对话框。 而是直接显示客户数据。 只有不明确的简称会导致打开客户选择屏幕。 客户功能将由属于客户管理团队的开发人员提供。 一种典型的方法是由客户管理开发团队提供一些服务而计费部门的开发人员创建用户界面并调用这些服务。 但是这种方法需要在这两个不同部门之间建立更强的耦合而不是实际需要的耦合。 发票只需要一个唯一的ID即可引用客户数据。 创建发票对话框的开发人员实际上并不想知道如何查询客户数据或在后台使用哪些服务来获取该信息。 客户管理开发人员应提供UI的完整部分以显示客户ID并处理客户的选择 使用JSF 2使用复合组件很容易实现。 客户管理部门和计费部门之间的逻辑接口包括三个部分 复合组件XHTML 复合组件的支持bean 侦听器界面用于处理选择结果 提供者客户管理部门 复合组件 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdhtml xmlnshttp://www.w3.org/1999/xhtmlxmlns:uihttp://java.sun.com/jsf/faceletsxmlns:hhttp://java.sun.com/jsf/htmlxmlns:fhttp://java.sun.com/jsf/corexmlns:compositehttp://java.sun.com/jsf/compositexmlns:icehttp://www.icesoft.com/icefaces/componentxmlns:acehttp://www.icefaces.org/icefaces/componentsxmlns:icecorehttp://www.icefaces.org/icefaces/coreui:compositioncomposite:interface namecustomerSelectionPanel displayNameCustomer Selection Panel shortDescriptionSelect a customer using its number or short namecomposite:attribute namemodel typeorg.fuin.examples.soui.view.CustomerSelectionBean requiredtrue / /composite:interfacecomposite:implementationui:param namemodel value#{cc.attrs.model}/ice:form idcustomerSelectionFormicecore:singleSubmit submitOnBlurtrue /h:panelGroup idtable layoutblocktabletrtdh:outputLabel forcustomerNumbervalue#{messages.customerNumber} //tdtdh:inputText idcustomerNumbervalue#{model.id} requiredfalse //tdtdnbsp;/tdtdh:outputLabel forcustomerShortNamevalue#{messages.customerShortName} //tdtdh:inputText idcustomerShortNamevalue#{model.shortName} requiredfalse //tdtdh:commandButton action#{model.select}value#{messages.select} //td/trtrtdh:outputLabel forcustomerNamevalue#{messages.customerName} //tdtd colspan5h:inputText idcustomerNamevalue#{model.name} readonlytrue //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//ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdhtml xmlnshttp://www.w3.org/1999/xhtmlxmlns:uihttp://java.sun.com/jsf/faceletsxmlns:hhttp://java.sun.com/jsf/htmlxmlns:fhttp://java.sun.com/jsf/corexmlns:fuinhttp://fuin.org/examples/soui/faceletsxmlns:customerhttp://java.sun.com/jsf/composite/customerui:composition template/WEB-INF/templates/template.xhtmlui:param nametitle value#{messages.invoiceTitle} /ui:define nameheader/ui:defineui:define namecontentcustomer:selection-panel model#{invoiceBean.customerSelectionBean} //ui:defineui:define namefooter/ui:define/ui:composition/html 摘要 总之用户界面中引用其他部门数据的部分应由提供数据的部门负责。 然后可以很容易地对提供的代码进行任何更改而无需对使用代码进行任何更改。 此方法的另一个重要好处是协调应用程序的用户界面。 显示相同数据的控件和面板始终看起来相同。 每个部门还可以为其提供的用户界面组件创建一个存储库从而使设计新对话框的过程像将正确的组件放在一起一样容易。 参考 A Java Developers Life博客上的JCG合作伙伴 Michael Schnell提供的面向服务的UI 。 翻译自: https://www.javacodegeeks.com/2012/09/service-oriented-ui-with-jsf.htmljsf服务