Я пишу составной компонент JSF datepicker, который поддерживается средством выбора даты jquery-ui (у меня нет возможности использовать библиотеки компонентов)
У меня заработал функционал, но сейчас я пытаюсь упростить интерфейс компонента, удалив ненужные атрибуты.
Один из атрибутов, предоставляемых моим компонентом, называется «значение». Я ожидаю, что пользователь компонента предоставит здесь ссылку на el, например. #{myCarBean.selectedCar}
Что я заметил, так это то, что компонент только когда-либо читает значение атрибута. Сеттер никогда не вызывается.
Мне удалось обойти это, представив этот метод как clientBehaviour. Но теперь у меня есть actionListener, который вызывается через это clientBehaviour (для установки значения), а также атрибут «value», который считывает значение из #{cc.attrs.values}
.
Как я могу иметь один атрибут, который может читать/записывать атрибут «значение» в базовый управляемый компонент, предоставленный страницей использования?
Вот код:
<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>
And the using page :
<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>