Primefaces commandButton is calling actionListener method but Not if having "rendered" attribute [duplicate] - primefaces

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Form submit in conditionally rendered component is not processed
(1 answer)
Closed 11 months ago.
I am facing an issue with primefaces(version 8.0) commandButton like, whenever I'm using rendered attribute to satisfy some condition, the method inside actionListener is not firing. But if I don't use the rendered attribute, it is normally invoking the method. I wonder why it's behaving in this way and how can I resolve this.
The commandButton is as,
<p:commandButton value="Display" actionListener="#{dispManagedBean.display}" process="#this"
update="growlMessage" icon="ui-icon-circle-arrow-e" rendered="#{demoManagedBean.isDisplay}" >
<f:attribute name="dispId" value="#{demoManagedBean.dispId}" />
</p:commandButton>
This is not calling dispManagedBean.display method anyway. But if I remove the rendered="#{demoManagedBean.isDisplay}" , then it is hitting the method normally.
Again, I tried with disabled="#{not demoManagedBean.isDisplay}" condition, and again it is not working there too.
I tried with <c:if test=""></c:if> jstl condition, it is not invoking there also.
But I must use that condition, it is the business logic. I cant omit that. How can I achieve this?

Related

"this" is not recognizing in react's input for getting value [duplicate]

This question already has answers here:
Are 'Arrow Functions' and 'Functions' equivalent / interchangeable?
(4 answers)
Closed 2 years ago.
I never understood how that this works if it ever works
in my react I wrote <input onChange={()=>console.log(this.value)} /> Why doesn't it recognize this??? it tells me that it Cannot read property 'value' of undefined
onChange anyone help please :/
React doesn't bind the event listener with the element.
So, the this refers to the class Component in which its defined.
If it was in functional Component then this it undefined
So if your trying to read input elements value use this,
<input onChange={e => console.log(e.target.value)} />
Read More,
Function And Class Components

primefaces disable commandButton

I have below code for primefaces p:commandButton. I have set update and oncomplete attributes to disable commandButton in p:panelGrid of "panelGrid1s4a3b1" and show messages on p:message of "customMessage1s4". But does not know why these two not working. Anyone can help me to make them work?
<p:commandButton id="cmdVerify1s4a2" widgetVar="cmdVerify1s4a2"
value="Verify" action="approveProfileQualifications"
update="#([id$=panelGrid1s4a3b1]), #([id$=customMessage1s4])"
oncomplete="PF(cmdVerify1s4a2).disable(); PF('cmdReject1s4a2').disable();"/>
You are not updating is right. Change your p:commandButton little
update="panelGrid1s4a3b1 customMessage1s4"
while I believe your p:messages like
<p:messages id="customMessage1s4" showDetail="true" autoUpdate="true" closable="true" />
MORE
You can also use keywords to update:
Keywords are the easier way to reference components, they resolve to ids so that if an id changes,
the reference does not need to change. Core JSF provides a couple of keywords and PrimeFaces
provides more along with composite expression support.
Following are the keywords.
#this Standard Current component. #all Standard Whole view. #form
Standard Closest ancestor form of current component. #none Standard No
component. #namingcontainer PrimeFaces Closest ancestor naming
container of current component. #parent PrimeFaces Parent of the
current component. #composite PrimeFaces Closest composite component
ancestor. #child(n) PrimeFaces nth child. #row(n) PrimeFaces nth row.
#previous PrimeFaces Previous sibling. #next PrimeFaces Next sibling.
#widgetVar(name) PrimeFaces Component with given widgetVar.

PrimeFaces Datatable filtering removed when sorting with o:form includeRequestParams="true" [duplicate]

This question already has answers here:
How to choose the right bean scope?
(2 answers)
Closed 4 years ago.
this is an issue following this one: PrimeFaces datatable.filter() and url parameter
is use PrimeFaces-5.1 and omnifaces-2.1 to render a datatable with pagination, filtering and sorting while using request parameters.
my datatable is constructed like this:
<o:form includeRequestParams="true">
<p:dataTable id="hostStateHistoryTable" value="#{HostHistoryBean.hostStateHistoryList}" var="status" widgetVar="statusTable"
filteredValue="#{HostHistoryBean.filteredHostStateHistoryList}"
rowStyleClass="#{status.state eq 0 ? 'up' : null} #{status.state eq 1 ? 'down' : null} #{status.state eq 2 ? 'unreachable' : null}"
rows="50" paginator="true" paginatorTemplate="{PageLinks} {RowsPerPageDropdown}" rowsPerPageTemplate="10,50,100">
<p:column sortBy="#{status.stateTime}">
<f:facet name="header">Start Time</f:facet>
<h:outputText id="Start" value="#{status.stateTime}" />
</p:column>
... all columns
</p:dataTable>
</o:form>
But Sorting is removing the PrimeFaces Datatable Filtering.
I can sort alone and filter alone without problem, but when i sort the datable after filtering it remove the filter. again Clicking on the same filter won't do anything but filtering on another value will display the expected result.
It seems that the o:form will resend the request, including attribute, instead of using the datatable filteredValue.
Edit:
I uploaded an eclipse based MCVE project here: http://www.dacave.fr/stackoverflow/test.faces.rar
Ok so i found out that filteredValue was reseted on each ajax call because of the #RequestScoped.
I think i was kind of mixing up things.
So i switched all #ManagedBeans to #Named
then i created a new #SessionScoped Bean with most of the attributes and i #inject a #RequestScoped bean with the request based attributes into it.
Now everything works as expected

commandButton actionListener isn"t called when an other component is required

I tried <p:commandButton> as shown above, it works correctly.
<p:spinner id="spinnerQte" min="1" value="#{newOpProgramme.quantite}"/>
<p:commandButton id="AjoutEquip" value="Ajouter" actionListener="#{newOpProgramme.addEquipement()}" update="spinnerQte"/>
But, when I tried ti nest this in my global page inside layout, panel, panel-Grid and field-Set, addEquipement() method is not called !
also, thee some fields which have required attribute set to true, I think this is why addEquipement() method isn't called.
Have you an Idea how to fix the problem.
thank you
I fixed the problem by adding process attribute to <p:commandButton> set to #this.

PrimeFaces DataTable - Row Selection inquiry

How does this code in the PrimeFaces DataTable row selection work?
<p:commandButton update=":form:display" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete">
<f:setPropertyActionListener value="#{car}" target="#{tableBean.selectedCar}" />
</p:commandButton>
I am confused by the following: update=":form:display", and image="ui-icon ui-icon-close".
Is this inbuilt into Primefaces? or do I need to create an additional form, or have an external image mapped to it?
update=":form:display" refers to a specific element on the page. The first ':' goes to the root of the page, so there needs to be a component with the id "form" (probably a form) and inside that a component with the id "display". This means after the button actions has completed :form:display will be updated. Note that it's generally not a great idea to use absolute paths as they can be hard to keep up to date when you change the page structure. If the button is on the same level as the "display" component you could just do update="display", or you can do things like update="#form" to update the entire current form.
image="ui-icon ui-icon-close" refers to style classes in your css. These two comes predefined with primeface, but if you want to use custom graphics you can also define your own style classes for them.