标签: composite-component

如何以编程方式或动态创建JSF 2中的复合组件

我需要以编程方式在JSF 2中创建复合组件.经过几天的搜索和实验,我找到了这种方法(在java.net上受到Lexi的启发):

/**
 * Method will attach composite component to provided component
 * @param viewPanel parent component of newly created composite component
 */
public void setComponentJ(UIComponent viewPanel) {
    FacesContext context = FacesContext.getCurrentInstance();
    viewPanel.getChildren().clear();

    // load composite component from file
    Resource componentResource = context.getApplication().getResourceHandler().createResource("whatever.xhtml", "components/form");
    UIComponent composite = context.getApplication().createComponent(context, componentResource);

    // push component to el
    composite.pushComponentToEL(context, composite);
    boolean compcompPushed = false;
    CompositeComponentStackManager ccStackManager = CompositeComponentStackManager.getManager(context);
    compcompPushed = ccStackManager.push(composite, CompositeComponentStackManager.StackType.TreeCreation);

    // Populate the component with value expressions 
    Application application = context.getApplication();
    composite.setValueExpression("value", …
Run Code Online (Sandbox Code Playgroud)

java dynamic composite-component jsf-2

11
推荐指数
2
解决办法
2万
查看次数

如何将属性传递给复合组件

我在以正确的方式使用JSF复合组件时遇到了麻烦.我把一些组件放在一起,一切正常.然后我只是将代码提取到复合​​组件,并传递相应的属性,然后我突然得到对话异常.

<composite:interface>
    <composite:attribute name="selectedIDs"  type="java.util.Collection" required="true"/>
    <composite:attribute name="selectItems" type="java.util.List" required="true" />    
    <composite:attribute name="addAction" required="true"/>
    <composite:attribute name="deleteAction" required="true"/>
    <composite:attribute name="deleteButtonDisabled" />
    <composite:attribute name="ajaxListener" method-signature="void listener(javax.faces.event.AjaxBehaviorEvent)"/>
</composite:interface>
<composite:implementation>
<div class="myClass">
    <h:outputStylesheet library="views" name="selectManyControlPanel.css" target="head" />

    <h:form>
        <h:selectManyListbox value="#{cc.attrs.selectedIDs}">
            <f:selectItems value="#{cc.attrs.selectItems}" />
            <f:ajax render="delete"
                listener="#{cc.attrs.ajaxListener}" />
        </h:selectManyListbox>
        <br />
        <h:commandButton id="delete" value="Delete"
            disabled="#{cc.attrs.deleteButtonDisabled}"
            action="#{cc.attrs.deleteAction}" />
        <h:commandButton id="add" value="Add" action="#{cc.attrs.addAction}"/>
    </h:form>
</div>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

这是我使用新创建的组件的页面

<view:selectManyControlPanel 
            selectedIDs="#{bean.selectedIds}" 
            selectItems="#{bean.listOfSelectItems}"
            addAction="#{bean.addNew}"
            deleteAction="#{bean.deleteSelection}"
            ajaxListener="#{bean.selectionChanged}"
            deleteButtonDisabled="#{bean.deleteButtonDisabled}" />
Run Code Online (Sandbox Code Playgroud)

Bean(某些方法跳过重命名的部分)

package views;

@SuppressWarnings("serial")
@Named
@RequestScoped
public class Bean implements Serializable, IOverviewView …
Run Code Online (Sandbox Code Playgroud)

composite-component jsf-2

11
推荐指数
1
解决办法
1万
查看次数

如何为数据表列创建复合组件?

鉴于此数据表(自然工作):

<rich:dataTable var="var" value="#{values}">
<rich:column>
  <f:facet name="header">
   HEADER
  </f:facet>
  <h:outputText value="#{var}" />
</rich:column>
</rich:dataTable>
Run Code Online (Sandbox Code Playgroud)

如果我定义一个自定义组件(在语法和资源/组件下的正确位置也可以):

   <?xml version="1.0" encoding="UTF-8"?>
    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:a4j="http://richfaces.org/a4j"
        xmlns:rich="http://richfaces.org/rich"
        xmlns:composite="http://java.sun.com/jsf/composite">

    <!-- INTERFACE -->
    <composite:interface>
        <composite:attribute name="val" />
    </composite:interface>

    <!-- IMPLEMENTATION -->
    <composite:implementation>
        <rich:column>
            <f:facet name="header">
       HEADER
       </f:facet>
       <h:outputText value="#{cc.attrs.val}" />
       </rich:column>
    </composite:implementation>
    </html>
Run Code Online (Sandbox Code Playgroud)

为什么以下不起作用?

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="/WEB-INF/templates/default.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:my="http://java.sun.com/jsf/composite/components">
    <ui:define name="content">
        <rich:dataTable var="var" value="#{values}">
                 <my:mycolumn val="#{var}"/>
                </rich:dataTable>
    </ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

你知道我怎么能让它工作(我想定义自己的列并保存代码)?非常感谢!再见

datatable jsf richfaces composite-component

11
推荐指数
1
解决办法
1万
查看次数

谷歌Chrome手机(Nexus 7)| 表单提交无效

我有一个登录我的网站的问题,似乎在移动Chrome浏览器中显示(但适用于某些手机中提供的Web工具包浏览器).我正在努力尝试在平板电脑上进入"开发者模式",但我希望其他人遇到这个问题并且可以指出我正确的方向,同时我弄清楚如何实际调试它.

它是一个JSF2应用程序(Primefaces over Bootstrap2.2)作为UI.

我的表单看起来像这样(第二组'onblur'调用是故意看看是否有帮助 - 它没有):

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:composite="http://java.sun.com/jsf/composite" 
>
    <composite:interface>
        <composite:attribute name="user" />
        <composite:attribute name="pass" />
        <composite:attribute name="error" />
        <composite:attribute name="loggedIn" />
        <composite:attribute 
            name="loginAction" 
            method-signature="void actionListener(javax.faces.event.ActionEvent)"
        />
        <composite:attribute 
            name="logoutAction" 
            method-signature="void actionListener(javax.faces.event.ActionEvent)"
        />
    </composite:interface>

    <composite:implementation>
        <script type="text/javascript">
        function copyValue(sourceId, targetId){
            var source = '#{cc.attrs.id}:' + sourceId;
            var target = '#{cc.attrs.id}:' + targetId;

            var sourceEl = document.getElementById(source);
            var targetEl = document.getElementById(target); 

            targetEl.value = sourceEl.value; 
        };
        </script>
        <h:form class="navbar-form pull-right" id="login" prependId="false" rendered="#{not cc.attrs.error and !cc.attrs.loggedIn}">
            <h:panelGroup rendered="#{!cc.attrs.loggedIn}" …
Run Code Online (Sandbox Code Playgroud)

javascript primefaces composite-component jsf-2 twitter-bootstrap

11
推荐指数
1
解决办法
1289
查看次数

如何检查复合组件中是否存在可选属性

我需要验证我的复合组件中是否已传递可选属性.我怎样才能做到这一点?

<composite:interface>
    <composite:attribute name="attr1" />
    <composite:attribute name="attr2" required="false" /> <!-- means OPTIONAL -->
</composite:interface>
<composite:implementation>
    <!-- How I can verify here whether attr2 is present or not whenever this component is used? -->
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

default属性设置为xxxfor <composite:attribute>不是我正在寻找的.

attributes composite-component jsf-2

11
推荐指数
1
解决办法
5515
查看次数

嵌套的JSF复合组件导致堆栈溢出异常

问题

当我尝试在自身中嵌套复合组件时,使用一些逻辑来结束无限递归,我收到堆栈溢出异常.我的理解是<c:xxx>标签在视图构建时运行,所以我不希望有无限的视图构建,因为我认为是这样的.

这是复合组件 simpleNestable.xhtml

<!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:composite="http://java.sun.com/jsf/composite"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:em="http://xmlns.jcp.org/jsf/composite/emcomp"

  xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">

    <h:head>
        <title>This content will not be displayed</title>
    </h:head>
    <h:body>
        <composite:interface>
            <composite:attribute name="depth" required="true" type="java.lang.Integer"/>
        </composite:interface>

        <composite:implementation>
            <c:if test="#{cc.attrs.depth lt 3}">
                 #{cc.attrs.depth}
                 #{cc.attrs.depth+1}
                 <em:simpleNestable depth="#{cc.attrs.depth+1}" /> 

            </c:if>

        </composite:implementation>
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

这就是它的用法

<h:head>
    <title>Facelet Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <h:outputStylesheet name="./css/default.css"/>
    <h:outputStylesheet name="./css/cssLayout.css"/>
</h:head>
<h:body>        
     <emcomp:simpleNestable depth="1"/>

</h:body>
Run Code Online (Sandbox Code Playgroud)

堆栈溢出异常

java.lang.StackOverflowError
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2407)
    at com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.get(CompositeComponentAttributesELResolver.java:393)
    at javax.el.MapELResolver.getValue(MapELResolver.java:199)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) …
Run Code Online (Sandbox Code Playgroud)

stack-overflow jsf nested jstl composite-component

10
推荐指数
1
解决办法
1680
查看次数

从复合组件中删除自动生成的j_id

我喜欢jsf 2.0复合组件设置.我喜欢的另一件事是在表格上prependId ="false".是否有一个可以在cc:interface或cc:implementation中定义的等价物,它将阻止jsf创建一个j_id以预先添加到复合组件中定义的id?

jsf composite-component

9
推荐指数
1
解决办法
8083
查看次数

JAR中的JSF组合组件在NetBeans中无法识别

我在项目中添加了一个通用的JAR.罐子看起来像......

CommonWeb.jar
 |-- META-INF
 |    |-- resources
 |    |    `-- common
 |    |         |-- css
 |    |         |    `-- my.css
 |    |         |-- js
 |    |         |    `-- my.js
 |    |         |-- images
 |    |         |    `-- my.png
 |    |         |-- components
 |    |         |    `-- mycomposite.xhtml
 |    |         `-- templates
 |    |              `-- mytemplate.xhtml
 |    |-- faces-config.xml
 |    `-- MANIFEST.MF
 :
Run Code Online (Sandbox Code Playgroud)

一切正常,但Netbeans无法识别我的复合组件.试图使用该组件的页面看起来像这样......

