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()}" />
Related
I have a required select and my problem is that when the user selects an empty option (null) the validation jumps in and the listener call of the select is being skipped. Some components on my view are depending on this value so in case of null being selected the bean won't get actualized and the components don't change.
Example:
<h:form id="createForm">
<p:selectOneMenu id="produktCreateTypSelect"
converter="omnifaces.SelectItemsIndexConverter"
value="#{productController.selectedProduct.typ}" required="true">
<f:selectItem itemValue="#{null}" itemLabel="-- Select --" />
<f:selectItems var="productType" value="#{productController.findAllProducts()}"
itemLabel="#{productType.name}" itemValue="#{productType}" />
<p:ajax process="#this " event="valueChange" update="createForm"
listener="#{productController.printHelloWorld}" />
</p:selectOneMenu>
<h:panelGroup id="dummy1" rendered="#{productController.selectedProduct.type != null}" />
</h:form>
The question is what the best way is to update that panelGroup
'dummy1'
Thanks for any help.
I'm using primefaces and have a datatable that has 2 columns. One column is outputtext another one is selectOneMenu. I made editable selectOneMenu. Actually it's work but not properly. Default value of selectItem is shown null but ı want it to show first value as default value. How can I make it?
<p:dataTable id="cellEditingTable" var="message"
value="#{messageTableController.menuList}" paginator="true"
paginatorPosition="bottom" editable="true" editMode="cell">
<p:column>
<p:selectOneMenu id="menu" value="#{messageTableController.selected}"
style="width:96%" effect="fold" editable="true">
<f:selectItem itemLabel="#{message.assign}"
itemValue="#{message.assign}" />
<f:selectItem itemLabel="#{message.combo}"
itemValue="#{message.combo}" />
</p:selectOneMenu>
</p:column>
</p:dataTable>
I change selectOneMenu's value to first ItemValue. So when run the program, first ItemValue picked selected item as a default.
<p:selectOneMenu id="menu" value="#{message.assign}"
style="width:97%" editable="true">
<f:selectItem itemLabel="#{message.assign}"
itemValue="#{message.assign}" />
<f:selectItem itemLabel="#{message.combo}"
itemValue="#{message.combo}" />
</p:selectOneMenu>
Add noSelectionOption to the first selectItem
<f:selectItem itemLabel="#{message.assign}"
itemValue="#{message.assign}" noSelectionOption="true" />
May be late to answer this.
If you use editable="true" then while rendering in the browse, it will render as textbox.
Remove the editable="true" then the default value will be selected.
If you want to provide the filter option in the selectOneMenu, use filter="true"
<p:selectOneMenu id="menu" value="#{message.assign}"
style="width:97%" filter="true">
<f:selectItem itemLabel="#{message.assign}"
itemValue="#{message.assign}" />
<f:selectItem itemLabel="#{message.combo}"
itemValue="#{message.combo}" />
</p:selectOneMenu>
Based on the editable property, it will render in browser as below.
I've a form, and i want it to show some inputs only if the user mark yes on a selectOneRadio.
Here is the code:
<p:selectOneRadio id="someSelectRadio" value="#{someBean.someClass.someSelectRadio}" >
<f:selectItem itemLabel="Sim" itemValue="Sim" />
<f:selectItem itemLabel="Não" itemValue="Não" />
//Here i use event=change to reconize if the user mark a option on selectOneRadio
<p:ajax event="change" process="someSelectRadio" update="panelGeral" />
</p:selectOneRadio>
//Here is the panel that i want to appear if the user mark selectOneRadio
<p:outputPanel id="panelGeral">
<p:panel id="panel" autoUpdate="true" rendered="#{someBean.someClass.someMethod}" />
</p:outputPanel>
I already have tryied to change event do click, on click, both doesn't work for me.
This may be due to the problem with event .
Change to
<p:ajax event="valueChange" process="someSelectRadio" update="panelGeral" />
More info
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 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" />