This question already has an answer here:
Ajax update/render does not work on a component which has rendered attribute
(1 answer)
Closed 4 years ago.
I am using JSF 2.2 with PrimeFaces 6.1 and, in order to make an "optional" validation, every time the p:inputNumber loses focus, a p:button is updated and it is rendered or not based on a specific validation method:
<div class="ui-grid-col-2">
<p:inputNumber id="quantidade" value="#{vendaMB.quantidadeItem}" decimalPlaces="1" minValue="0.0" onfocus="this.setSelectionRange(0, this.value.length)">
<p:ajax event="blur" process="#this" update="btnImgQtdeUltrapassa"/>
</p:inputNumber>
</div>
<div class="ui-grid-col-1">
<p:button id="btnImgQtdeUltrapassa" title="Quantidade inserida ultrapassa quantidade em estoque" disabled="true" icon="fa fa-fw fa-warning" rendered="#{vendaMB.verificaQtdeEstoque()}" styleClass="btn-round"/>
</div>
Strangely, when I use update="#form", the update happens perfectly, but there are other processes and methods that can't be re-executed on this form update, therefore, I can't use this approach. Could someone help me solve this problem?
Also, I am using a "p:button" but I actually just need the icon and something similar to its "title" attribute. I'd be grateful if you could also suggest me another tag or approach to use instead of this "improvised icon".
You can't do a "update=" on an item which might be conditionally rendered. You can't update it, if it's not rendered.
Simply do this:
<h:panelGroup id="updateme">
<p:commandButton rendered="#{bean.condition}"/>
</h:panelGroup>
now you can use
<p:ajax update="updateme"/>
Related
This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 3 years ago.
I'm using Soteria 1.0.1 , Mojarra 2.3.9 and PrimeFaces 6.1. on Glassfish 5.1
Inside a ui:repeat the ajax listener is not called on the change-event. The listener is called only once on the click-event.
Which event should be used?
I've used foreach to iterate, but the listener is not called.
I've changed the execute-attribute from #this into :frmOverviewPlant:selectDyna3 and :rep_mandatory3:selectDyna3 , but still the listener is not called
If I change f:ajax event="change" into f:ajax event="click" the listener is called but only once.
If I omit the attributes execute: and render: , and use immediate="true" instead, the listener is called. But this is not useful because the value is not sent back to the listener.
If I use the same selectOneMenu outside ui:repeat, the listener is called even without setting the ajax-attribute execute.
Which component could be used to iterate over a dynamically generated list? That list changes each time another main-item is selected. The details of that main-item are rendered in the form.
Is this behaviour caused by ui:iterate? or by invalid values for the ajax-attributes event: or render: or execute: ?
<h:form id="frmOverviewPlant" prependId="false">
<table style="width: 30%" border="0">
<ui:repeat id="rep_mandatory3" value="#{assortiment.mandatoryPropertyList}" var="VBNprop">
<tr><td class="noWrap"> <h:outputText styleClass="#{VBNprop.codevaluesW.value == null ? 'error' : ''}" value="#{msg[VBNprop.codevaluesW.mainCode]}"/></td>
<td class="noWrap">
<h:selectOneMenu id="selectDyna3" value="#{assortiment.plantdetail.addedProperty}" > <f:selectItems value="#{VBNprop.codevaluesList}" />
<f:ajax event="change" listener="#{assortiment.checkAddProperties}" execute="#this" render=":frmOverviewPlant:idTabView:grp_properties"/>
</h:selectOneMenu>
</td>
</tr>
</ui:repeat>
</table>
</h:form>
I expect the listener is called in order to update the main-item with the selected option.
I couldn't able to give you a straight answer to your question since your statements say that everything is good. but I have noticed the following in your code.
We can't create id inside since the JSF view won't allow duplicate ids.
Make sure your listener method should have the param AjaxBehaviorEvent For (example - methodXXXX(AjaxBehaviorEvent event)
Please make sure we shouldn't render the parent group of which includes the drop-down actions.
Let's try valueChangeListener which is specifically introduced for value change actions.
If you want to render the parent area of then I suggest you make it possible by javascript since I didn't find any solution by using any JSF components.
I'm asking how I can achieve updating a specific element of a loop?
e.g.
<h:form>
<ui:repeat var="element" value="#{bean.elements}" varStatus="status">
<h:outputtext value="#{element.text}" id="#{element.id}" />
<p:commandLink update="#{element.id}" >
<h:outputtext value="UpdateTextField #{element.id}" />
</p:commandLink>
</ui:repeat>
</h:form>
I know that status.index doen't work since its view-rendered. Also the "dynamic" index-setting also doen't work since its view-rendered... But how can i achieve that when the button is clicked, it updates (ajax) the outputtext? Is this only possible with c:forEach?
its ViewScoped and the form must be outside of the loop. otherwise i would solve it with update="#form", but here its not possible
thanks for any help!
Since both ui:repeat and c:forEach generate different dynamic Component Ids for the elements you can't Guarantee the update an individual Item out of all generated items from outside.
I think best approach for this kind of problem would be placing a h:panelGroup around ui:repeat or c:forEach itself and update the h:panelGroupitself.
Please see the following code:
<h:panelGrid columns="2" border="0" cellpadding="0" cellspacing="0">
<p:inputText id="text" value="#{xTest.input}">
<p:ajax process="text" update="searchResult" event="keyup" />
</p:inputText>
<h:panelGroup layout="block" id="searchResult" style="border: none;">
#{xTest.input}
</h:panelGroup>
</h:panelGrid>
xTest is just a dummy bean with a field to hold the input, which is presented in the panelGroup.
Now this works fine as long as I don't update #form in the ajax tag. If I do, the ajax tag will fire the first keyup, but not after any subsequent. I've seen Balusc answer about commandLink/button problems: commandButton/commandLink/ajax action/listener method not invoked or input value not updated and maybe this has something to do with no 7 in that list. However, I don't understand it, and I would like to know what I can do to come around this problem.
In my view JSF 2.2 was not properly released. It has some weird bugs and fixing times are quite slow at the moment. What I can tell you is that:
There are a few things that are working with the new namespaces and some that work with the old ones. You can try switching them and test
There are bugs with the jsf.js, especially if you are using multipart forms: see bug
If you render a component that contains the form, try adding the form in the render as well render='comp #form. (might help)
I would suggest switching back to JSF 2.0 and migrating to 2.2.* when it is of adequate quality
I'm using JSF with PrimeFaces to make an application as an assignment for college. I'm struggling to get something working. I'm using PrimeFaces and I have a tabview which contains 5 tabs. In one of those tabs I have a dataTable which has several rows and columns. This all works fine, but the problem is that I want to submit the form without rerendering the (entire page). The thing is, every column in the dataTable has a selectBooleanCheckbox, and when that checkbox is selected, a button should disappear. If it's unselected the button should appear. This works fine with onchange="this.form.submit()" or onclick="this.form.submit()" but it refreshes the entire application, and it causes the first tab to be selected, rather than the one I was at. So I'm looking for a solution to be able to submit and re-render some stuff without refreshing the entire program. This is my code:
<body>
<h:form id="customerForm">
<p:dataTable id="customerlist" var="c" value="#{customerBean.customerList}">
<p:column>
<f:facet name="header">Select</f:facet>
<center>
<p:selectBooleanCheckbox value="#{c.selected}" onchange="this.form.submit()"/>
</center>
</p:column>
</p:dataTable>
<h:commandButton id="testtest" value="test" rendered="#{customerBean.numberSelected() == 0}"/>
</h:form>
</body>
I removed most of the columns for the sake of simplicity. What is the solution to this? I've tried using ajax, but that didn't work
<p:selectBooleanCheckbox value="#{c.selected}">
<f:ajax event="click" execute="#form" render="#none"/>
</p:selectBooleanCheckbox>
Do you really need to submit the whole form? If it's enough that the view is being rerenderd try just to update the form. For that you can use the primefaces ajax event.
<p:selectBooleanCheckbox value="#{c.selected}">
<p:ajax update="#form"/>
</p:selectBooleanCheckbox>
If this does not work, please tell us what "..ajax, didn't work" exactly mean. Is there any POST Request submitted? Is any Action/Setter called?
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 have a component that I want to show/hide after user hits a commandButton.
It's like this:
<h:commandButton id="showButton" value="#{bean.wasPressed ? 'Hide' : 'Show'}">
<f:ajax listener="#{bean.toggle()}" render="explanation showButton" />
</h:commandButton>
and
<h:panelGroup id="explanation" rendered="#{bean.wasPressed}">
<h:outputText value="something" />
</h:panelGroup>
The bean.toggle() simply sets the wasPressed property to true or false appropriately. I am using <h:form prependId="false">.
The problem is the value of the render attribute of my button. It explicitly enlists both: explanation and showButton.
As long as the showButton is always present (it only changes its label), the explanation is present only if the wasPressed property is true. Otherwise it says:
malformedXML: During update: explanaition not found
How can I solve this problem?
I would like not to revert to hiding the element in the source code, so I would like not to use any jQuery toggle(-) or any way of hiding the element using style="display: none" or any of this stuff.
Is it even achievable in JSF 2.1?
You cannot update elements which are not rendered , rendered=false "is a JSF way to" to remove elements from the DOM Tree ,
its not like css display:none or visibility:hidden <- this two will keep the elements in the DOM tree but hidden , while the JSF rendered=false wont even render (keep) the element in the DOM tree (you wont even see it in the "view source" of the page)
So in you case you need to wrap the panelGroup with another `panelGroup' and update the id of the wrapper
<h:commandButton id="showButton" value="#{bean.wasPressed ? 'Hide' : 'Show'}">
<f:ajax listener="#{bean.toggle()}" render="explanationWrapper showButton" />
</h:commandButton>
<h:panelGroup id="explanationWrapper">
<h:panelGroup id="explanation" rendered="#{bean.wasPressed}">
<h:outputText value="something" />
</h:panelGroup>
</h:panelGroup>
also look at similar question
Can you update an h:outputLabel from a p:ajax listener?