My selectOneMenu isn't fireing an onchange event. Here is the code:
<p:selectOneMenu id="select_preset"
value="#{JobMgmtBean.presetGroupName}"
valueChangeListener="#{PFJobMgmtBean.PresetGroupChangeEvent}"
onchange="submit();">
<f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
</p:selectOneMenu>
The selectOneMenu is nicely populated, and I can select different values. But I would expect that after I change a selection, page would be refreshed, i.e. backing bean (RequestScoped) would be recreated (onchange="submit();")? But nothing happens when selection in the selectOneMenu is changed.
Also, value change listener PresetGroupChangeEvent() is not called.
Did I go wrong somewhere?
I'm using Tomcat 7.0.25 + MyFaces 2.1.6 + PrimeFaces 3.2.
try to remove
onchange="submit();"
and to add
<p:ajax update="#this"/>
from your p:selectOneMenu when you using primefaces
<p:selectOneMenu id="select_preset"
value="#{JobMgmtBean.presetGroupName}"
valueChangeListener="#{PFJobMgmtBean.PresetGroupChangeEvent}">
<f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
<p:ajax update="#this"/>
</p:selectOneMenu>
check your listener signature (starts from big "P" ?)
import javax.faces.event.ValueChangeEvent;
public void PresetGroupChangeEvent(ValueChangeEvent event) { }
why you are not adding update attribute using p:ajax? I think rerendering components more better solution than refreshing, also you can just rerender needed components. But if you still want to refresh page you can also use javascript:
<p:selectOneMenu id="select_preset" value="#{JobMgmtBean.presetGroupName}" onchange="window.location.reload();">
<f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
</p:selectOneMenu>
and just for updating necessary components:
<p:selectOneMenu id="select_preset" value="#{JobMgmtBean.presetGroupName}">
<f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
<p:ajax event="change" update="#form" />
</p:selectOneMenu>
this works for me
<p:selectOneMenu id="select_preset"
value="#{JobMgmtBean.presetGroupName}"
valueChangeListener="#{PFJobMgmtBean.PresetGroupChangeEvent}">
<f:selectItems value="#{JobMgmtBean.presetGroupList}"/>
<p:ajax process="select_preset" partialSubmit="true" event="valueChange" update="yourComponentName"/>
</p:selectOneMenu>
try to use ajax from primefaces and refresh only what you want to refresh
Related
I want to reset a selectOneMenu with another selectOneMenu to the default value and I can't use ajax.
First menu:
<h:selectOneMenu value="#{bean.rel}" id="relSelection"
valueChangeListener="#{bean.onRelChange}" onchange="submit();"
immediate="true">
<f:selectItems value="#{bean.rel}" />
</h:selectOneMenu>
Menu I want to reset:
<h:selectOneMenu value="#{bean.domSelected}" id="domSelection"
valueChangeListener="#{bean.onDomChange}" onchange="submit()"
hideNoSelectionOption="true" immediate="true" >
<f:selectItem itemValue="#{null}" itemLabel="Select..."
noSelectionOption="true" />
<f:selectItems value="#{bean.domNames}" var="item"
itemLabel="#{item}" itemValue="#{item}"/>
</h:selectOneMenu>
If the first menu is selected after the second already was selected by the user I want to reset the second menu.
I expected that the second menu would display the noSelectionOption after I set its value to null from the onReleaseChange listener, but it keeps the selected value.
Listener:
public void onRelChange(ValueChangeEvent event) {
domSelected = null; //type String
rel = (String) event.getNewValue();
//som other stuff
}
I already tried the remoteCommand approach described here
by adding this:
<p:remoteCommand name="resetInputs" process="#this relSelection"
actionListener="#{bean.clearMenu}" immediate="true">
<p:resetInput target="domSelection" />
</p:remoteCommand>
In the first menu I called the remoteCommand via onChange="submit(); resetInputs()"
Any other Ideas or Ideas why this is not working?
Thanks!
Primefaces 6.1
JSF 2.2
GlassFish 4.1.1
I have setted a JSF Varidable Like this:
<c:set var="selectedech" value="#{ManagedBean.selectedtypeFacturation}" scope="request"/>
After that i putted it on a SelectOneMenu:
<p:selectOneMenu panelStyle="width: 120px" effect="fade" id="typeFacture" value="#{selectedech}" >
<f:selectItem itemValue="Echeancier" itemLabel="Echeancier"/>
<f:selectItem itemValue="Mensuel" itemLabel="Mensuel"/>
<p:ajax event="change" update="#this"/>
</p:selectOneMenu>
I would like to change the value of JSF variable "selectedech" each time i change the selection.
Any idea in order to get it work well
Thx
I have a p:commandButton which calls a method from managed bean. I want to add one more functionality to it. So after calling that particular function , I want to set focus to a p:selectOneMenu
My code is :
<p:selectOneMenu id="particulars" filter="true"
filterMatchMode="startsWith"
value="#{receiptMB.selectedFeeSchemeDetail.planId}"
style="width:120px !important;">
<f:selectItem itemLabel="Select" itemValue="" />
<f:selectItems value="#{receiptMB.incomeSchemes}" var="acc"
itemLabel="#{acc.feeInstallment}" itemValue="#{acc.planId}" />
<p:ajax event="change"
listener="#{receiptMB.onIncomeSourceSelect()}"
update=":messageGrowl :receiptEntryForm:planId
:receiptEntryForm:newVouchDetails txtQty totalAmount
particulars :receiptEntryForm:planId :receiptEntryForm:receiptSource
advAmtRemaining advCheckBox amtPaid" />
</p:selectOneMenu>
<p:commandButton value="#{bundle.add}" icon="ui-icon-plus"
partialSubmit="true" process="jvPanel autoCompleteData"
id="addVoucher" actionListener="#{receiptMB.loadTableData}"
update=":messageGrowl cmdSave :receiptEntryForm:newVouchDetails
txtQty totalAmount
particulars :receiptEntryForm:planId :receiptEntryForm:receiptSource
advAmtRemaining advCheckBox amtPaid">
</p:commandButton>
Please suggest me some solutions.
You can use RequestContext in you action method as :
RequestContext context = RequestContext.getCurrentInstance();
context.scrollTo("receiptEntryForm:particulars");
you can checkout primefaces documentation and showcase for more info.
I am using primtefaces 3.5 and below code to poplulate p:selectOneMenu. On selecting an item, I want to know the value of selected itemValue i.e. userStar.userStarId.
Have tried using f:setPropertyActionListener or f:attribute or passing the value in listener method, but no luck.
Thanks for your time and help.
<p:selectOneMenu editable="true" style="width:300px" value="#{starBean.newStarName}">
<f:selectItems value="#{starBean.userStarList}" var="userStar" itemLabel="#{userStar.starName}" itemValue="#{userStar.userStarId}" />
<p:ajax event="change" listener="#{starBean.changeValueListener}" process="#this" partialSubmit="true">
</p:ajax>
</p:selectOneMenu>
Change this
<p:selectOneMenu editable="true" style="width:300px" value="#{starBean.newStarName}">
to
<p:selectOneMenu editable="true" style="width:300px" value="#{starBean.userStarId}">
p:selectOneMenu value is the selected value here.
If you want to avoid using Custom Converter, you can put all your pojo in Map and load that in to p:selectOneMenu and once you get the selected pojo using Map.get(K).
Initialization:
Map<String,UserStar> userStarMap = new LinkedHashMap<String,UserStar>();
UserStar user1 = new UserStar(...);
userStrMap.put(user1.userStarId, user1);
...
...
...
Facelt:
<p:selectOneMenu editable="true" style="width:300px" value="#{starBean.newStarName}">
<f:selectItems value="#{starBean.userStarMap.values()}"
var="userStar" itemLabel="#{userStar.starName}" itemValue="#{userStar.userStarId}" />
<p:ajax event="change" listener="#{starBean.changeValueListener}" process="#this" partialSubmit="true">
</p:ajax>
</p:selectOneMenu>
Listener:
public void changeValueListener(){
UserStar selectedUser = userStarMap.get(newStarName);
}
I have problem with jsf. My jsf code is:
<h:form>
<p:selectOneMenu style="text-align:left;"
value="#{contractBean.selectedCust}" converter="CustomerConverter">
<f:selectItems value="#{classificatorBean.customerList}"
var="customer" itemLabel="#{customer.name} #{customer.sname}" itemValue="#{customer}" />
<p:ajax event="change" update="custTel" />
</p:selectOneMenu>
<p:inputText id="custTel" value="#{contractBean.selectedCust.name} " />
</h:form>
and I have managed bean (Contractbean) with getter and setter functions of selectedCust Customer object. My problem is when menu changed object dont show customers tel number.
try to use ajax like this:
<p:ajax event="change" process="#this" update="custTel" />