【发布时间】:2012-03-23 19:20:10
【问题描述】:
在将下面提到的复合组件用于一组按钮(按钮的计数可以是 1 到 3)时,我遇到了“JSF 中不允许空 id 属性”的问题(我在 Tomcat 上使用 Mojarra 2-0-8 -7) 。
<?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 rendered = "#{cc.attrs.buttonCount eq '3'}">
<h:commandButton id="#{cc.attrs.button3Id}" styleClass="#{cc.attrs.button3Style}">
<f:ajax listener="#{cc.attrs.button3Action}" immediate="true"/>
</h:commandButton>
</h:panelGroup>
</composite:implementation>
</html>
使用上述抄送。
<Buttons:myButton txtHeader="Title" txtDescription="text1"
txtAction="TextAction." button1Style="btnSave" buttonCount ="1" button1Id="btnSaveConf" button1Action="#{MyBean.save()}"></Buttons:myButton>
有没有更好的方法可以根据计数或主页上的任何类似输入动态生成按钮。 注意:- id、styles 和 action 名称应该不同。
【问题讨论】: