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" />
Related
This is my current structure for my p:selectOneMenu:
<h:form id="groupSelectionForm">
<p:outputLabel value="Momentane Gruppe:" for="groupSelection" />
<p:selectOneMenu id="groupSelection" value="#{foodPlanManagementBean.selectedGroup}" style="width:150px">
<f:selectItem itemLabel="-" itemValue="#{null}"/>
<f:selectItems value="#{foodPlanManagementBean.getGroups()}" var="group" itemLabel="#{group.name}" itemValue="#{group}"/>
<p:ajax event="change"/>
</p:selectOneMenu>
</h:form>
This results in a checkbox containing a default value given by the single selectItem as well as a few generated options from the selectItems.
However, the setter for the given field "selectedGroup" is only triggering for the selectItem.
The selectItems do not seem to do anything when they are being clicked.
Any ideas?
try to define a listener in ajax component, ex:
<p:ajax id="seasonAjax" event="change" process="#this" listener="#{yourBean.yourMethod}" update="elementThatYouWantToUpdate" />
process = this to process selected element.
In selectItems don't use get method use directly list elements(put get/set in your bean) ex:
<f:selectItems value="#{yourBean.yourList}" var="" itemLabel="" itemValue="" />
If this doesn't work test if you need to use a converter, if selectedGroup is a complex object or pass directly identification of selectGroup( selectedGroup.id)
I hope it helps.
I have the following component on the xhtml:
<p:outputLabel for="concept" value="Concept" />
<p:selectOneMenu id="concept" value="#{dIGRCController.digrc.qconce}"
requiredMessage="Debe de seleccionar un concepto."
required="#{request.getParameter('validate')}">
<f:selectItem itemLabel="Concept" itemValue="" />
<f:selectItems value="#{cCRX1Controller.ccrx1.concepts.entrySet()}"
var="concepts" itemValue="#{concepts.key}"
itemLabel="#{concepts.value}" />
<p:ajax event="change" execute="#this" listener="#{dIGRCController.testing()}" />
</p:selectOneMenu>
The values are coming correctly from the cCRX1Controller class. However, when I select an option, I am trying to display the value. the #{dIGRCController.testing()} looks like this:
public void testing()
{
System.out.println("sdfsd");
}
What am I doing wrong? I checked this question but could't figure out what the problem is.
Try with this
<p:ajax process="#this" listener="#{dIGRCController.testing()}" />
I think the default of ajax event of Primefaces select one menu is valueChange event. So, try with using also
<p:ajax event="valueChange" process="#this" listener="#{dIGRCController.testing()}" />
I'm having a trouble with getting rid of required message.
I have a form in which I have a few fields and a button.
When I press a button there is validation that checks if required fields where filled with values if not then required message is displayed for invalid value/component.
Now I want to select a value from selectOneMenu or type something into inputText and when I do that I want the required message to dissapear without need to press the button again.
How would you do that?
I've tried to remove message with sth like this, but it doesn't seems to work:
Iterator<FacesMessage> msgIterator = FacesContext.getCurrentInstance().getMessages();
while (msgIterator.hasNext())
{
FacesMessage facesMessage = msgIterator.next();
msgIterator.remove();
}
Could you help me with that?
Here is example code:
<h:form id="mainForm">
<h:selectOneMenu required="true" id="dictionaryValueId" value="#{SomeBean.dictionarySelectedValue}">
<f:selectItem itemValue="#{null}" itemLabel="#{i18n['view.choose']}" />
<f:selectItems value="#{SomeBeanBean.dictionaryValuesMap}" var="element"
itemLabel="#{element.descripption}" itemValue="#{element.key}" />
<f:ajax event="change" execute="#this msgId" render="msgId dictionaryValueId"/>
</h:selectOneMenu>
<h:message id="msgId" style="display:none;" for="dictionaryValueId" />
...
<h:commandButton value="#{i18n['button.forward.name']}"
actionListener="#{SomeBean.forward}" >
<p:ajax process="#form" update="mainForm"/>
</h:commandButton>
I am not sure, but is not there a problem with
style="display:none;"
for
<h:message id="msgId"/>
You can wrap your message with <h:panelGroup/> and render by this panelGroup Id, this Id will be always present on your form.
<h:form id="mainForm">
<h:selectOneMenu required="true" id="dictionaryValueId" value="#{SomeBean.dictionarySelectedValue}">
<f:selectItem itemValue="#{null}" itemLabel="#{i18n['view.choose']}" />
<f:selectItems value="#{SomeBeanBean.dictionaryValuesMap}" var="element" itemLabel="#{element.descripption}" itemValue="#{element.key}" />
<f:ajax event="change" execute="#this" render="messageBundle1 dictionaryValueId"/>
</h:selectOneMenu>
<h:panelGroup id="messageBundle1">
<h:message id="msgId" style="display:none;" for="dictionaryValueId" />
</h:panelGroup>
<h:commandButton value="#{i18n['button.forward.name']}"
actionListener="#{SomeBean.forward}" >
<p:ajax process="#form" update="mainForm"/>
</h:commandButton>
</h:form>
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 have an <p:selectOneMenu> which has an <f:selectItems> and in this <f:selectItems> I have set an itemLabel and an itemValue. The Item Value is an Enum Object which contains only a String and the Label is these String. The value of the <p:selectOneMenu> is an Collection of these Enum Objects. The selectOneMenu has an valueChangeListener and when its called it becomes the label as "new Value" and not the value. Has anyone an idea how I can fix this?
<h:form>
<p:selectOneMenu id="changeSpracheMenu"
value="#{sessionManager.currentUser.sprache}"
label="#{messageManager.getMessage('USER')}"
valueChangeListener="#{sessionManager.updateSpracheForCurrenUser}"
converter="sprachConverter">
<f:selectItem itemLabel="#{messageManager.getMessage('LANGUAGE')}"
noSelectionOption="true" />
<f:selectItems value="#{sprachManager.allSprachen}" var="sprache"
itemLabel="#{messageManager.getMessage('LANGUAGE_'.concat(sprache.name))}"
itemValue="#{sprache}" />
<p:ajax event="change" update="#form" />
</p:selectOneMenu>
</h:form>
Instead of using the Event of valueChangeListener, you can send the value of your selectItem to your bean.
For that, you have to modify
<p:ajax event="change" update="#form" />
To:
<p:ajax event="change" listener="#{yourBean.yourMethod(sprache)}" update="#form" />
Now in your bean:
private yourObject sprache;
//getter/setter
public void yourMethod(yourObject typeSprache){
whatever xyz = typeSprache.getWhatEverYouWant();
}