标签: composite-component

将操作方法​​添加到复合组件

我正在学习使用JSF 2.0的复合组件,我希望我的组件能够从支持bean中触发方法,所以我创建了一个简单的例子,但是出了点问题.

这是我创建的组件:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>
        <composite:attribute name="attribute1"/>
        <composite:attribute name="attribute2"/>
        <composite:attribute name="actionBtnText"/>
        <composite:attribute name="actionMethod" method-signature="java.lang.String action()"/>
</composite:interface>

<composite:implementation>
    <h:form>
            <h:inputText value="#{cc.attrs.attribute1}"/>
            <br/>
            <h:inputText value="#{cc.attrs.attribute2}"/>
            <br/>
            <h:commandButton action="#{cc.attrs.actionMethod}" value="#{cc.attrs.actionBtnText}"/>          
    </h:form>

</composite:implementation> 

</html>
Run Code Online (Sandbox Code Playgroud)

这是我在JSF页面中使用它的方式

<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:custom="http://java.sun.com/jsf/composite/custom">

...

    <h:body>
    <custom:demoCustomComponent attribute1="#{demoBB.value1 }" attribute2="#{demoBB.value2 }" actionBtnText="Button text!" actionBtn="#{demoBB.act}"/>
    </h:body>
Run Code Online (Sandbox Code Playgroud)

这是支持组件所在页面的支持bean

@Named("demoBB")
@RequestScoped
public class DemoBB {

    private String value1;
    private String value2;
    public String getValue1() {
        return value1;
    }

