Does dblclick event actually trigger p:ajax for SelectOneMenu?
According to the manual it should but when I try the following code below it does not. No response, no error message. Neither can I see a dblclick event listener on inspection.
Can someone please advise if possible how do I get it to work?
Using Primefaces 11.0.0
Many thanks!
D
<p:selectOneMenu value="#{menuBean.selectedPlayer}" converter="player" var="p">
<p:ajax event="dblclick" listener="#{menuBean.handleDblclick}" update="msgs" />
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{menuBean.players}" var="player" itemLabel="#{player.name}" itemValue="#{player}"/>
</p:selectOneMenu>
And in MenuBean:
public void handleDblclick(AjaxBehaviorEvent x) {
// processing ....
}
Related
I have a big problem with selectOnMenu in JSF2, i tried to use this component with but not working , i tested also the primefaces example http://www.primefaces.org/showcase/ui/ajax/dropdown.xhtml but without any new result .
i think that i miss some config or filter about ajax in my project or my page.
Here is dropdown code:
<p:selectOneMenu style="width:300px;" value="#{parameterBean.name}">
<f:selectItem itemLabel="Select parameter Type" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{parameterTypeBean.listParameterTypes}" var="ptype" itemValue="#{ptype.id}" itemLabel="#{ptype.name}" />
<p:ajax listener="#{parameterBean.serviceChange}" event="change" update="pTable" process="#form"/>
</p:selectOneMenu>
This is my simple actionBean :
public void serviceChange() {
System.out.println("change");
}
Can you help me to resolve this problem ?
remove process="#form" so it would be
<p:ajax listener="#{parameterBean.serviceChange}" event="change" update="pTable"/>
Given the following code:
<p:column headerText="#{text.article}">
<h:panelGroup>
<p:autoComplete id="relationArticle"
value="#{relation.article}"
completeMethod="#{articleRelationsModel.findArticles}"
queryDelay="#{text.query_delay}"
minQueryLength="#{text.artikkel_min_query_length}"
var="article"
itemLabel="#{article.articleNo} #{article.text1}"
itemValue="#{article}"
converter="#{articleConverter}"
scrollHeight="150"
forceSelection="true"
styleClass="ui-autocomplete-big">
<p:ajax event="itemSelect" update="relationUnit" process="#this"/>
</p:autoComplete>
<p:message for="relationArticle"/>
</h:panelGroup>
</p:column>
<p:column headerText="#{text.unit}" style="width: 80px;">
<h:selectOneMenu id="relationUnit" value="#{relation.unit}" converter="#{articleUnitConverter}">
<f:selectItem itemLabel="<< #{text.search}" noSelectionOption="true" itemDisabled="#{relation.article != null}"/>
<f:selectItems value="#{articleRelationsModel.getUnits(relation)}" var="unit" itemLabel="#{unit.code}" itemValue="#{unit}"/>
<p:ajax event="change" process="#this" update="#this"/>
</h:selectOneMenu>
<p:message for="relationUnit"/>
</p:column>
How can I refresh the "relationUnit" component after the user has selected a value in the "relationArticle" component?
What happens now, is that after the autcompete itemSelect event has fired, the "relationUnit" component gets updated with new content using #{articleRelationsModel.getUnits(relation)}. During this update, the relation object is updated with one of the options from the resulting list. This, however, is not reflected in the "relationUnit" component after the update. But if I manually do another update after this, it gets selected.
How can I achieve the wanted result here?
You can use p:remoteCommand, which is usually used to call the ManagedBean Methods from Javascript.
While it serves the above purpose you can use it to update other components also.
You can call the p:remoteCommand from p:ajax's oncomplete attribute.
<p:autoComplete id="relationArticle" ...>
<p:ajax event="itemSelect" update="relationUnit" onComplete="updateRelationUnit()" process="#this"/>
</p:autoComplete>
<p:remoteCommand name="updateRelationUnit" update="relationUnit" process="#this" />
Now p:ajax will update relationUnit once and then calls the p:remoteCommand which in-turn relationUnit again.
I don't know why you want this strange behavior, but the above strategy and code servers your purpose just fine.
I am trying to implement cascading drop down in JSF. listing down the things that i did below please help me
XHTML code:
<h:selectOneMenu value="#{bean.country_id}" id="countries">
<f:selectItem itemLabel="-- Select a Country -- " itemValue="0"/>
<f:selectItems value="#{bean.countries}" var="country" id="countryList"/>
<f:ajax event="change" listener="#{bean.getCityList}" execute="countries" render="cityList" />
</h:selectOneMenu>
<h:selectOneMenu value="#{bean.city_id}" id="cities">
<f:selectItem itemLabel="-- Select a City -- " itemValue="0"/>
<f:selectItems value="#{bean.cities}" var="city" id="cityList" />
</h:selectOneMenu>
The call is going to getCityList once we change the country and we are getting the countries value int that method too but the list returned in the getcitylist is not getting applied to the cityList and the xhtml is throwing error.
Please help me in this regard
Thanks
KK
Use render="cities" in f:ajax. You have to rerender the whole selectOneMenu to see the updated list in the view.
I trying to use the onChange event of selectOneMenu, but it doesn't work and the component is not displayed when I add onChange attribue.
Can someone tell me how can I handle the onChange event of <p:selectOneMenu>?
Here is my view:
<p:selectOneMenu id="service" filterMatchMode="startsWith">
<f:selectItem itemLabel="Selectionner un Service : " />
<f:selectItems value="#{newOpProgramme.listeSevice}" var="service" itemValue="#{service.serviceId}" itemLabel="#{service.serviceNom}"/>
<f:ajax event="change" execute="#this" listener="#{newOpProgramme.serviceChange()}" render="nomCdp"/>
</p:selectOneMenu>
And here is the <f:ajax listener> method in a request scoped bean:
public void serviceChange() {
System.out.println("change");
}
When I change the menu, however, nothing is been printed.
How is this caused and how can I solve it?
First of all, onChange is the wrong event name. It's change. Secondly, if you intend to call the HTML attribute name, onChange is also the wrong attribute name. It's onchange.
Coming back to your concrete problem; the standard JSF <f:ajax> is not compatible with PrimeFaces components. You should be using PrimeFaces own <p:ajax> instead.
<p:selectOneMenu ...>
...
<p:ajax listener="#{newOpProgramme.serviceChange()}" update="nomCdp" />
</p:selectOneMenu>
Note that I omitted the event and the process attributes. They both have already the right default value of valueChange and #this respectively.
See also:
What values can I pass to the event attribute of the f:ajax tag?
Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
When I want to update something after change in selectOneMenu, I use <f:ajax> tag inside selectOneMenu like this:
<h:selectOneMenu value="#{bean.selected}" >
... select items here
<f:ajax event="change" execute="#this" render="search" />
</h:selectOneMenu>
Where search is the Id of the object you want to update.
Other solution is that you should try onchange not onChange.
<p:selectOneMenu value="#{someBean.myAttr.id}" valueChangeListener="#someBean.mySelectioMethodListener}">
<f:selectItems value="#{someBean.listAttrs}" var="item"
itemLabel="#{item.name}" itemValue="#{item.id}" />
<p:ajax process="#this" update="someElementId" />
</p:selectOneMenu>
You must put an Id for <f:selectItems /> and set your selection on backing bean side by posted ajax itemValue (id).
Server side method bean without a converter:
public void mySelectionMethodListener(ValueChangeEvent event) {
ApplicationContext context = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
SomeBeanDao someBeanDao = (SomeBeanDao) context.getBean(SomeBeanDao.class);
myAttr = someBeanDao.byId((Long) event.getNewValue());
System.out.println("value changed...");
}
I am currently facing issue using with primefaces Calendar control
My requirement is to invoke a java method on change of the Calendar control value either from the input box or using the button and also pass a set of parameters(Java object and the field id) to the java method.
below is the code that I have implemented and it is not working
<p:calendar showOn="button" id="effectiveDt" navigator="true" pattern="MM/dd/yyyy"
styleClass="overrideable" value="#{coverage.startDate}">
<f:ajax event="change" render="hiddenStartDt" onevent="myEvent" listener="#{certInquiry.ovrrrideListener}"/>
<f:attribute name="covg" value="#{coverage}" />
<f:attribute name="field" value="StartDate" />
</p:calendar>
here myEvent is a java script method which will be called after the ajax is completed where i am checking the ajax status is success and performing some action.
method signature of the java method is.
*public void overrideListener(AjaxBehaviorEvent e) *
I tried with all kinds of methos signatures like
public overrideListener(ValueChangeEvent e)
public overrideListener(ActionEvent e)
public ovrrrideListener(DateSelectEvent event)
nothing was working for me
I have tried using also even this was not working
I also tried using valueChangeListener if the method gets called but it was not invoking the method
this is working for and fields using the
<h:selectBooleanCheckbox class="overrideable"
value="#{coverage.clIndicator}">
<f:ajax event="change" render="hidgenLiabClaimsMdInd" onevent="myEvent" listener="#{certInquiry.overrideListener}"/>
<f:attribute name="covg" value="#{coverage}" />
<f:attribute name="field" value="ClIndicator" />
</h:selectBooleanCheckbox>
<h:inputText id="genLiabEachOccAmt" value="#{coverage.eachOccAmt}"
class="amt_field overrideable">
<f:ajax event="change" render="hidgenLiabEachOccAmt" onevent="myEvent" listener="#{certInquiry.overrideListener}"/>
<f:attribute name="covg" value="#{coverage}" />
<f:attribute name="field" value="EachOccAmt" />
</h:inputText>
Please help me in solving this issue for the Calendar component.
Make the ajax event="dateSelect" and you should get the date value in your BB when you use ovrrrideListener(DateSelectEvent event).