I have to stop and start a p:poll in JSF using some conditions... I am able to do that by putting the poll in a panelgrid and making the panelGrid rendered... I thought its working since the pollOperationStatus is not called after I made the panelGrid rendered false... When I show it , it restarts as well..
But there is a network call still firing ; which messes up many things ;How to deal it?
<h:form>
My main form
</h:form>
<h:form id="mypollform">
<p:outputLabel id="currentTime" value="#{myBean.counter}" />
<h:outputText value="#{myBean.startPoll}" id="counter11" />
<p:panelGrid rendered="#{myBean.startPoll}">
<p:poll interval="8" widgetVar="poller" autoStart="true"
listener="#{myBean.pollOperationStatus}"
update=":#{p:component('newServerID')},:#{p:component('mypollform')}" />
</p:panelGrid>
</h:form>
Primefaces 7 Documentation says:
Poll can be started and stopped using client side api; Or bind a
boolean variable to the stop attribute and set it to false at any
arbitrary time.
In your case this would be in javaScript:
PF('poller').stop(); or PF('poller').start();
Or bind a boolean bean property the the stop attribute of the p:poll:
<p:poll stop="#{myBean.stopPoller}" interval="8" widgetVar="poller" autoStart="true"
listener="#{myBean.pollOperationStatus}"
update=":#{p:component('newServerID')} :#{p:component('mypollform')}" />
Also beware that component IDs in update attribute are separated by space, not comma.
Related
I'm using PrimeFaces poll component to refresh some content.
<h:form id="formBsvtt">
<p:messages autoUpdate="true" showDetail="false" />
<p:outputPanel id="panelOut" layout="block">
...
... content to refresh
...
</p:outputPanel>
<p:panelGrid id="panelIn" layout="block">
...
... various input components with validation
...
</p:panelGrid>
<p:poll widgetVar="poll1" autoStart="true" global="false" interval="15"
partialSubmit="true" process="#this" update="panelOut"
listener="#{myBean.myListener}">
</p:poll>
</h:form>
As you can see I'm using messages with autoUpdate=true. My Problem is: In case of validation errors FacesMessages will be shown, but disappear not later than 15 seconds.
Is it possible to prevent poll from clearing FacesMessages without setting messages autoUpdate=false?
My web application is much bigger as code snippet specified above and my intention is not updating messages manually in each possible case!
PrimeFaces 2.x/3.x
This is not natively possible, so a trick is needed. In the rendered attribute of <p:messages>, check if <p:poll> was been triggered and if so, then return false. This way JSF thinks there's no auto-updatable messages component in the component tree during rendering and will therefore ignore it.
If the <p:poll> is triggered, then its client ID appears as javax.faces.source request parameter. So, this should do:
<p:messages ... rendered="#{param['javax.faces.source'] ne poll.clientId}" />
...
<p:poll binding="#{poll}" ... />
(note: no additional bean properties needed)
PrimeFaces 4.x+
All PrimeFaces command components got a new ignoreAutoUpdate attribute which you could set to false to ignore all autoUpdate="true" components in the ajax update.
<p:poll ... ignoreAutoUpdate="true" />
For folks using Primefaces 4.0 and above, the Primefaces team have added an attribute to their ajax aware components to skip triggering components with autoUpdate set to true. So your poll would be
<p:poll ignoreAutoUpdate="true" .../>
See also their blog post about it: http://blog.primefaces.org/?p=2836
i have another strange JSF problem here... I don´t really know why, but what ever i try to do, i have one out of two problems. Either the action method inside my popupPanel is not (means never) called or it is called, but the value from my selectBox is (always) null. Can´t figure out, what the problem is, but it seems to me, like it´s a XHTML property problem.
Already tried to put the popupPanel outside my h:form (helped me at some other locations...), i also tried to put it outside and put another form into my popup. Beyond that i was trying to change the attachment to parent/form and i changed the execute of the commandButton inside my popup to form/form-id/popuppanel-id and i guess there were some more things i did... but nothing helped.
The Bean is session scoped and i am using Richface 4.0 Final if it does matter at all.
What ever, the XHTML looks like this:
<rich:popupPanel
header="#{label['edit.title']} #{mandateAction.ccService.mandateList[mandateAction.currentIndex].id}"
id="addExternalSystem"
onmaskclick="#{rich:component('addExternalSystem')}.hide()"
domElementAttachment="form" autosized="true" layout="block">
<h:panelGrid columns="2">
<h:outputText value="#{label['login.username']}" />
<h:inputText
value="#{mandateAction.newExternalSystem.username}" />
<h:outputText value="#{label['login.password']}" />
<h:inputSecret
value="#{mandateAction.newExternalSystem.password}" />
<h:outputText value="#{label['mandate.externalSystem']}" />
<h:selectOneMenu
value="#{mandateAction.newExternalSystem.externalSystem}">
<f:selectItems
value="#{creditcardConfigurationService.externalSystems}"
itemLabel="#{system.name}" itemValue="#{system}"
var="system" />
<f:converter binding="#{externalSystemConverter}" />
</h:selectOneMenu>
....
<a4j:commandButton value="#{label['insert.save']}"
action="#{mandateAction.insertNewSystem}"
render="mandate_table" execute="#form"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('addExternalSystem')}.hide();}" />
If your page have any of the required fields kept as empty the submit from the popup panel will not work. In that case include the popup panel inside a form and domElementAttachment="form" , and perform the submit.
I need to set a boolean field whenever p:fieldset is toggled. I tried out following code but the field is never set by f:setPropertyActionListener although p:ajax listener is invoked on toggle. I tried out following code.
<p:fieldset legend="(Optional) Link.." toggleable="true">
<p:ajax event="toggle" listener="..">
<f:setPropertyActionListener target="#{viewScope.rendrUsrProjctsList}" value="#{true}"/>
</p:ajax>
</p:fieldset>
However when I tried modifying the code as below then field is successfully set:
<p:fieldset legend="(Optional) Link.." toggleable="true">
<p:ajax event="toggle" listener="#{view.viewMap.put('rendrUsrProjctsList', true)}" />
<p:ajax event="toggle" listener=".."/>
</p:ajax>
</p:fieldset>
I want to ask:
Why 1st way doesn't work ?
Is it bad attaching multiple p:ajax to
single parent as done in 2nd way ?
The <f:setPropertyActionListener> works as being an ActionListener implementation only on components implementing ActionSource interface, such as UICommand, i.e. <h:commandXxx>, <p:commandXxx>, etc. The <p:ajax> does not implement this interface and therefore the <f:setPropertyActionListener> is basically completely ignored.
As to your workaround, you could do so although I'd rather just use a concrete view scoped bean or wrap it in a composite with a backing component.
I have the following code
<a4j:status id="commonstatus" onstart="#{rich:component('loading')}.show();" onstop="#{rich:component('loading')}.hide();" />
<rich:dataTable id="dTable" reRender="ds">
<rich:column id="name" filterMethod="#{myBean.filterName}">
...
<h:inputText> <a4j:support event="onkeyup" reRender="dTable, ds" ignoreDupResponses="true" requestDelay="700" oncomplete="setCaretToEnd(event);" /> </h:inputText>
...
<rich:datascroller id="ds" reRender="dTable">
...
<a4j:support event="onchange" reRender="dtable, ds" status="commonstatus" />
...
</rich:dataTable>
<rich:modalPanel id="loading" moveable="false" autosized="true">
<h:panelGrid columns="2">
<h:graphicImage value="images/progress.gif"/>
<h:outputText value="Loading..."/>
</h:panelGrid>
</rich:modalPanel>
Problem: Even if I have not specified status="commonstatus" in <h:inputText> I still get the loading image for onkeyup event.
What am I missing here?
Any help would be great.
The <a4j:status> by default applies for all the components in the page that fire an ajax request. However, you can restrict the components that will be caught using the for attribute as stated in the tag component documentation:
for: ID of the AjaxContainer component whose status is indicated (in the format of a javax.faces.UIComopnent.findComponent() call).
You can wrap h:inputText by an a4j:region
or
Set status attribute of the a4j:support to a not existing status id (e.g. status="none")
It's probably a little deprecated, but might be useful if anyone still works with Richfaces 3.3... I defined 2 status components in the common facelet template. One is the main status that is used across application whenever an ajax event fires and it applies to the whole page, and one is "none" status that does nothing (and it must be wrapped in region):
<a4j:status id="main" onstart="(something)" onstop="(something else)" />
<a4j:region>
<a4j:status id="none" onstart="" onstop="" />
</a4j:region>
Whenever I don't want main status to appear, I specify "none" status as Andrey suggested, but the status component actually exists so the warning about non-existing component is avoided.
Don't forget to wrap it in a4j:region, or it won't work correctly - if you have 2 status components in the same region, I think that always the second one will be used, no matter what you put in status tag of your component which fires the request...
I have a problem with submitting composite components.
Most of my composite components contain both the input components and the "submit" button.
When I tried to put the button still in the same h:form but not in the same composite component, the submitted value seemed to be "lost" somewhere. And, for instance, my validators got called on original values.
Example :
<composite:interface>
<composite:attribute name="titreContext" required="true"/>
</composite:interface>
<composite:implementation>
<p:outputPanel id="selectionTitreDetailsPanel" styleClass="selectionTitreDetails">
<p:outputPanel id="selectionTitreDetailsPanelInner" rendered="#{not empty cc.attrs.titreContext.selected}">
<p:panelGrid columns="2" id="panelId">
<h:outputText id="idLabel" value="Id :"/>
<h:outputText id="id" value="#{cc.attrs.titreContext.selected.titeluid}"/>
<p:tooltip for="id" value="Identifiant unique"/>
</p:panelGrid>
<p:panelGrid columns="2" id="titelePanel">
<p:outputLabel for="selectTitele" value="Titre :"/>
<p:selectOneMenu id="selectTitele" value="#{cc.attrs.titreContext.selected.titele}" effect="fold" styleClass="fullWidth">
<f:selectItems value="#{constants.getTitelesForTypman(cc.attrs.titreContext.selected.titele.typman)}" var="titele" itemLabel="#{titele.titelelil}" itemValue="#{titele}" styleClass="fullWidth"/>
<p:column styleClass="fullWidth">#{titele.titelelil}</p:column>
</p:selectOneMenu>
</p:panelGrid>
[...]
<p:commandButton id="confirmerModifications" icon="small_edit" type="submit" value="Confirmer les modifications"
action="#{elutersEditionContext.confirmeModifsSelection}" process="mandatsTerritorial"
update="mandatsTerritorial #{cc.attrs.notifUpdates}"/>
</composite:implementation>
works.
But putting the p:commandButton out of the composite :
<h:form>
<mylib:mycomponent /*parameters *//>
<p:commandButton /*parameters*/ />
</h:form>
does not work. When I debug my validators, I can see that the modified values where not even submitted. Neither getLocalValue, getSubmittedValue nor getValue is changed.
Is there a syntax in composite component declaration to use to correct this situation ?
By the way : when I was writing my components as composite components rather than custom components, retrieving #{asen} in the backing bean just worked.
Thanks in advance.
I am using :
PrimeFaces 3.4.1
CODI 1.0.5
OpenWebBeans 1.1.6
MyFaces 2.1.9
Tomcat 7.0.32
(update) This very strange problem was caused by h:form nesting.
Very strange because h:form nesting did not perturbate the processing of the first level of composite components, but caused this strange "input lost" in nested composite.
Nesting looked like this :
<h:form>
...
<p:tabView ...>
<p:tab>
<h:form>
<my:composite ....>
</h:form>
</p:tabView>
</h:form>
You're using a relative client ID in the process attribute of the <p:commandButton>:
<p:commandButton ... process="mandatsTerritorial" />
A relative client ID is relative to the parent NamingContainer component. It will be searched as direct child of the NamingContainer component. If the child is by itself a NamingContainer, then its children would not be searched.
Composite components are by itself in fact also NamingContainer components. If the button is placed in the composite, then this will be searched as direct child of the <cc:implementation>. In your particular case, only the component with id="mandatsTerritorial" will be processed on form submit, including all of its children (note that this component is nowhere visible in the code posted so far, but I'd imagine that you omitted it for brevity).
If the button is placed in <h:form>, then this will be searched as direct child of the <h:form>. However as this is apparently been placed inside the composite (which is, as said, another NamingContainer component), it wouldn't be found and hence basically nothing would be processed. You'd need to fix the process to point to the right client ID. E.g.
<h:form>
<mylib:mycomponent id="mycomponent" />
<p:commandButton ... process="#this mycomponent:mandatsTerritorial" />
</h:form>
This way it will process itself (mandatory to invoke the action!) and the component with id="mandatsTerritorial" inside the <cc:implementation> of the composite with id="mycomponent".
As a completely different alternative, which would work just fine in this particular construct, is to remove the process attribute altogether. It defaults to #form already which will thus process the entire form.
Update as per your question update: nesting forms is invalid in HTML. Using the JSF <h:form> representation doesn't change that; you'd still end up with nested forms in HTML. The browser behaviour is unspecified as to which data would be submitted to the server. Make sure that you don't nest <h:form> in JSF as well.