2017-03-31 17 views
0

나는 JQuery와 - UI의 날짜 선택기에 의해 백업됩니다 복합 구성 요소 날짜 선택기 JSF를 쓰고 있어요 속성. I가 기능을 입수했습니다읽기/쓰기는 복합 구성 요소

(I 구성 요소 라이브러리를 사용하는 옵션이 없습니다) 작동하지만 이제 불필요한 특성을 제거하여 구성 요소의 인터페이스를 단순화하려고합니다.

내 구성 요소가 노출하는 특성 중 하나를 "값"이라고합니다. 구성 요소의 사용자가 예를 들어 el 참조를 제공 할 것으로 기대합니다. #{myCarBean.selectedCar}

주목해야 할 것은 구성 요소가 속성 값을 읽는 것만 보인다는 것입니다. 설정자는 결코 호출되지 않습니다.

나는이 방법을 clientBehaviour로 노출함으로써이 문제를 해결할 수있었습니다. 하지만 이제는이 clientBehaviour (값을 설정하기 위해)와 #{cc.attrs.values}에서 값을 읽는 "value"속성을 통해 호출되는 actionListener가 있습니다.

사용 페이지에서 제공되는 기본 managedBean에 "value"속성을 읽고 쓸 수있는 단일 속성을 어떻게 가질 수 있습니까?

<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> 
+0

호기심에서 벗어났다면 왜 _ : "(구성 요소 라이브러리를 사용할 수있는 옵션이 없음)"_ – Kukeltje

+0

@Kukeltje : 프로젝트의 아키텍트는 컴포넌트 라이브러리에 의존하고 싶지 않다고 느꼈습니다. 새롭고 우수한 구성 요소 라이브러리가 항상 나오고 있으며 마이그레이션 오버 헤드를 원하지 않습니다. 그래서 저는 mojarra 2.1에 국한되었습니다. 그들은 적어도 나를 허용 한 omnifaces 비록 –

+0

심지어 autoComplete 같은 간단한 구성 요소와 함께 그들은 예를 들어 사용하고 싶지 않아요. PrimeFaces.하지만 http://stackoverflow.com/questions/42834630/how-to-execute-client-behaviour-before-the-event-it-targets와 같은 맞춤형 복잡성을 원하십니까? 좋아 ... 데이터 테이블, 필터링, 페이징, 트리 테이블 및 기타 구성 요소 정렬과 함께 행운을 빈다 ;-) – Kukeltje

답변

0

당신은 당신의 inputText 필드에 변환기를 추가 할 필요가 여기에

는 코드입니다. 이를 달성하기 위해 inputText<f:convertDateTime/> 태그를 중첩시킬 수 있습니다. 사용 가능한 모든 속성은 convertDateTime을 참조하십시오.

+0

감사합니다. 그래야합니다. 날짜가 설정된 managedBean은 Date를 String으로 선언합니다 (구성 요소의 인터페이스에서 "value"속성이 java.util.Date로 선언되어 있음에도 불구하고). 왜 이것이 작동하는지 잘 모르겠습니다. –