Jsf 2 复合组件中的读/写属性
我正在编写一个JSF datepicker复合组件,它由jQueryUI的datepicker支持 我已经实现了功能,但我现在正试图通过删除不必要的属性来简化组件的接口 我的组件公开的属性之一称为“值”。我希望组件的用户在这里提供el参考,例如。Jsf 2 复合组件中的读/写属性,jsf-2,composite,Jsf 2,Composite,我正在编写一个JSF datepicker复合组件,它由jQueryUI的datepicker支持 我已经实现了功能,但我现在正试图通过删除不必要的属性来简化组件的接口 我的组件公开的属性之一称为“值”。我希望组件的用户在这里提供el参考,例如。 {myCarBean.selectedCar} 我注意到组件似乎只读取属性的值。setter似乎从未被调用过 通过将此方法公开为ClientBehavior,我成功地解决了这个问题。 但是现在我有了一个actionListener,它通过这个Clien
{myCarBean.selectedCar}
我注意到组件似乎只读取属性的值。setter似乎从未被调用过
通过将此方法公开为ClientBehavior,我成功地解决了这个问题。
但是现在我有了一个actionListener,它通过这个ClientBehavior(设置值)调用,还有一个“value”属性,它从{cc.attrs.values}
读取值
如何使一个属性既可以读取“value”属性,又可以将其写入使用页面提供的底层managedBean
代码如下:
<ui:component xmlns="http://www.w3.org/1999/xhtml" xmlns:util="http://discovery.co.za/mytags" xmlns:c="http://java.sun.com/jsp/jstl/core" 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:cc="http://java.sun.com/jsf/composite">
<cc:interface componentType="modal">
<cc:attribute name="value" type="java.util.Date" shortDescription="An El expression representing the managed bean field to which the selected date will be wired."></cc:attribute>
<cc:attribute name="minYear" type="java.lang.Integer" shortDescription="An El expression representing a managed bean field which should return an Integer indicating the year component of the minDate"></cc:attribute>
<cc:attribute name="minMonth" type="java.lang.Integer" shortDescription="An El expression representing a managed bean field which should return an Integer indicating the month component of the minDate.(January is 0)"></cc:attribute>
<cc:attribute name="minDay" type="java.lang.Integer" shortDescription="An El expression representing a managed bean field which should return an Integer indicating the day component of the minDate."></cc:attribute>
<cc:attribute name="maxYear" type="java.lang.Integer" shortDescription="An El expression representing a managed bean field which should return an Integer indicating the year component of the maxDate"></cc:attribute>
<cc:attribute name="maxMonth" type="java.lang.Integer" shortDescription="An El expression representing a managed bean field which should return an Integer indicating the month component of the maxDate"></cc:attribute>
<cc:attribute name="maxDay" type="java.lang.Integer" shortDescription="An El expression representing a managed bean field which should return an Integer indicating the day component of the maxDate"></cc:attribute>
<cc:attribute name="render" type="java.lang.String" />
<cc:clientBehavior name="change" targets="#{cc.clientId}:dateInput" event="change" />
</cc:interface>
<cc:implementation>
<div id="#{cc.clientId}">
<h:inputText id="dateInput" value="#{cc.attrs.value}" styleClass="jquery-datepicker"
onclick="modifyDatePickerOptions('#{cc.attrs.clientId}', #{cc.attrs.minYear}, #{cc.attrs.minMonth}, #{cc.attrs.minDay}, #{cc.attrs.maxYear}, #{cc.attrs.maxMonth}, #{cc.attrs.maxDay} );">
<f:ajax execute="@form" event="change" render="#{cc.attrs.render}" />
</h:inputText>
</div>
</cc:implementation>
和使用页面:
<h:form id="datePickerForm">
<my:datepicker render=":datePickerForm:datePickerAjax" value="#{datePickerBean.selectedDate}" minYear="1999" minMonth="0" minDay="1" maxYear="2019" maxMonth="0" maxDay="1">
<f:ajax event="change" listener="#{datePickerBean.selectedDate}" />
</my:datepicker>
<h:panelGroup id="datePickerAjax" layout="block">
<br />
<b><h:outputText value="You selected : #{datePickerBean.selectedDate}" rendered="#{datePickerBean.selectedDate != null}" /></b>
</h:panelGroup>
</h:form>
您需要在inputText
字段中添加一个转换器。您可以在inputText
中嵌套一个
标记来实现这一点。查看所有可用的属性。出于好奇,为什么不:“(我没有使用组件库的选项)”@Kukeltje:项目的架构师觉得他们不想依赖组件库,因为新的更好的组件库总是出现,他们不希望迁移开销。所以我只限于mojarra 2.1。他们至少允许我使用Omnifaces,即使是像autoComplete这样的简单组件,他们也不想使用例如PrimeFaces,但他们想要自定义复杂度,比如?好啊祝他们在数据表、筛选、分页排序、树表和其他组件方面好运;-)我知道这是个奇怪的决定。更重要的是,考虑到我们的其他应用程序已经在PrimeFaces上运行。。。那为什么不再来一杯呢?谢谢是的我应该这么做。设置日期的managedBean实际上将日期声明为字符串(即使在组件的接口中,“value”属性声明为java.util.date)。。我不知道为什么会这样。