【发布时间】:2013-10-17 00:53:48
【问题描述】:
我正在开发一个 JSF Web 应用程序,我需要在其中使用周期性作为数据结构。以下是我使用的 Java 类:
public class Periodicity implements Serializable {
private Integer value = 0;
private PeriodicityType type;
//Getter and setters
}
public enum PeriodicityType {
DAY, WEEK, MONTH, YEAR
}
这样我可以为我的任务指定不同的周期,可以将值与PeriodicityType结合起来。
我还创建了一个名为 periodicityInput.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:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<composite:interface>
<composite:attribute name="value" required="true" />
<composite:attribute name="disabled" required="false" default="false" />
</composite:interface>
<composite:implementation>
<h:panelGrid columns="2" id="#{cc.id}">
<p:spinner value="#{cc.attrs.value.value}" min="1"
id="value_spinner" disabled="#{cc.attrs.disabled}" />
<p:selectOneMenu value="#{cc.attrs.value.type}" style="width:200px"
disabled="#{cc.attrs.disabled}">
<f:selectItem noSelectionOption="true"
itemLabel="#{windowsMessages.NOT_ASSIGNED}" />
<f:selectItems value="#{viewUtils.periodicityTypes}" />
</p:selectOneMenu>
</h:panelGrid>
</composite:implementation>
</h:body>
</html>
基本上我有一个spinner 元素和一个selectOneMenu,以便为周期性选择一个值和一个类型。也有可能不选择任何类型,在这种情况下,输入的数值必须为零。或者,更好的是,如果没有选择周期性,则必须将输入转换为 null/null 元组。
正如我在一些sites 中读到的那样,有机会在验证方法中访问 id 来一次验证多个 JSF 组件:
UIInput confirmComponent = (UIInput) component.getAttributes().get("confirm");
问题是,如何调整它以便在没有固定 id 的复合组件中使用?
【问题讨论】:
标签: validation jsf jsf-2 composite-component