    public String act() {
        System.out.println("Input 1: " + value1 …
Run Code Online (Sandbox Code Playgroud)

java jsf facelets composite-component jsf-2

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

JSF Composite组件中不允许使用empty id属性

我面临一个问题"在JSF中不允许使用空id属性",而下面提到的复合组件用于一组按钮(按钮的计数可以是1到3)(我在Tomcat-7上使用Mojarra 2-0-8) .

    <?xml version="1.0" encoding="UTF-8"?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:composite="http://java.sun.com/jsf/composite">


    <composite:interface>       
        <composite:attribute name="buttonCount" />
        <composite:attribute name="button1Id" />
        <composite:attribute name="button1Style" />
        <composite:attribute name="button1Action" />
        <composite:attribute name="button2Id" />
        <composite:attribute name="button2Style" />
        <composite:attribute name="button2Action" />
        <composite:attribute name="button3Id" />
        <composite:attribute name="button3Style" />
        <composite:attribute name="button3Action" />

    </composite:interface>
    <composite:implementation>       
        <h:commandButton  rendered = "#{cc.attrs.buttonCount ge '1'}" id="#{cc.attrs.button1Id}" styleClass="#{cc.attrs.button1Style}">
            <f:ajax listener="#{cc.attrs.button1Action}" immediate="true"/>                                     
        </h:commandButton>
        <h:panelGroup rendered = "#{cc.attrs.buttonCount ge '2'}">
            <h:commandButton  id="#{cc.attrs.button2Id}" styleClass="#{cc.attrs.button2Style}">
                <f:ajax listener="#{cc.attrs.button2Action}" immediate="true"/>                                     
            </h:commandButton>
        </h:panelGroup> 
        <h:panelGroup …
Run Code Online (Sandbox Code Playgroud)

composite-component jsf-2

6
推荐指数
1
解决办法
7951
查看次数

JSF中的新手:组合与复合

我正在开始使用JSF 2作为视图技术的新Web应用程序.我之前没有使用过JSF的经验,对这些概念有点困惑.
我阅读了一些关于JSF的文档,其主要思想是它是一个基于组件的框架.应用程序是从组件构建的.

但是现在有两种创建组件的方法,正如我所理解的:
1.组合 - 可以包含在页面中的组件集合
2. composite - 一个新的组件,它封装了一些组件并向用户公开了一个接口

选择它们的基本规则是什么?
例如,我想向用户显示产品列表.对于这个列表,我应该创建我自己的组件,我将其添加到主布局,以分隔视图代码.那么这个列表应该是一个组合还是复合?

我希望有人可以帮助我清理这些基本的东西.

提前致谢,

jsf composite-component

5
推荐指数
1
解决办法
3354
查看次数

复合组件必需属性在 Mojarra 2.0.3 中引发异常

我一直在玩 JSF 2.0 复合组件,但我对composite:attribute标签中的 require 属性的用途有点困惑。该文档说,如果页面作者必须为此属性提供值,则 required 属性为 true。

我已经将其解释为意味着必须为所有具有required=true. 我还假设空字符串是有效值。这就是它在 Mojarra 2.0.2 中的工作方式。

使用这个简单的托管 bean:

@ManagedBean(name = "simpleMB")
@ViewScoped
public class SimpleManagedBean implements Serializable {

   private static final long serialVersionUID = -1;

   private String whatever;

   ... setter and getter
}
Run Code Online (Sandbox Code Playgroud)

和复合组件:

<composite:interface>
    <composite:attribute name="value" required="true" />
</composite:interface>

<composite:implementation>
    <h:outputText value="Value: '#{cc.attrs.value}'" />    
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

这些标签适用于 Mojarra 2.0.2:

<foo:bar value="" />
<foo:bar value="#{simpleMB.whatever}" />
Run Code Online (Sandbox Code Playgroud)

但是,当我升级到 2.0.3 时,只有第一个标签有效。第二个标记导致此错误消息:

/requiredAttribute.xhtml @20,42 <foo:bar> The following attribute(s) are 
required, but no …
Run Code Online (Sandbox Code Playgroud)

composite-component jsf-2

5
推荐指数
1
解决办法
2496
查看次数

JSF递归复合组件

我有一个递归的对象bean结构,就像

Master DTO列表 - >值 - > Master DTO列表

我正在尝试创建一个递归复合组件,其中包含一个输入文本和一个值绑定到值字段的按钮.我正在调用相同的组件来构建子类型,但它给了我堆栈溢出错误.

我尝试使用包含面板中的呈现属性,基于列表是否为空但不起作用.我试图在c:中包含对复合组件(来自复合组件内)的调用,但它不起作用.

我总是得到一个StackOverflowError.

有关如何构建递归复合组件的任何帮助都会有所帮助.谢谢你的时间!

recursion composite-component jsf-2

5
推荐指数
1
解决办法
2153
查看次数

组件ID形式:composite:j_id2已在视图中找到

/test.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:composite="http://java.sun.com/jsf/composite/components">
    <f:view>

        <h:head>
            <title>Default Title</title>
        </h:head>

        <h:body>
            <h:form id="form">
                <composite:test id="composite"/>
            </h:form>
        </h:body>

    </f:view>

</html>
Run Code Online (Sandbox Code Playgroud)

/resources/components/test.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:composite="http://java.sun.com/jsf/composite/components"
      xmlns:p="http://primefaces.org/ui">

    <head>
        <title>(For validation only)</title>
    </head>

    <body>
    <cc:interface>
    </cc:interface>

    <cc:implementation>

        <p:panel header="header foo bar">

            <p:panel>
                <f:facet name="header">
                    <h:outputText value="foo"/>

                    <h:outputText value="bar"/>
                </f:facet>
            </p:panel>

        </p:panel>

    </cc:implementation>

</body>

</html>
Run Code Online (Sandbox Code Playgroud)

这种组合给出:

GRAVE: Error Rendering View[/test.xhtml]
java.lang.IllegalStateException: Component ID form:composite:j_id2 …
Run Code Online (Sandbox Code Playgroud)

duplicates composite-component jsf-2

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

扩展UIComponentBase时如何保存状态

我正在创建一个复合组件,它将包装数据表以实现非常简单的分页.我需要在ajax请求之间保存状态(当前页码).

我尝试在FacesComponent中创建字段,但我发现它们在JSF生命周期中被删除了:

@FacesComponent(value = "bfTableComponent")
public class BFTableComponent extends UIComponentBase implements NamingContainer {

    private int currentPageNumber;
    ...
Run Code Online (Sandbox Code Playgroud)

我似乎无法在任何地方找到这样做的简明指南!在创建复合组件时,如何在请求之间保存状态?

java java-ee composite-component jsf-2 state-saving

5
推荐指数
1
解决办法
2576
查看次数

组件在ui:repeat中具有相同的id

不幸的是,如果你试图动态创建标签,那么primefaces accordionPanel在版本2.2.1中效果不佳.这是我的情况,我需要在用户点击添加图标时创建手风琴,如果他点击x图标则删除.没问题,我已经创建了自己的复合组件,就像你在这里看到的那样:

<c:interface>
    <c:attribute name="titulo" default="" required="false" />
    <c:attribute name="renderizar" default="true" required="false" />
    <c:attribute name="width" required="false" default="300"/>
    <c:facet name="extra" required="false" />
</c:interface>

<c:implementation>
    <h:outputStylesheet library="css" name="hrgiAccordion.css" target="head" />
    <h:outputStylesheet library="css" name="clearfix.css" target="head" />
    <h:outputScript library="js" name="hrgiAccordion.js" target="head" />
    <h:panelGroup layout="block" rendered="#{cc.attrs.renderizar}"
    styleClass="hrgi-accordion clearfix" style="width: #{cc.attrs.width}px;">
        <div class="hrgi-cabecalho-accordion clearfix"
            onclick="abrirAccordion(this)">
            <h:outputLabel value="#{cc.attrs.titulo}" />
            <c:renderFacet name="extra" required="false"/>
        </div>
        <h:panelGroup layout="block" class="hrgi-conteudo-accordion clearfix">
            <c:insertChildren />
        </h:panelGroup>
    </h:panelGroup>
</c:implementation>
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我有一些具体的需求...手风琴选项卡的内容是一些选择和一个带有inputField和一个微调器(由我再次创建)的动态表,你可以在这里看到用户界面:

Popup forma de pagamento

当用户在微调器中插入值时,标签"Total das parcelas"应该更新,但只有当对话框只有一个折叠式选项卡时它才会更新!看看生成的HTML代码,我看到不同手风琴标签中的微调器是相等的!可能这就是我无法更新值的原因.以下是此对话框的代码:

<ui:composition template="../templates/popupSubmit.xhtml">
<ui:param name="titulo" value="#{vendaMsg['popup.forma_pagamento.titulo']}"/>
<ui:param name="popup" value="#{modeloPopupFormaPagamento}"/>
<ui:param name="controladorPopup" value="#{controladorPopupFormaPagamento}"/> …
Run Code Online (Sandbox Code Playgroud)

primefaces composite-component jsf-2 uirepeat

5
推荐指数
1
解决办法
4414
查看次数

Managed Bean as Facelet参数使复合组件无法解析

在给定的情况下,我想将Facelet与不同的ManagedBeans一起使用,因此About操作bean作为参数给出:

<?xml version="1.0" encoding="UTF-8" ?>
<!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" >
<h:body>
    <ui:include src="ratings.xhtml" >
      <ui:param name="createAction" value="#{myOneCreateAction}" />
      <ui:param name="ratings" value="#{context.ratings}" />
    </ui:include>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

我给create动作作为参数value="#{myOneCreateAction}"

在该构面中,一个组件也在其他页面上多次使用-因此,我尝试在复合组件中对其进行重构。

<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:io="http://java.sun.com/jsf/composite/inoutComponents">
<ui:composition>
    <rich:dataTable id="ratingTblId" 
    value="#{ratings}" 
    var="rating">
        <rich:column>
             <io:removeButton
                 id="removeButton"
                 actionMethod="#{createAction.removeRating}"
                 immediate="true"
                 render=":#{rich:clientId('ratingTblId')}" />

             <h:commandButton
                 id="removeButton2"
                 actionListener="#{createAction.removeRating}"
                 immediate="true" >                    
                    <f:ajax render="ratingTblId" />
              </h:commandButton>
        </rich:column>
</rich:dataTable>
</ui:composition>
</html>
Run Code Online (Sandbox Code Playgroud)

参见,如何actionMethod="#{createAction.removeRating}"针对组件给出方法。该组件本身如下所示:

<ui:composition 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:cc="http://java.sun.com/jsf/composite">
    <!-- INTERFACE --> …
Run Code Online (Sandbox Code Playgroud)

jsf facelets composite-component jsf-2

5
推荐指数
1
解决办法
1516
查看次数

在视图中使用复合组件两次在JSF中重复组件ID

我在我的公司"继承"了一个JSF 2(JSF 2.2.7)应用程序并面临java.lang.IllegalStateException,因为两个组件似乎具有相同的ID.

视图的结构如下(为了说明目的,我提取了相关代码,它可能包含一些拼写错误/无效语法,因为我更改了一些名称):

<p:commandButton id="editButton"
   action="#{controller.prepareItem()}"
   update=":itemEditDlg" oncomplete="PF('itemtEditDlg').show()" />


<comp:editItemDlg id="itemEditDlg"  />

<p:dialog id="anotherDlg" >
   <h:form id="anotherForm">
      <c:forEach items="#{controller.allArgs}" var="arg" >
         <!-- next line is the problem -->
         <comp:mycomponent arg="#{arg}"  />
      </c:forEach>
   </h:form>
</p:dialog>
Run Code Online (Sandbox Code Playgroud)

mycomponent.xhtml如下所示:

<cc:interface>
    <cc:attribute name="arg" required="true" />
</cc:interface>
<cc:implementation>
    <p:inputText id="argValue" value="#{cc.attrs.arg}" />
    <p:message id="argValueMessage" for="argValue" />
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)

重要:mycomponent组件也在editItemDlg中使用(与"anotherDlg"中的方式相同),即在对话框和forEach循环中)

如果我点击editButton,我得到:

java.lang.IllegalArgumentException: Component ID anotherForm:j_idt192:argValue  
has already been found in the view.
Run Code Online (Sandbox Code Playgroud)

它相当奇怪,因为"anotherDlg"在这种情况下并不是开放的,但显然已经渲染了.

我在StackTrace中获得以下信息(仅显示相关部分):

         +id: j_idt192
             type: javax.faces.component.UINamingContainer@399bd0dc
              +id: j_id2
               type: javax.faces.component.UIPanel@24ad3910
                +id: argValue  <===============
                 type: org.primefaces.component.inputtext.InputText@687d5c3f …
Run Code Online (Sandbox Code Playgroud)

jsf facelets composite-component

5
推荐指数
1
解决办法
2310
查看次数