<ui:composition template="/resources/common/templates/mytemplate.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:cmn="http://java.sun.com/jsf/composite/common/components">

    <ui:define name="content">
        ...
        <cmn:mycomposite ... />
        ...
    </ui:define>
</ui:composition> …
Run Code Online (Sandbox Code Playgroud)

jsf netbeans jar composite-component jsf-2

9
推荐指数
1
解决办法
1678
查看次数

PrimeFaces CommandButton Action未在Composite内部调用

在下面的代码中,jsf html commandButton动作被完美地调用.但是没有调用primefaces commandButton动作.

<ui:component          
              xmlns="http://www.w3.org/1999/xhtml" 
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html"
           xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:p="http://primefaces.prime.com.tr/ui"
    xmlns:composite="http://java.sun.com/jsf/composite">

    <composite:interface>
        <composite:attribute 
            name="managedBean"          
            type="java.lang.Object"
            required="true">                    
        </composite:attribute>
    </composite:interface>

    <composite:implementation>
        <f:view contentType="text/html"> 
            <h:form id="componentes">  
                <h:panelGrid columns="3">
                    <h:panelGroup>              
                        <h:outputText 
                              escape = "false" 
                               value = "#{cc.attrs.managedBean['value']}"       
                            rendered = "#{!cc.attrs.managedBean['editing']}"/> 
                        <p:editor 
                            widgetVar = "editor" 
                                value = "#{cc.attrs.managedBean.value}" 
                             rendered = "#{cc.attrs.managedBean.editing}"/>
                    </h:panelGroup>
                    <!-- ACTION IS CALLED -->                                 
                    <h:commandButton 
                                action = "#{cc.attrs.managedBean.toogleEditing}" 
                                 value = "#{cc.attrs.managedBean.editing?'Back':'Edit'}" 
                                update = "componentes"/>

                                    <!-- ACTION IS NOT CALLED -->           
                    <p:commandButton 
                                action = "#{cc.attrs.managedBean.toogleEditing}" 
                                 value = "#{cc.attrs.managedBean.editing?'Back':'Edit'}" 
                                update = "componentes"/>
                </h:panelGrid>
            </h:form> …
Run Code Online (Sandbox Code Playgroud)

primefaces composite-component jsf-2

8
推荐指数
2
解决办法
3万
查看次数

在JSF复合组件中集成JavaScript,干净的方式

在JSF中,将JavaScript集成到复合功能中的"正确"和"干净"方式是什么?我是Unobtrusive JavaScript的粉丝,并将HTML与JS分离.什么是尽可能小怪癖的好方法?到目前为止,这是我最喜欢的:

<composite:interface>
  // ...
</composite:interface>

<composite:implementation>
  // ...
  <script> initSomething('#{cc.clientId}'); </script>
</composite:implementation>    
Run Code Online (Sandbox Code Playgroud)

我不喜欢的是,language A用来生成language B.事件处理程序和东西基本相同.我最喜欢的是通过附加那些处理程序<insert favorite DOM JavaScript library here>.这可能吗?你是如何进行这种整合的?

javascript integration jsf composite-component

8
推荐指数
1
解决办法
7918
查看次数