JSF/primefaces selectOneMenu does not work with commandButton [duplicate] - jsf

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Validation Error: Value is not valid
(3 answers)
Closed 5 years ago.
I have this jsf page with primefaces 3.5. Controller and converter are #Component from spring version 3.0.5.RELEASE.
<h:form>
<h:panelGrid columns="2" id="grid">
<h:outputText value="Field names: "/>
<p:selectOneMenu value="#{controller.something}"
converter="#{SomethingConverter}">
<f:selectItems value="#{controller.listOfsomething}"/>
</p:selectOneMenu>
<h:outputLabel value="Value : *" for="inputField" />
<p:inputText id="inputField" required="true"
value="#{documentController.documentValue.value}"/>
<p:commandButton value="Add" action="#{controller.add}" />
</h:panelGrid>
</h:form>
Class controller have this method:
public String add() {
//do something
return null;
}
Which is called only if I remove selectOneMenu component. Values in selectOneMenu are converter successful.
I have no idea now..

Related

p:commandButton action attribute is not being called [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
How to display dialog only on complete of a successful form submit
(1 answer)
How to call JSF backing bean method only when onclick/oncomplete/on... event occurs and not on page load
(1 answer)
Closed 2 years ago.
I am trying to submit the contents of a form to a method in a managed bean, storeAppointment(), however the action attribute of the commandButton is never fired. If i use the onclick attribute, then the method in the managed bean is called, however, the onclick attribute also fires when the page is loaded which is not what I want to happen. My form is as follows :
<h:form>
<p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true">
<p:autoUpdate />
</p:growl>
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="start" value="Start Time" />
<p:datePicker id="start" value="#{createAppCtrl.startTime}" showTime="true" stepMinute="5"/>
<p:outputLabel for="finish" value="Finish Time" />
<p:datePicker id="finish" value="#{createAppCtrl.finishTime}" showTime="true" stepMinute="5"/>
<h:outputLabel for="multiple" value="Multiple:" />
<p:selectCheckboxMenu id="multiple" value="#{createAppCtrl.selectedUsers}" label="Users" multiple="true"
filter="true" filterMatchMode="startsWith" panelStyle="width:250px">
<p:ajax event="itemUnselect" listener="#{createAppCtrl.onItemUnselect}" />
<f:selectItems value="#{createAppCtrl.involvement}" />
</p:selectCheckboxMenu>
</h:panelGrid>
<p:commandButton value="Submit"
action="#{createAppCtrl.storeAppointment}"
update="displayItems"
oncomplete="PF('itemDialog').show()"/>
<p:dialog header="Selected Items" modal="true" showEffect="fade" hideEffect="fade" widgetVar="itemDialog" width="250">
<p:outputPanel id="displayItems">
<h:outputText value="Time: " />
<h:outputText value="#{createAppCtrl.startTime}" >
<f:convertDateTime pattern="MM/dd/yyyy HH:mm" />
</h:outputText>
<h:outputText value="Time: " />
<h:outputText value="#{createAppCtrl.finishTime}">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm" />
</h:outputText>
<p:dataList value="#{createAppCtrl.selectedUsers}" var="city" emptyMessage="No cities selected" style="margin-bottom: 10px;">
<f:facet name="header">
Multiple
</f:facet>
#{city}
</p:dataList>
</p:outputPanel>
</p:dialog>
</h:form>
When the commandButton is clicked the update and oncomplete attributes work as expected, but the dialog that is shown by oncomplete displays only null values.
And the method that is being called by action is #{createAppCtrl.storeAppointment}:
public String storeAppointment() {
try {
System.out.print(startTime + " " + finishTime + " " + involvement);
appointmentBean.createAppointment(startTime, finishTime, involvement);
return "";
} catch (Exception e) {
System.out.print("Ctrl: " + e);
return "";
}
}

Using temporary value without backing bean [duplicate]

This question already has answers here:
Pass input text value to bean method without binding input value to bean property
(2 answers)
Closed 6 years ago.
Inside a primefaces overlayPanel I am asking a user for a value, which will be reused directly afterwards. So I don't want to save it in a backing bean.
Here's the code:
<p:overlayPanel id="ovlpanel" for="copy" hideEffect="fade" style="width:300px">
<h:form>
<p:panel id="grid" header="#{msg.copy_item}">
<h:panelGrid columns="2" cellpadding="5"
styleClass="ui-panelgrid-blank">
<p:outputLabel value="#{msg.number_of_copies}: " for="number_of_copies" />
<p:column>
<p:inputText id="number_of_copies"
value="tempValNumberOfCopies" />
</p:column>
</h:panelGrid>
<p:commandButton
action="#{controller.copyItem(tempValNumberOfCopies)}"
value="#{msg.copy}" />
</p:panel>
</h:form>
</p:overlayPanel>
I want to save the value for tempValNumberOfCopies inside a temporary variable and use it in the action of the button.
Do you maybe have any ideas how to implement that?
You could use the implicit scopes, e.g.
<p:inputText id="number_of_copies"
value="requestScope.tempValNumberOfCopies" />
<p:commandButton action="#{controller.copyItem(requestScope.tempValNumberOfCopies)}"
value="#{msg.copy}" />
or
<p:inputText id="number_of_copies"
value="viewScope.tempValNumberOfCopies" />
<p:commandButton action="#{controller.copyItem(viewScope.tempValNumberOfCopies)}"
value="#{msg.copy}" />

jsf commandButton does not call method from bean [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 1 year ago.
I checked a dozen of answers on similar question to this one, but none helped me solve the issue.
Here is the body .xhtml file, where logout button does not work. This page is shown after login, if that is relevant.
<body>
<h:form id="newTaskForm">
<center>
<p:commandButton value="Logout" action="#{LogoutController.logout}"/>
</center>
<p:panel id="panel" header="New task" style="margin-bottom:20px">
<h:panelGrid id="grid" cellpadding="5" columns="3" style="margin-bottom:10px">
<f:facet name="header">
<p:messages id="msgs" />
</f:facet>
form stuff, this is ok
<p:commandButton action="#{createNewTaskController.saveTask}"
value="Spremi zadatak" update="newTaskForm" />
</h:panelGrid>
</p:panel>
</h:form>
and here is a bean:
#SessionScoped
#ManagedBean
public class LogoutController {
public String logout() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(true);
session.invalidate();
return "/createNewTask.xhtml?faces-redirect=true";
}
}
I've seen a list of possible reasons why it could not work, but I can't really tell what an actual reason is, so I'd be grateful for any help
I had the same problem and tried everything but when I gave the CommandButton an id it was resolved

JsfUtil addErrorMessage is not working while calling ajax in jsf [duplicate]

This question already has an answer here:
h:messages does not display messages when p:commandButton is pressed
(1 answer)
Closed 2 years ago.
JsfUtil addErrorMessage is not working while calling ajax function to bean method..
<h:outputLabel value="Effect Date" styleClass="boldFound,rsInput" />
<p:calendar value="#{salarypromotionBean.salarypromotiondto.effectDate}"
pattern="dd-MM-yyyy" yearRange="#{c-100}" navigator="true"
size="21">
<p:ajax event="dateSelect" listener="#{salarypromotionBean.salaryPromotion}" update="emp,empName,empDept,empDesig,empDate"/>
</p:calendar>
<h:outputText value="Employee No" />
<p:selectOneMenu value="#{salarypromotionBean.salarypromotiondto.employeeNo}" id="emp">
<f:selectItem itemLabel="select" itemValue="0" />
<f:selectItems value="#{salarypromotionBean.empid}" />
</p:selectOneMenu>
Java method:
public void salaryPromotion() throws ParseException{
JsfUtil.addErrorMessage("New salary should be greater than current salary");
}
<p:messages autoUpdate = "true"/>
This would resolve your issue for the error messages to be displayed:

Partial rendering via FacesContext [duplicate]

This question already has answers here:
Can I update a JSF component from a JSF backing bean method?
(5 answers)
Closed 7 years ago.
actually I got a inputText and some ajax Request to render a datatable when a keyup event appears.
mypage.xhmtl:
<h:form id="form">
<h:inputText id="number_in" value="#{bean.number}" redisplay="false" >
<f:ajax event="keyup" render=":form:dataTable" />
</h:inputText>
<h:dataTable id="dataTable" ...>
...
</h:dataTable>
<h:form>
I don't want to render the dataTable from the jsf page anymore. I want to render the dataTable in a MangedBean by FacesContext when a listener method is invoked.
mypage.xhtml:
<h:form id="form">
<h:inputText id="number_in" value="#{bean.number}" redisplay="false" >
<f:ajax event="keyup" listener="#{bean.onKeyup}" />
</h:inputText>
<h:dataTable id="dataTable" ...>
...
</h:dataTable>
mybean.java:
#ManagedBean(name="bean")
#SessionScoped
public class Bean {
...
public void onKeyUp(AjaxBehaviorEvent event) {
//Here I want to render the dataTable
}
...
}
How can I achieve that?
You can programmatically add render IDs to PartialViewContext#getRenderIds().
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("form:dataTable");
Note that this can contain only absolute client IDs and should not be prefixed with :.
FacesContext.getCurrentInstance().getPartialViewContext().setRenderAll(true);

Resources