0

I have a situation where i need to execute a specific component for every row inside a ui:repeat:

<h:form id="form">
   <h:panelGroup id="mediaCards" layout="block">

    <ui:repeat id="media" value="#{mediaManager.entries}" var="m">
      <div class="media-card">

        <h:outputText id="keyword" value="#{m.keyword}" />

        <h:outputText id="producer" value="#{m.producer}" />
        <h:outputText id="location" value="#{m.location}" />

        <!-- many other fields -->        
      </div

    </ui:repeat>
  <h:panelGroup>

  <ui:remove>actual solution</ui:remove>
  <h:commandButton value="Send keywords to Server">
      <f:ajax execute="mediaCards"/>
  </h:commandButton>

</h:form>

Currently i execute the whole HTML which is too heavy since i have lots of media-cards and i am only intereseted in executing just every keyword for each row.

As an alternative, i could attach an ajax-change listener to every keyword. but making a server-communication on each change-event is also not the best here.

<h:outputText id="keyword" value="#{m.keyword}">
    <f:ajax/>
</h:outputText>

What i would like to have is a dynamic approach of

<h:commandButton value="Send keywords to Server">
     <f:ajax execute="media:0:keyword media:1:keyword media:2:keyword media:3:keyword"/>
</h:commandButton>

Can we do this in a preferably clean way?

Note: i use mojarra 2.2.14 without primcefaces but omnifaces.

Edit: replacing ui:repeat with c:foreach leads to the same problem:

<c:forEach value="#{mediaManager.entries}" var="m" varStatus="row">
    <div class="media-card">
       <h:outputText id="keyword_#{row.index}" value="#{m.keyword}" />
    </div
</c:forEach>

<ui:remove>what to do here?</ui:remove>
<h:commandButton value="Send keywords to Server">
     <f:ajax execute="keyword"/>
</h:commandButton>
Steve
  • 384
  • 1
  • 7
  • 17
  • start reading https://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense most likely you need a jstl `c:foreach` – Kukeltje Mar 20 '18 at 10:56
  • Keep in mind that this does **not** reduce the amount of data that is submitted to the server. Check the OmniFaces `o:form` for this – Kukeltje Mar 20 '18 at 11:13
  • hi, replacing ui:repeat with c:foreach does not help. at the end it leads to the same problem. – Steve Mar 20 '18 at 11:16
  • No it does not... You can assign each element in the c:foreach a unique ID (see the link) and 'execute' those... – Kukeltje Mar 20 '18 at 11:18
  • replacing h:form with o:form only affects ominfaces 3.0. i am using 2.6.8. what i need is a dynamic approach for the row without writing manually a list of execute="media:1:keyword media:n:keyword ..." – Steve Mar 20 '18 at 11:31
  • The execute can be created in a bean and via EL added to the component. So there is no need to create it manually. But how many cards do you have? if you have more than a hundred you have a design issue. If you have less, then the 'execute' might not result in the performance increase that you hope for. Looks like your primary problem is to determine **what** to send to the server and what not – Kukeltje Mar 20 '18 at 12:01
  • its about 30-40 cards, not more. i don't really have a performance issue, just thought about avoiding sending data to the server which is not of interest. you are right: there is not a notable differece here between execute="media:0:keyword" and execute="mediaCards" – Steve Mar 20 '18 at 12:11

0 Answers0