【问题标题】:Problems using c:foreach with ui:include使用 c:foreach 和 ui:include 的问题
【发布时间】:2012-01-14 02:48:54
【问题描述】:

我有一个名为“StartsideElement”的自定义对象类型的数组列表。

 <c:forEach items="#{startsideClient.brukerelementer}" var="element" begin="0" step="1">                         
  <div class="#{element.headerStyle}">
   <div>
    <table width="100%" cellpadding="0" cellspacing="0">
     <tr height="25px">
      <td width="5px">
       <img src="#{facesContext.externalContext.requestContextPath}/resources/gfx/topmenu_lefttop.gif" width="5" height="5" />
       <img src="#{facesContext.externalContext.requestContextPath}/resources/gfx/topmenu_left.gif" width="5" height="15" />

       <img src="#{facesContext.externalContext.requestContextPath}/resources/gfx/topmenu_leftbottom.gif" width="5" height="5" />
      </td>
      <td background="#{facesContext.externalContext.requestContextPath}/resources/gfx/topmenu_bg.gif" style="width: 920px;">
       <img src="#{facesContext.externalContext.requestContextPath}/resources/gfx/Calendar_16x16.png" width="16" height="16" style="float:left; margin-bottom:2px;"/>
      <div class="headerText" style="text-align:left; position:relative; left: 15px; margin-top:2px"><h:outputText value="#{element.tittel}" /></div>
      </td>
      <td width="5px">
       <img src="#{facesContext.externalContext.requestContextPath}/resources/gfx/topmenu_righttop.gif" width="5" height="5" />

       <img src="#{facesContext.externalContext.requestContextPath}/resources/gfx/topmenu_right.gif" width="5" height="15" />
       <img src="#{facesContext.externalContext.requestContextPath}/resources/gfx/topmenu_rightbottom.gif" width="5" height="5" />
      </td>
     </tr>
    </table>
   </div>
   <!-- InnholdsDIV til Kommende oppgaver -->
   <div class="#{element.boxStyle}" style="clear: both;">          
    <div class="boxDokumenterFont">                            
     <ui:include src="#{element.mal}" />       
    </div>
   </div>
  </div>
  <!-- END CONTAINER FOR WIDGET -->             
 </c:forEach>

这里的问题是循环 c:foreach 会循环 6 次,这是正确的,但是 element 的值会随着我的使用而改变。创建的框的标题&lt;h:outputText value="#{element.tittel}" /&gt; 将不对应正确的值。如果我这样做:&lt;h:outputText value="#{element.tittel element.tittel}" /&gt;element.tittel 打印的值将不会在两个地方相同。

任何关于做什么的建议都会很棒。我不能使用&lt;ui:repeat&gt;,因为#{element.mal} 包含一个我需要传递给ui:include 的文件名,它不适用于ui:repeat

【问题讨论】:

    标签: java jsf


    【解决方案1】:

    如果我理解正确,标题 &lt;h:outputText value="#{element.tittel}" /&gt; 在您的自定义对象“StartsideElement”中随着 jsf 代码迭代您的 arrayList 而发生变化。您希望该值保持不变而不改变。

    为什么不在“StartsideElement”自定义对象中创建另一个具有正确对应值的属性?

    【讨论】:

    • 我认为他的意思是 element 不仅在每次循环迭代时更改,而且在每次引用时都会更改,这听起来像是一个错误。但也许我读错了描述。
    • 问题是每次我访问该元素时,该元素都会更改为 toto2 所说的。由于时间限制,通过另一种方式构建代码解决了我的问题。
    猜你喜欢
    • 2011-12-18
    • 2012-12-04
    • 1970-01-01
    • 2011-11-23
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    相关资源
    最近更新 更多