I have this composite component:
<cc:interface>
<cc:attribute name="image_1" />
<cc:attribute name="image_2" />
<cc:attribute name="image_3" />
</cc:interface>
<cc:implementation>
<div id="slider-container">
<div id="slider-small">
<h:graphicImage library="images" name="#{cc.attrs.image_1}" />
<h:graphicImage library="images" name="#{cc.attrs.image_2}" />
<h:graphicImage library="images" name="#{cc.attrs.image_3}" />
</div>
</div>
</cc:implementation>
I use it in this way :
<cs:small_slider
image_1="about/1.jpg"
image_2="about/2.jpg"
image_3="about/3.jpg"
/>
but is limited to three attributes. What should I do if I have to send more than three, using the same composite component, like this:
<cs:small_slider
image_1="about/1.jpg"
image_2="about/2.jpg"
image_3="about/3.jpg"
image_4="about/4.jpg"
image_5="about/5.jpg"
/>
I want to do this to reuse the component and I don’t want to create another.
UPDATE:
Follow @BalusC approach renders the follow HTML:
<!-- small slider -->
<div id="slider-container">
<div id="slider-small">
<img src="/brainset/javax.faces.resource/1.jpg.xhtml?ln=images" />
<img src="RES_NOT_FOUND" />
<img src="RES_NOT_FOUND" />
</div>
<div id="frame-slider-small"></div>
</div><!-- end #slide-container -->
It not found the others images, only the first. I’m sure those images: ‘about/2.jpg’ and ‘about/3.jpg’ exist.
That’s not possible and it also violates the DRY principle.
Your best bet is to either pass it as a
List<String>from the bean instead so that you can iterate over it using<ui:repeat>:with
Or define it as a hardcoded comma-separated string instead and use JSTL
fn:split()to split them into aString[]which you in turn feed to<ui:repeat>:with
Unrelated to the concrete problem, try to be consistent with Java/JSF naming conventions. I’d rename your
small_slider.xhtmltorenameSlider.xhtmlso that you can use it as<cs:smallSlider>, which is nicely in line with all normal JSF components.