标签: composite-component

如何将焦点设置到 ui:repeat JSF 中的最后一项

我有一个可滚动的 div,我喜欢将焦点设置在最后一个元素。我怎样才能实现这个目标?

<div class="scrolldiv">  
<h:form id="form">  
  <ui:repeat...> 
    <h:panelGrid columns="2"...>  
      <h:graphicImage../>  
      <h:outputText.../>  
    </h:panelGrid>  
  </ui:repeat>  
</h:form>  
</div>  
Run Code Online (Sandbox Code Playgroud)

javascript jsf composite-component

3
推荐指数
1
解决办法
456
查看次数

如何通过clientId访问复合组件的兄弟

我有一个复合组件捆绑一些输入字段.该组件将在页面上多次使用,并包含一个用于复制其他组件的值的按钮.为此,我需要通过其clientId访问其中一个兄弟姐妹作为目标

<f:ajax execute=":XXX:siblingId" render="...">

我的问题在于构建此ID.我有兄弟的名字,我可以确保它与包含复制按钮的组件位于相同的命名容器中,但我无法控制完整的嵌套层次结构,因此它可能是:form:foo:bar:parent:child或只是form:parent:child.所以基本上我想获得当前复合组件的前缀,但没有组件自己的ID,然后附加要从中复制的组件的ID.

这与以下问题类似:

但是,这两个答案使用PrimeFaces-sepcific功能,如@parentwidgetVar,这并不适用于我的项目.

在试验EL的隐式对象时,我基本上尝试了与第二个问题的海报相同的东西 - 结果相同:cc.parent.clientId总是空的.我也尝试cc.namingContainer.clientId了两种组合,唉 - 没有成功.特别是parent不能按预期工作的事实让我感到困惑......

那么:是否存在与组件库无关的方式来访问包含复合组件命名容器的"路径"?该如何parent对象应该工作,尤其是:我们什么时候可以使用它,何时不?

PS:我正在考虑使用复合的完整clientId然后修剪它的实际ID fn:split,但是,如果有更直接的方式我会乐意使用它.

jsf clientid naming-containers composite-component

3
推荐指数
1
解决办法
2806
查看次数

在 f:ajax 渲染中引用复合组件 ID

我正在编写一个复合组件,用于包装输入元素,并在其下方添加一个“可选字段”名称和 h:message 元素。这是组件(在 input.xhtml 文件中):

<composite:interface/>
<composite:implementation>
  <div>
  #{component.children[1].setStyleClass(component.children[1].valid ? '' : 'inputError')}
    <composite:insertChildren/>
  </div>
  <h:panelGroup styleClass="optional" 
      rendered="#{!component.parent.children[1].required}" 
      layout="block" >
    #{msgs['common.optional.field']}
  </h:panelGroup>
  <h:message id="msgId" 
       for="#{component.parent.children[1].id}" errorClass="error"/>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

同样,该组件的预期用途是包装一个 h:input* 元素,该元素应该是它在 using 页面中的第一个和直接子元素。

在使用页面中,我会写:

    <h:form id="f1">
    <h:panelGrid border="0" columns="2" style="width: 80%">
        <f:facet name="header">
            <col width="40%" />
            <col width="60%" />
        </f:facet>
        <h:outputLabel styleClass="sectionBody" for="i1"
            value="Input 1"></h:outputLabel>
            <my:input id="ii1">
            <h:inputText id="i1" size="20" maxlength="20" tabindex="0"
            required="true" label="Input 1">
            </h:inputText>
            </my:input>
        <h:outputLabel styleClass="sectionBody" for="i2"
            value="Input 2"></h:outputLabel>
            <my:input id="ii2">
            <h:inputText id="i2" size="20" maxlength="20" tabindex="0"
                label="Input 2"> …
Run Code Online (Sandbox Code Playgroud)

jsf clientid composite-component ajax-update

3
推荐指数
1
解决办法
3333
查看次数

通过将复合组件放置在 /WEB-INF 内来防止直接访问复合组件

我正在尝试在我的 Web 应用程序中定义一些复合组件。根据我阅读的教程,我必须将 xhtml 文件放置在位于 webcontent 的资源文件夹中。这个解决方案是有问题的,因为它会使这些文件可供公众通过 URL 访问。有没有办法将此组件放入 web-inf 文件夹中,并使 jsf 查找那里的文件?如果没有,是否有其他方法可以避免直接访问?

谢谢。

PS:我已经研究过这个答案,如果我正确理解了 BalusC 的答案,我打算做的事情是可能的。

