This question already has answers here:
Is it possible to update non-JSF components (plain HTML) with JSF ajax?
(3 answers)
Closed 6 years ago.
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?
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.
Related
This question already has an answer here:
Ajax update/render does not work on a component which has rendered attribute
(1 answer)
Closed 6 years ago.
I having a list of items to display, where I wanted to restrict user from clicking the ShowMore button when the set of items have all displayed.
my code:
<div class="row center">
<h:commandButton id="morebutton" rendered="#{homeBean.hasMoreProjects()}" styleClass="hoverable btn-large yellow lighten-2 black-text" value="SHOW MORE" >
<f:ajax listener="#{homeBean.showMore()}" render="result morebutton" />
</h:commandButton>
</div>
The issue here is the button will not be hide whenever the list of items is all shown, but it will be hide when I refresh the whole page.
How can I check the method when I check the button?
Any helps will be much appreciate, Thanks
EDIT 1:
this question is slightly different from the question Ajax update/render does not work on a component which has rendered attribute, this question stating the commandLink button targeting to the button itself for hide/show rendering where the issue from the link is to target the input form
You always need to render the parent component in jsf2, this should work:
<a4j:outputPanel id="morebuttonPanel" styleClass="row center">
<h:commandButton id="morebutton" rendered="#{homeBean.hasMoreProjects()}" styleClass="hoverable btn-large yellow lighten-2 black-text" value="SHOW MORE" >
<f:ajax listener="#{homeBean.showMore()}" render="result morebuttonPanel" />
</h:commandButton>
</a4j:outputPanel>
How to show some content inside light-box of primefaces as I have to show some information about the image as no. of likes,no. of comments,and also have to provide option to post comments so on and so forth?
On xhtml page I have written this:
<p:lightBox styleClass="imagebox">
<c:forEach var="event1" items="#{event.files}" varStatus="cnt">
<h:outputLink value="#{listOfFilesForEventBean.getImage854By480ProfileUrl(event1)}" title="#{event1.location.locationName}">
<h:graphicImage value="#{listOfFilesForEventBean.getImageIconProfileUrl(event1)}"/>
</h:outputLink>
</c:forEach>
</p:lightBox>
Where files is list of image profiles that I am iterating.
And I want along with the image which is displayed on lightbox some information about the image should be displayed.
I had similar problem. If somebody is still looking for the answer here is my solution.
I did not find easy way to have some additional controls inside p:lightBox item.
Guess it assigns own JavaScript handlers to all its children and that makes a problem.
Also I had the problems with using commandButton inside ui:repeat. So I'm using my own implementation of p:lightBox and p:remoteCommand to call other actions(like post comments, delete image etc). Something like that:
<p:remoteCommand name="deleteImage" update="imagesGrid"
actionListener="#{imageBean.deleteImage}" />
<h:panelGroup id="imagesGrid">
<ui:repeat var="item" value="#{imageBean.list}">
<div class="docThumbContainer">
<div class="docPlaceholder"></div>
<div class="docThumbImage">
<h:outputLink value="/images?id=#{item.imageId}">
<h:graphicImage value="data:image/jpg;base64,#{item.thumbnail}"
alt="" />
</h:outputLink>
</div>
<div class="docThumbButtons">
<p:commandButton type="button" value="Delete"
onclick="deleteImage([{name:'imageId', value:#{item.imageId}}]);" />
</div>
</div>
</ui:repeat>
</h:panelGroup>
ImageBean:
public void deleteImage(ActionEvent event) {
ImageManager manager = getManager();
manager.deleteImage(StringUtil.parseInt(getUrlParameter("imageId"), -1));
}
Of course it is simplified replacement for p:lightBox. To show the full image in the overlay with prev/next buttons you need additional work. E.g. using p:dialog etc
Hi i have this sceneario, i have 2 forms each of them with preprendId=false, the first one have a h:panelGroup that i want to update from the second h:form. The problem that i have
is that i dont know what String i have to put for update my panelGroup. I tried with this strings:
panelGroupComboId and :panelGroupComboId
But i always get: Cannot find component with expression ":panelGroupComboId" referenced from...
Because i need to use preprendId=false at least in the first form (where my panelGroup is) i cannot set preprendIf=true, but if i did it i could update my component with any problem using: :loginFormRegistroId:panelGroupComboId
But remember i NEED to use preprendId= false, when i use preprendId=false i can see using
firebug that my h:panelGroup is converted as a div with the id panelGroupComboId, then thats why i dont how do i have to call for update it.
Is preprendId=true the only way to this works?
FIRST FORM
<h:form id="loginFormRegistroId" prependId="false">
<h:panelGroup id="panelGroupComboId" layout="block">
<select id="comboCarreraId" name="comboCarreraId" class="form-control">
<ui:repeat value="#{miBean.list}" var="obj">
<option value="#{obj.id}">#{obj.name}</option>
</ui:repeat>
</select>
</h:panelGroup>
</h:form>
SECOND FORM
<h:form prependId="false">
<p:remoteCommand
name="cargarCarrerasRemoteCommand"
process="#this"
actionListener="#{miBean.myListener}"
update="panelGroupComboId">
</p:remoteCommand>
</h:form>
By the way i DONT want to update the entire first FORM, just my h:panelGroup
Remove prependId from the forms. Update the code as
<h:form>
<p:remoteCommand
name="cargarCarrerasRemoteCommand"
process="#this"
actionListener="#{miBean.myListener}"
update=":loginFormRegistroId:panelGroupComboId">
</p:remoteCommand>
</h:form>
I have a ui:repeat. I want it to refresh for every 5 seconds. I tried p:poll but it doesnt work. Is there any way to make this working?
<ui:repeat value="#{videoImpl.fGetAllComments()}" var="v" id="commentlist">
<div class="comment-entry"><h:outputText value="#{v.comment}"/></div>
</ui:repeat>
<p:poll update="commentlist" interval="5" />
The <ui:repeat> doesn't generate any HTML by itself. So there is no element with id="commentlist" in the HTML output and hence the JS code behind <p:poll> can't find anything to update.
Wrap it in another JSF component which renders a fullworthy HTML element, such as <h:panelGroup>, and update it instead.
<h:panelGroup id="commentlist">
<ui:repeat value="#{videoImpl.fGetAllComments()}" var="v">
<div class="comment-entry">#{v.comment}</div>
</ui:repeat>
</h:panelGroup>
<p:poll update="commentlist" interval="5" />
I'm working with jsf2 and want to use the ajax-functionality of it. Problem: I've already seen some ajax refresh things. But nothing to refresh a whole div...
I have a xhtml page with data from my bean, and i don't really want to refresh all fields of it, it would be easier to refresh the whole ui:include...
does anybody knows a solution? Or do I have to refresh all fields manually?
best regards
Just put them in some container component with an ID and use it in render attribute of f:ajax.
<h:form>
<h:commandButton value="submit" action="#{bean.submit}">
<f:ajax render=":foo" />
</h:commandButton>
</h:form>
<h:panelGroup id="foo" layout="block">
<ui:include src="include.xhtml" />
</h:panelGroup>
Note that <h:panelGroup layout="block"> renders a <div>. If you omit the layout attribute, it defaults to <span> (only whenever there are any attributes which needs to be rendered to HTML, like id).
Okay BalusC, but I'm still having a problem with the includes and ajax.
my index.xhtml includes a search.xhtml and a results.xhtml
the ajax-part is in search.xhtml and the toRender-id is in results.xhtml...
so at rendering the jsf-tags there's the problem that there's no toRender-Id at this time...
EDIT:
Okay the problem was not the arrangement of the includes, it was that the ajax-parts must be in the same form tag like this:
<h:form>
<div id="search" class="search">
<ui:insert name="search" >
<ui:include src="search.xhtml" />
</ui:insert>
</div>
<h:panelGroup id="ajaxResult" layout="block">
<ui:insert name="searchResults" >
<ui:include src="searchResults.xhtml" />
</ui:insert>
</h:panelGroup>
</h:form>
search contains f:ajax tag, ajaxResult is toRenderId
best regards, emre