我一直在玩 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) 大家好.我正在为名为flot的javascript图表库创建一个组件.
<cc:interface>
<cc:attribute name="data" required="true" />
</cc:interface>
<cc:implementation>
<div id="placeholder" style="width:600px;height:300px;"></div>
<script type="text/javascript">
//<![CDATA[
$(function () {
var d1 = [#{cc.attrs.data}];
$.plot($("#placeholder"), [ d1 ]);
});
//]]>
</script>
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的少量代码.我遇到的问题是如何在页面上随机生成div标签,以便我可以输出多个图表.显然,在目前的状态下它不会那样做.我需要将值传递给javascript函数.
我知道我可以创建另一个需要id的属性,用户必须指定id,但我注意到很多组件都不需要id.似乎在重要的ajax/javascript库中,如primefaces和icefaces,这些id是随机的.
谢谢你的帮助.
我目前正在创建一个JSF复合组件,其方法签名可以接受参数.
这是摘录:
<composite:interface>
....
<composite:attribute name="activateHeroMethod" method-signature="java.util.List action(id.co.sofcograha.core.Dto, id.co.sofcograha.core.Dto)" />
</composite:interface>
<composite:implementation>
....
<p:commandLink value="#{hero.map['heroName']}"
process="@this"
update="#{cc.attrs.update}"
oncomplete="infoRaceDialog.hide()"
image="ui-icon ui-icon-search">
<f:setPropertyActionListener value="#{hero}"
target="#{cc.attrs.activateHeroMethod(infoRaceBean.race, hero)}" />
</p:commandLink>
....
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)
target ="#{cc.attrs.activateHeroMethod(infoRaceBean.race,hero)}"因以下错误消息而失败:
javax.faces.view.facelets.TagAttributeException: /resources/sofco/infoRace.xhtml @57,76 target="#{cc.attrs.activateHeroMethod(infoRaceBean.race, hero)}" /resources/sofco/infoRace.xhtml @57,76 target="#{cc.attrs.activateHeroMethod(infoRaceBean.race, hero)}" Illegal attempt to pass arguments to a composite component lookup expression (i.e. cc.attrs.[identifier]).
at com.sun.faces.facelets.tag.TagAttributeImpl.getValueExpression(TagAttributeImpl.java:401)
at com.sun.faces.facelets.tag.TagAttributeImpl.getValueExpression(TagAttributeImpl.java:351)
at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler.applyAttachedObject(SetPropertyActionListenerHandler.java:128)
at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler.apply(SetPropertyActionListenerHandler.java:101)
Run Code Online (Sandbox Code Playgroud)
是否可以从复合组件的属性中调用参数化方法?我认为我可以处理多个作为在一个方法中使用多个参数的解决方法,但我不喜欢这种方法,因为它会随着参数的增加而变大.
我可以将每个参数包装成1个包装器对象,但我仍然很好奇是否有办法解决调用多个参数的方法的问题.
请分享你的想法!
谢谢.
/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) 我正在创建一个复合组件,它将包装数据表以实现非常简单的分页.我需要在ajax请求之间保存状态(当前页码).
我尝试在FacesComponent中创建字段,但我发现它们在JSF生命周期中被删除了:
@FacesComponent(value = "bfTableComponent")
public class BFTableComponent extends UIComponentBase implements NamingContainer {
private int currentPageNumber;
...
Run Code Online (Sandbox Code Playgroud)
我似乎无法在任何地方找到这样做的简明指南!在创建复合组件时,如何在请求之间保存状态?
我有一个JSP 2.0 <ui:component>,其中<p:dataTable>有一个列使用Composite来呈现关于某些内容的特殊边框.现在我需要识别<p:dataTabe>位于内容中的ajax呈现属性.
<ui:component>
<p:dataTable id="dataTable" var="userItem" ... />
<p:column>
<my:borderBox id="borderBox">
<p:commandButton
action="#{userController.doDelete(userItem.id)}"
value="delete"
update="?????"/> <!-- How to address the dateTable? -->
</my:borderBox>
</p:column>
</p:dataTable>
<ui:component>
Run Code Online (Sandbox Code Playgroud)
我的BorderBox:
<html xmlns:composite="http://java.sun.com/jsf/composite" ...>
<composite:interface>
<composite:attribute name="styleClass" default="" type="java.lang.String"/>
</composite:interface>
<composite:implementation>
<h:panelGroup ...>
...
<composite:insertChildren/>
</h:panelGroup>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)
我的想法是使用类似的东西
update=":#{component.namingContainer.parent.namingContainer.clientId}:dateTable
但是component.namingContainer.parent接缝是空的.
当我<p:commandButton>用以下语句替换时:
Parent ClientId 1: #{component}
Parent ClientId 2: #{component.namingContainer}
Parent ClientId 3: #{component.namingContainer.clientId}
Parent ClientId 4: #{component.namingContainer.parent}
Parent ClientId 5: #{component.namingContainer.parent.namingContainer}
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
Parent ClientId …Run Code Online (Sandbox Code Playgroud) 我有一个复合组件:
<composite:interface>
<composite:attribute name="actionMethod"
method-signature="java.lang.String action()" required="true" />
</composite:interface>
<composite:implementation>
<h:form>
<h:commandButton id="captureButton" value="#{msgs.capture}"
action="#{cc.attrs.actionMethod}" />
</h:form>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)
和一个调用该复合组件的页面:
<ezcomp:captureTitle actionMethod="#{saveDecisionsBean.captureTitle}" />
Run Code Online (Sandbox Code Playgroud)
和一个包含动作的bean:
@Named(value="saveDecisionsBean")
@SessionScoped
public class SaveDecisionsBean extends BackingBeanBase {
...
public String captureTitle() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
现在这是我的问题.当我尝试运行它时,它说SaveDecisionsBean没有属性captureTitle.因此,我必须添加一个SaveDecisionsBean#getCaptureTitle()方法.当我这样做时,它运行得很好.我为什么要定义这个方法?它说它<composite:attribute />是一种方法,它被用作一种动作.
这是我得到的确切错误消息:
javax.el.PropertyNotFoundException: /index.xhtml @54,86
actionMethod="#{saveDecisionsBean.captureTitle}":
The class 'com.example.persistence.SaveDecisionsBean_$$_javassist_209'
does not have the property 'captureTitle'.
Run Code Online (Sandbox Code Playgroud)
(出于SEO原因:其他实现可能会显示类名WeldClientProxy.)
我们在项目的其他组件中使用复合组件.在JBoss 7.1.0上一切正常,但在JBoss 7.1.1上,我们得到如下错误:
No handlers found for exception javax.faces.view.facelets.TagException:
/resources/components/my/bigComponent.xhtml @21,47 <my:nestedComponent>
Tag Library supports namespace: http://java.sun.com/jsf/composite/components/my,
but no tag was defined for name: nestedComponent
Run Code Online (Sandbox Code Playgroud)
我们尝试了这个JBoss社区线程中提出的解决方案,但它没有改变我们的问题(在这种情况下接缝我们不是唯一的,并且解决方案可能不起作用,因为我们也在ui:define模板文件的标签中) .
这是我们的两个组成部
嵌套:
<!DOCTYPE html PUBLIC ...>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:my="http://java.sun.com/jsf/composite/components/my" >
<cc:interface componentType="...">
<h:panelGroup>
<cc:attribute name="someAttribute" />
</h:panelGroup>
</cc:interface>
<cc:implementation>
<my:nestedComponent content="a text" />
</cc:implementation>
</html>
Run Code Online (Sandbox Code Playgroud)
嵌套:
<!DOCTYPE html PUBLIC ...>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface>
<cc:attribute name="content" />
</cc:interface>
<cc:implementation>
<h:outputText …Run Code Online (Sandbox Code Playgroud) 我正在制作复合组件,我有commandButton.但它不起作用.
用法:
<wk:commandButton value="Non-Ajax actionListener" actionListener="#{ioBean.saveListener}" />
Run Code Online (Sandbox Code Playgroud)
组件代码:commandButton.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface>
<cc:attribute name="value" />
<cc:attribute name="action" method-signature="void action(javax.faces.event.ActionEvent)" default="null"/>
<cc:attribute name="actionListener" method-signature="void actionListener(javax.faces.event.ActionEvent)" default="null"/>
<cc:attribute name="styleClass" default="button" />
</cc:interface>
<cc:implementation>
<p:commandButton
value="#{cc.attrs.value}"
action="#{cc.attrs.action}"
actionListener="#{cc.attrs.actionListener}"
styleClass="#{styleClass}">
<cc:insertChildren />
</p:commandButton>
</cc:implementation>
</html>
Run Code Online (Sandbox Code Playgroud)
这是日志:
0000006c FaceletViewDe E Inner component action not found when retargetMethodExpressions
0000006c FaceletViewDe E Inner component actionListener not found when retargetMethodExpressions
0000006c srt W com.ibm.ws.webcontainer.srt.SRTServletResponse setIntHeader SRVE8094W: Ostrze?enie: nie …Run Code Online (Sandbox Code Playgroud) 这被称为3次,每行一次.(示例表有3行)
....
<ui:param name="rowIndex" value="#{cc.attrs.rowIndex}" />
<ui:param name="rowActive" value="#{cc.attrs.activeRow}" />
<c:set var="index" value="#{rowIndex}" type="java.lang.Long"/>
<c:set var="activeRowIndex" value="#{rowActive}" type="java.lang.Long"/>
<c:choose>
<c:when test="${index == 2}">
ACTIVE
</c:when>
<c:when test="${index != activeRowIndex}">
${index} - ${activeRowIndex} - INACTIVE
</c:when>
<c:otherwise>
NONE
</c:otherwise>
</c:choose>
....
Run Code Online (Sandbox Code Playgroud)
结果:
0 - 1 - 不活跃
1 - 1 - 不活跃
2 - 1 - 不活跃
我原以为:
0 - 1 - 不活跃
没有
活性
我很无能为什么结果与我的预期有很大的不同.所以我希望你能帮助我:-)
jsf-2 ×8
jsf ×4
primefaces ×2
clientid ×1
duplicates ×1
facelets ×1
java ×1
java-ee ×1
java-ee-6 ×1
javascript ×1
jboss7.x ×1
jstl ×1
state-saving ×1