0

I am trying to update the element "entryDiv" in my xhtml from a button inside a form like this:

<div id="entryDiv">    
    <div>                              
        <h:form id="myForm">
            <c:forEach items="#{foodPlanManagementBean.loadRestaurantsHistory()}" var="restaurantHistoryEntry">
                    <p:commandButton value="MyName" update="entryDiv"/>
            </c:forEach>
        </h:form>
    </div>

    Some more unrelated elements here...
</div>

However, this way all I am left with is a ComponentFoundException, tell me that the component could not be located:

Cannot find component for expression "entryDiv" referenced from "form:myForm:j_idt25".

I already read up a bit on SO and I found one solution proposing to put a : in front of the "entryDiv", but that doesn't turn out to give me any different results.

How could I fix this?

Sossenbinder
  • 4,852
  • 5
  • 35
  • 78

1 Answers1

7

JSF can't see the id of your div if it is not a JSF component so you need to convert your div to a h:panelGroup

 <h:panelGroup id="entryDiv" layout="block">
     <div>                              
        <h:form id="myForm">
            <c:forEach items="#{foodPlanManagementBean.loadRestaurantsHistory()}" var="restaurantHistoryEntry">
                    <p:commandButton value="MyName" update=":entryDiv"/>
                </div>
            </c:forEach>
        </h:form>
    </div>
  </h:panelGroup>

if you don't put layout="block" it will render a span instead of a div.

raven
  • 2,381
  • 2
  • 20
  • 44
  • Thanks for the help! Sadly, I'm still getting the error, even after replacing my div with a panelGroup – Sossenbinder Apr 29 '16 at 15:52
  • @Sossenbinder in this case you need to add the `:` – raven Apr 29 '16 at 16:00
  • Thats what I thought as well, but even that doesn't change a thing :( Are the parent elements of the "entryDiv"-panelGroup of any significance? – Sossenbinder Apr 29 '16 at 16:02
  • @Sossenbinder it shouldnt matter are they h:panelGroup too? why dont you try updating the root parent? – raven Apr 29 '16 at 16:08
  • 1
    @Sossenbinder there is this tag `` below the button is that ok ? – raven Apr 29 '16 at 16:09
  • @Sossenbinder i think i found the bug, try with a `p:panel` instead of the `h:panelGroup` and remove `layout="block"` and let me know. – raven Apr 29 '16 at 16:17
  • 1
    I fixed the mistake on my own. My own stupidity which was not displayed in this code, sorry :) Your answer was correct – Sossenbinder Apr 29 '16 at 16:38