security jsf web-inf composite-component jsf-2

3
推荐指数
1
解决办法
1760
查看次数

如何向复合组件的属性添加文档

我有一个复合组件,看起来像这样:

<composite:interface>           
    <composite:attribute name="confirmUnload" type="java.lang.Boolean" default="false" />
    <composite:attribute name="showLoader" type="java.lang.Boolean" default="true" />
    <composite:attribute title="test test" name="menuFormIds" type="java.lang.String" default="menuForm" />
    <composite:attribute name="unloadMessage" type="java.lang.String" default="You have unsaved data" />            
</composite:interface>

<composite:implementation>
    <div title="unloadEventComponent">...</div>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

在页面中使用此组件时,eclipse自动完成将帮助处理属性.但是,有时候如果不查看代码就很难理解属性的作用,这对用户体验没有帮助.

有没有办法以eclipse自动完成中显示的方式将属性描述添加到复合组件?

PrimeFaces组件在选择属性时通常有描述,但它们使用自定义组件而不是复合组件.

documentation jsf composite-component jsf-2

3
推荐指数
1
解决办法
1746
查看次数

每个请求都会重新创建复合组件中的支持bean

我有两个变量"userId"和"name".当我点击例如"SHOW USERID"按钮时它工作正常并设置"renderUserId = true"并用"render"显示它,但是如果我点击另一个"SHOW"按钮,那么Bean重建并且我松了"renderUserId = true",它变为"false"和"renderName = true",因此它显示正常,但USERID被隐藏.

我的问题是,当我渲染xhtml时,如何避免丢失bean值?

这是我的代码的简单模拟.

注意:如果我在"h:commandButton"中使用"actionListener"而不是"f:setPropertyActionListener"我有相同的结果,那么bean就是重构

example.xhtml

<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:a4j="http://richfaces.org/a4j"
    xmlns:cc="http://java.sun.com/jsf/composite">

    <cc:interface componentType="com.bean.ExampleBean">
        <cc:attribute name="userId" type="java.lang.Integer"/>
        <cc:attribute name="name" type="java.lang.String"/>
    </cc:interface>

    <cc:implementation>

        <h:panelGrid id="example_panel" columns="1" width="100%">

            <h:outputText value="USERID: #{cc.attrs.userId}" rendered="#{!cc.attrs.renderUserId}"/>

            <a4j:commandButton value="SHOW USERID" render="example_panel"
                rendered="#{!cc.attrs.renderUserId}">
                <f:setPropertyActionListener value="#{true}"
                    target="#{cc.attrs.renderUserId}"/>
            </a4j:commandButton>                
            <a4j:commandButton value="HIDE USERID" render="example_panel"
                rendered="#{cc.attrs.renderUserId}">
                <f:setPropertyActionListener value="#{false}"
                    target="#{cc.attrs.renderUserId}"/>
            </a4j:commandButton>                


            <h:outputText value="NAME: #{cc.attrs.name}" rendered="#{!cc.attrs.renderName}"/>

            <a4j:commandButton value="SHOW NAME" render="example_panel"
                rendered="#{!cc.attrs.renderName}">
                <f:setPropertyActionListener value="#{false}"
                    target="#{cc.attrs.renderName}"/>
            </a4j:commandButton>                
            <a4j:commandButton value="HIDE NAME" render="example_panel"
                rendered="#{cc.attrs.renderName}">
                <f:setPropertyActionListener value="#{false}"
                    target="#{cc.attrs.renderName}"/>
            </a4j:commandButton>                


        </h:panelGrid>

    </cc:implementation>

</ui:composition> …
Run Code Online (Sandbox Code Playgroud)

java composite-component jsf-2 managed-bean

3
推荐指数
1
解决办法
5502
查看次数

如何在复合组件中加载资源包属性文件?

我的组件库目录树设置如下:

resources
    mylib
        css
            mycomponent.css
        properties
            mycomponent.properties
        mycomponent.xhtml
Run Code Online (Sandbox Code Playgroud)

我想加载 mycomponent.xhtml 中的属性文件以用于消息。这样做的正确方法是什么?是否有 f:loadbundle 类型的解决方案?

jsf resourcebundle properties-file composite-component

3
推荐指数
1
解决办法
682
查看次数

基于复合组件中的动态列表渲染多个 &lt;option&gt; 元素

我正在使用 JSF 2.2 和 Prime Faces 5.3。

我正在尝试创建一个具有动态选项的 html5 组件。目标是创建类似于 f:selectItems 标记的内容

