2011-08-01 4 views
1

본인은 '제목'속성의 값을 삽입 할 필요가 있지만, 그것이 있어야 뭔가처럼 그렇게 궁금 해요 :하나의 ui에서 두 개의 배열을 반복하는 방법 : repeat?

<!-- calling the component --> 
<cs:small_slider images="products/eletricity.jpg,products/water.jpg" > 

<!-- the component with dynamic rendering --> 
<cc:interface> 
    <cc:attribute name="images" type="java.lang.String" required="true" /> 
</cc:interface> 

<cc:implementation> 
    <div id="slider-container"> 
     <div id="slider-small"> 
      <ui:repeat value="#{fn:split(cc.attrs.images, ',')}" var="image"> 
       <h:graphicImage library="images" name="#{image}" /> 
      </ui:repeat> 
     </div> 
    </div> 
</cc:implementation> 
:

<ui:repeat //..> 
    <h:graphicImage library="images" name="#{image}" title="#{title}" /> 
</ui:repeat> 

난 단지 구분하는 쉼표 하나의 문자열을 보낼 수 있습니다

아이디어가 있으십니까?

답변

3

두 배열의 관련 항목에 동일한 배열 인덱스가있는 경우 varStatus (<ui:repeat>)에 사용할 수있는 배열 중 하나의 현재 루프 인덱스로 액세스 할 수 있습니다.

사용법 :

<cs:small_slider 
    images="products/eletricity.jpg,products/water.jpg" 
    titles="Electicity,Water" 
/> 

복합 구성 요소 :

<cc:interface> 
    <cc:attribute name="images" type="java.lang.String" required="true" /> 
    <cc:attribute name="titles" type="java.lang.String" required="true" /> 
</cc:interface> 

<cc:implementation> 
    <ui:param name="images" value="#{fn:split(cc.attrs.images, ',')}" /> 
    <ui:param name="titles" value="#{fn:split(cc.attrs.titles, ',')}" /> 

    <div id="slider-container"> 
     <div id="slider-small"> 
      <ui:repeat value="#{images}" var="image" varStatus="loop"> 
       <h:graphicImage library="images" name="#{image}" title="#{titles[loop.index]}" /> 
      </ui:repeat> 
     </div> 
    </div> 
</cc:implementation> 
+0

수 없습니다 UI : ViewScope 콩을 깰 반복? – Dejell

+0

@BalusC, 감사합니다! 그것은 매력처럼 작동합니다 =) –

관련 문제