vue 动态组件组件复用_真正的动态声明性组件

2023年7月19日09:05:23

vue 动态组件组件复用

在这篇简短的文章中,我将重点介绍ADF动态声明性组件。 我的意思是一个众所周知的ADF标签af:declarativeComponent 。 它可以用作将页面设计为页面片段和组件组成的一种非常便捷的方法。 例如,我们的页面可以包含以下代码片段:

<af:declarativeComponent viewId="PageFragment.jsff" id="dc1">
   <f:facet name="TheFacet">
     <af:button text="button 1" id="b1"/>
   </f:facet>                    
 </af:declarativeComponent>

PageFragment.jsff是像这样的普通页面片段:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:outputText value="This is a page fragment. 
                          You can add your content to the following facet:"
                   id="ot1"/>
    <af:facetRef facetName="TheFacet"/>
  </af:panelGroupLayout>
</jsp:root>

如果我们需要将一些参数传递给页面片段,可以将片段定义为组件:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<af:componentDef var="attrs">
  <af:xmlContent>
    <component xmlns="http://xmlns.oracle.com/adf/faces/rich/component">
      <facet>
        <facet-name>TheFacet</facet-name>
      </facet>
      <attribute>
        <attribute-name>Title</attribute-name>
      </attribute>
    </component>
  </af:xmlContent>
  <af:panelGroupLayout id="pgl1">
    <af:outputText value="This is a component #{attrs.Title}.
                          You can add your content to the following facet:" id="ot1"/>
    <af:facetRef facetName="TheFacet"/>
  </af:panelGroupLayout>
 </af:componentDef> 
</jsp:root>

在此示例中,我们可以传递如以下代码片段所示的Title属性的值:

<af:declarativeComponent viewId="ComponentFragment.jsff"
                         id="dc2"
                         Title="Buttom Container">                    
   <f:facet name="TheFacet">
        <af:button text="button 2" id="b2"/>
    </f:facet>                    
</af:declarativeComponent>

这项技术最酷的地方是viewId属性不仅可以接受静态字符串,而且还可以接受EL表达式:

<af:declarativeComponent viewId="#{TheBean.fragmentViewID}"
                          id="dc1">
   <f:facet name="TheFacet">
     <af:button text="button 1" id="b1"/>
   </f:facet>                    
 </af:declarativeComponent>
public String getFragmentViewID() {
    return "PageFragment.jsff";
}

实际上,这就是为什么这种构造称为dynamic的原因,因此可以将此功能视为构建结构良好,灵活而动态的UI的强大工具。

而已!

翻译自: https://www.javacodegeeks.com/2014/09/really-dynamic-declarative-components.html

vue 动态组件组件复用

  • 作者:dnc8371
  • 原文链接:https://blog.csdn.net/dnc8371/article/details/107266815
    更新时间:2023年7月19日09:05:23 ,共 2247 字。