目前我有以下用于 datalist 标签的代码(datalist.xhtml 文件)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns:cc="http://xmlns.jcp.org/jsf/composite">

<cc:interface></cc:interface>

<cc:implementation>
    <datalist id="#{cc.attrs.id}">
        <cc:insertChildren/>
    </datalist>
</cc:implementation>

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

以及单个选项的以下内容(option.xhtml 文件)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns:cc="http://xmlns.jcp.org/jsf/composite">

<cc:interface>
    <cc:attribute name="value" type="java.lang.String" default=""/>
    <cc:attribute name="label" type="java.lang.String" default=""/>
</cc:interface>

<cc:implementation>
    <option value="#{cc.attrs.value}" label="#{cc.attrs.label}"/>
</cc:implementation>

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

通过这种方法我可以创建这样的东西

<myTag:dataList id="test">
    <myTag:option value="1" label="label1"/>
    <myTag:option value="2" label="label2"/>
    <myTag:option value="3" label="label3"/>
</myTag:dataList>
Run Code Online (Sandbox Code Playgroud)

但我需要一些能让我拥有动态选项列表的东西。我希望编写以下代码(或类似的代码)

<myTag:dataList id="test">
    <myTag:options value="#{myBean.myCollection}" var="mySingleObj" itemValue="mySingleObj.value" itemLabel="mySingleObj.label"/>
</myTag:dataList>
Run Code Online (Sandbox Code Playgroud)

jsf composite-component html-datalist

3
推荐指数
1
解决办法
892
查看次数

在复合组件内部引用组件(反之亦然)

我在使用 Primefaces (v5.2) 时遇到一两个问题:

复合组件中引用组件

假设我有一个包含输入字段的复合组件:

我的输入字段.xhtml

<composite:interface>
    <composite:attribute name="value" />
    ...
</composite:interface>

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

(当然,真正的应用程序做得“多一点”。)

在我的页面中,我现在像这样使用这个字段:

索引.xhtml

<my:myinputputfield value=#{controller.inputstring} />
Run Code Online (Sandbox Code Playgroud)

这有效。但是:知道我想从外部引用该内部输入字段,例如用于标签或消息。东西喜欢

<composite:interface>
    <composite:attribute name="value" />
    ...
</composite:interface>

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

当然这不起作用,因为id没有为myinputfield. 所以第一个想到的想法是像这样扩展 cc:

myinputfield.xhtml (新)

<composite:interface>
    <composite:attribute name="id" />
    <composite:attribute name="value" />
    ...
</composite:interface>

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

这也不起作用。我尝试了不同的事情并阅读了不同的答案和文章,但没有找到答案。


第二个问题正好相反:

复合组件之外引用组件

这一次换个角度想象一下。我有一个自定义的标签、消息或在我的情况下是一个工具提示:

我的工具提示.xhtml

<composite:interface>
    <composite:attribute name="for" />
    <composite:attribute name="value" /> …
Run Code Online (Sandbox Code Playgroud)

jsf primefaces composite-component

3
推荐指数
1
解决办法
1466
查看次数

JSF 2.0复合组件进入jar

我正在尝试创建一个复合组件,以便在我的项目中使用,因此,我创建了一个名为"componentes-ui-web"的项目,并推出了2个xhtml文件,这些文件是我的组件.

项目的结构如下:

src
> |-> main
> >       |->java
> >          |->META-INF
> >              |->faces-config.xml
> >              |->resources
> >                    |->componentes
> >                           |->popupSimples.xhtml
> >                           |->popupSubmit.xhtml
Run Code Online (Sandbox Code Playgroud)

这是代码popupSubmit.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:ui="http://java.sun.com/jsf/facelets"
        xmlns:icecore="http://www.icefaces.org/icefaces/core"
        xmlns:ice="http://www.icesoft.com/icefaces/component"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:composite="http://java.sun.com/jsf/composite"
        xmlns:ace="http://www.icefaces.org/icefaces/components">
    <composite:interface>
        <composite:attribute name="modal" default="false" />
        <composite:attribute name="visivel" default="false" />
        <composite:attribute name="style" default="" />
        <composite:attribute name="titulo" default="Sem título definido" />
        <composite:attribute name="exibidoQuandoTipoUsuario" default="" />
        <composite:attribute name="metodoFechar"
        method-signature="java.lang.Void fechar()" required="true" />
        <composite:attribute name="metodoSubmeter"
        method-signature="java.lang.Void …
Run Code Online (Sandbox Code Playgroud)

jar facelets composite-component jsf-2

2
推荐指数
1
解决办法
9486
查看次数