简体   繁体   English

如何将ArrayList / lists / iterables参数传递给JSF1.2自定义组件

[英]How to pass ArrayList/lists/iterables argument to a JSF1.2 custom components

I am trying to show a list of images from my backing bean which has a function 我试图显示我的支持bean的图像列表,它具有一个功能

public getImgList(){
    return ArrayList<string>imgPathList;
}

Now this List has to be rendered to a equivalent output of images which are displayed side by side. 现在,必须将此列表渲染为并排显示的等效图像输出。 like 喜欢

[image][image][image]

Which is not possible if I use <h:datatable> , because it will render all of them one per row, And I cant find any method by which I can render them using custom component as I will have to pass the list of images to the custom components. 如果我使用<h:datatable> ,这是不可能的,因为它将每行渲染一个,而且我找不到任何方法可以使用自定义组件渲染它们,因为我必须将图像列表传递给自定义组件。 Can anyone please explain how to pass a list to a custom component in JSF 1.2 Mojarra? 任何人都可以解释如何将列表传递给JSF 1.2 Mojarra中的自定义组件?

Just specify it as attribute. 只需将其指定为属性即可。

<my:component value="#{bean.imagePaths}" />

It'll just be available as exactly the same type in the value property of your custom component class with help of UIComponent#getValueExpression() . UIComponent#getValueExpression()帮助下,它将在自定义组件类的value属性中以完全相同的类型提供。


Given the fact that you're already asking this trivial question, I think developing the custom component is going to take a lot of time for you. 鉴于您已经在提出这个微不足道的问题,我认为开发自定义组件会花费大量时间。 Also, since a lot of solutions already exist, you're basically reinventing the wheel here. 此外,由于已经存在很多解决方案,你基本上都在重新发明轮子。 I'd suggest to take a different route, namely just using existing tags/components. 我建议采用不同的路线,即仅使用现有的标签/组件。 There are two options: 有两种选择:

  • Use JSTL <c:forEach> . 使用JSTL <c:forEach> This will work if you don't put it inside another iterating component like <h:dataTable> and you aren't rendering input elements in the loop. 如果你不把它放在像<h:dataTable>这样的另一个迭代组件中并且你没有在循环中渲染输入元素,这将有效。

     <c:forEach items="#{bean.imagePaths}" var="imagePath"> <img src="#{imagePath}" /> </c:forEach> 
  • Use a 3rd party component library which offers a fullworthy JSF iterating component which doesn't render any HTML. 使用第三方组件库,它提供了一个完整的JSF迭代组件,它不会呈现任何HTML。 I'd suggest Tomahawk's <t:dataList> . 我建议Tomahawk的 <t:dataList>

     <t:dataList value="#{bean.imagePaths}" var="imagePath"> <img src="#{imagePath}" /> </t:dataList> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM