p:commandButton inside p:dialog does not work - jsf

I have this problem and I search here and some pages on Google and none of the answers worked for me.
I have the following dialog:
<!-- Dialog Fechar Pedido -->
<p:dialog header="Fechar Pedido" widgetVar="clsPedido" id="clsPedido" minWidth="550">
<h:form prependId="true" id="frmClsPedido">
<p:panel id="pnlDialogClsPedido" header="Informe a forma de pagamento">
<h:panelGrid id="grdClsPedido" columns="2" cellpadding="5">
<p:outputLabel value="Valor Total:." />
<p:outputLabel value="R$ #{pedidoMB.totalPedido}" size="5" style="color: red;">
<f:convertNumber currencySymbol="R$" integerOnly="true" pattern="#0.00" locale="pt_BR" minFractionDigits="1" minIntegerDigits="1" />
</p:outputLabel>
<p:outputLabel value="Valor Recebido:." />
<pe:inputNumber id="vlrRecebido" value="#{pedidoMB.vlrRecebido}" minValue="0" required="true" onblur="returnValue(this.value)" requiredMessage="Informe o valor recebido!" decimalPlaces="2" decimalSeparator="," thousandSeparator="." />
<p:outputLabel value="Pagamento em:." />
<p:selectOneRadio id="frmPagamento" value="#{pedidoMB.frmPagamento}" onchange="daTroco(this.value);" required="true" requiredMessage="Informe a forma de pagamento!">
<f:selectItem itemLabel="Dinheiro" itemValue="DIN" />
<f:selectItem itemLabel="Débito" itemValue="DEB" />
<f:selectItem itemLabel="Crédito" itemValue="CRED" />
<f:selectItem itemLabel="Vale Refeição" itemValue="REF" />
</p:selectOneRadio>
<p:outputLabel value="Valor Troco:." />
<p:inputText value="#{pedidoMB.vlrTroco}" size="5" style="color: blue;" id="vlrTroco" widgetVar="vlrTroco" readonly="true">
<f:convertNumber currencySymbol="R$" integerOnly="true" pattern="#0.00" locale="pt_BR" minFractionDigits="1" minIntegerDigits="1" />
</p:inputText>
</h:panelGrid>
<h:messages></h:messages>
<div align="right">
<p:commandButton icon="ui-icon-disk" actionListener="#{pedidoMB.doFecharPedido}" />
</div>
</p:panel>
</h:form>
</p:dialog>
And I have the following method at my mbean:
public void doFecharPedido(ActionEvent event) {
if (getId() != null) {
Pedido p = getService().findById(getId());
getService().fecharPedido(getVlrRecebido(), getVlrTroco(), p);
}
}
I already tried removing the mbean ActionEvent but nothing seems to work.

Why not simply write
<p:commandButton icon="ui-icon-disk" action="#{pedidoMB.doFecharPedido}" />
and
public void doFecharPedido() {
if(getId() != null) {
Pedido p = getService().findById(getId());
getService().fecharPedido(getVlrRecebido(), getVlrTroco(), p);
}
}
?

The problem was a validation error. For some reason the inputNumber from PF extension does not accept a paste value or some other form of automatic fill of the field.

Related

How to create form with multiple page on JSF with PrimeFaces

Hi I wanna ask something, I try to make a form for website using java with primeface, I make this form with 2 page but when I try to input data, the data from second page can't set on database sometimes when I try to modify the code the data on first page can't set but the data on second page can be set on database
this my code for save data
public String save(){
String nextPage = "";
PRPKUserNonIt PRPKUser = new PRPKUserNonIt();
PRPKUser prpkUser = new PRPKUser();
setListUserSelected(chooseBean.getListSelecteduser());
try{
prpkUserController.save(prpkUser);
nextPage = "/prpk/master_prpk.xhtml?faces-redirect=true";
RequestContext rq = RequestContext.getCurrentInstance();
rq.execute("PF('successDialog').show();");
}catch(Exception e){
e.printStackTrace();
FacesMessage messageFailed = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error","Save data failed");
RequestContext.getCurrentInstance().showMessageInDialog(messageFailed);
nextPage = "#";
}
Group group = new Group();
setListGroupSelected(chooseTargetSDDialogBean.getGroupSelection());
try{
groupController.save(group);
nextPage = "/prpk/master_prpk.xhtml?faces-redirect=true";
RequestContext rq = RequestContext.getCurrentInstance();
rq.execute("PF('successDialog').show();");
}catch(Exception e){
e.printStackTrace();
FacesMessage messageFailed = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error","Save data failed");
RequestContext.getCurrentInstance().showMessageInDialog(messageFailed);
nextPage = "#";
}
PRPKNon PRPKNon = new PRPKNon();
PRPKNon.setUser_non_itId(userLogin.getId());
PRPKNon.setSenderId(userLogin.getId());
PRPKNon.setPic_prpkId(userLogin.getId());
PRPKNon.setCreatedBy(userLogin.getName());
PRPKNon.setUpdatedBy(userLogin.getName());
for (Map.Entry<String, Integer> e : prpkTypeIdMap.entrySet()) {
if (prpkTypeTypeId.equals(e.getValue())) {
prpkTypeType = e.getKey();
continue;
}
}
PRPKNon.setPrpkTypeId(prpkTypeTypeId); //diubah
PRPKNon.setPrpkTypeName(prpkTypeType);
PRPKNon.setPrpkDesc(prpkDesc);
PRPKNon.setMemoNumber(memoNumber);
for (Map.Entry<String, Integer> e : priorityIdMap.entrySet()) {
if (priorityTypeId.equals(e.getValue())) {
priorityType = e.getKey();
continue;
}
}
setPriorityLevelId(priorityTypeId);
setPriorityName(priorityType);
for (Map.Entry<String, Integer> e : departmentIdMap.entrySet()) {
if (departmentTypeId.equals(e.getValue())) {
departmentType = e.getKey();
continue;
}
}
for (Map.Entry<String, Integer> e : businessUnitIdMap.entrySet()) {
if (businessUnitTypeId.equals(e.getValue())) {
businessUnitType = e.getKey();
continue;
}
}
PRPKNon.setPriorityId(getPriorityLevelId());//diubah
PRPKNon.setPriorityLevel(getPriorityName());
PRPKNon.setBusinessUnitId(getBusinessId());
PRPKNon.setBusinessUnitName(getBussinessName());
PRPKNon.setPicDepartmentId(getDepartmentId());
PRPKNon.setDepartmentName(getDepartmentNames());
PRPKNon.setBusinessUnitId(getBusinessUnitId());
PRPKNon.setPicDepartmentId(departmentTypeId);//diubah
System.out.println("Pic : "+ prpk.getPicDepartmentId());
PRPKNon.setDepartmentName(departmentType);
PRPKNon.setBusinessUnitId(businessUnitTypeId);//diubah
PRPKNon.setBusinessUnitName(businessUnitType);
nextPage = "/prpk/next_prpk_new.xhtml?faces-redirect=true";
PRPKNon.setPrpkRequest(prpkRequest);
PRPKNon.setPrpkBackground(prpkBackground);
PRPKNon.setPrpk_analysisBenefit(prpk_analysisBenefit);
try{
prpkNonController.save(PRPKNon);
nextPage = "/prpk/next_prpk_new.xhtml?faces-redirect=true";
RequestContext rq = RequestContext.getCurrentInstance();
rq.execute("PF('successDialog').show();");
}catch(Exception e){
e.printStackTrace();
FacesMessage messageFailed = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error","Save data failed");
RequestContext.getCurrentInstance().showMessageInDialog(messageFailed);
nextPage = "#";
}
return nextPage;
}
this xhtml for the first page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
template="/user_templates/template.xhtml">
<ui:define name="metadata">
</ui:define>
<ui:define name="content">
<h:form id="formId" style="margin-top:35;" prependId="false">
<p:contextMenu>
<p:menuitem value="© Indomaret" />
</p:contextMenu>
<p:breadCrumb>
<p:menuitem value="Home" />
<p:menuitem value="PRPK" />
<p:menuitem value="List PRPK"/>
<p:menuitem value="Add New PRPK"/>
<p:menuitem value="#{pRPKUserNonItBean.header}" />
</p:breadCrumb>
<h:panelGrid id="TableInputId" columns="2" cellpadding="10" >
<h:panelGrid id="inputGridId1" columns="3" cellpadding="10" >
<p:outputLabel value="PRPK Type" for="prpktypeTxt" />
<p:selectOneMenu id="prpktypeTxt" value="#{pRPKUserNonItBean.prpkTypeTypeId}"
>
<p:ajax listener="#{pRPKUserNonItBean.updateButton}" update="formId"/>
<f:selectItem itemLabel="None Selected" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{pRPKUserNonItBean.prpkTypeIdMap}" />
</p:selectOneMenu>
<p:message for="prpktypeTxt" display="icon" />
<p:outputLabel value="PRPK Reference" for="prpkReferenceTxt" />
<h:panelGrid columns="2" cellpadding="0" border="0">
<p:inputText id="prpkReferenceTxt" disabled="true"
readonly="true" style="width:200; height:25"
value="#{pRPKUserNonItBean.prpkReference}" />
<p:commandButton icon="ui-icon-search"
action="#{pRPKUserNonItBean.showPRPKReferenceDialog}" rendered="#{pRPKUserNonItBean.prpkReferenceRendered}" process="#this">
<p:ajax event="dialogReturn" update="prpkReferenceTxt" />
</p:commandButton>
</h:panelGrid>
<p:message for="prpkReferenceTxt" display="icon"></p:message>
<p:outputLabel value="Description" for="descriptionTxt" />
<p:inputTextarea id="descriptionTxt" required="true" style="width:300; height:50"
value="#{pRPKUserNonItBean.prpkDesc}" />
<p:message for="descriptionTxt" display="icon"></p:message>
<p:outputLabel value="Memo" for="memoTxt"
style="display:block; width:100px;" />
<p:inputText id="memoTxt" required="true" style="width:225; height:25"
value="#{pRPKUserNonItBean.memoNumber}" />
<p:message for="memoTxt" display="icon"></p:message>
</h:panelGrid>
<h:panelGrid id="inputGridId2" columns="3" cellpadding="10" >
<p:outputLabel value="Priority Level" for="prioritylevelTxt" />
<p:selectOneMenu id="prioritylevelTxt" value="#{pRPKUserNonItBean.priorityTypeId}"
>
<f:selectItem itemLabel="None Selected" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{pRPKUserNonItBean.priorityIdMap}" />
</p:selectOneMenu>
<p:message for="prioritylevelTxt" display="icon" />
<p:outputLabel value="Department" for="departmentTxt" />
<p:selectOneMenu id="departmentTxt" value="#{pRPKUserNonItBean.departmentTypeId}"
>
<f:selectItem itemLabel="None Selected" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{pRPKUserNonItBean.departmentIdMap}" />
</p:selectOneMenu>
<p:message for="departmentTxt" display="icon" />
<p:outputLabel value="OPU" for="opuTxt" />
<p:selectOneMenu id="opuTxt" value="#{pRPKUserNonItBean.businessUnitTypeId}"
>
<f:selectItem itemLabel="None Selected" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{pRPKUserNonItBean.businessUnitIdMap}" />
</p:selectOneMenu>
<p:message for="opuTxt" display="icon" />
<p:row></p:row><p:row></p:row><p:row></p:row>
<p:row></p:row><p:row></p:row><p:row></p:row>
<p:row></p:row><p:row></p:row><p:row></p:row>
<p:row></p:row><p:row></p:row><p:row></p:row>
<p:row></p:row><p:row></p:row><p:row></p:row>
</h:panelGrid>
</h:panelGrid>
<p:outputLabel value="Target SD *" style="border:0;margin-top:10;margin-left:25;"/>
<h:panelGrid width="60%">
<p:commandButton value="Select Target SD"
action="#{pRPKUserNonItBean.showTargetSDDialog()}" immediate="true" >
<p:ajax event="dialogReturn" update="targetTable"/>
</p:commandButton>
<p:dataTable
paginatorPosition="bottom" rows="3" paginator="true"
rowsPerPageTemplate="10,15,25,50,100" rowIndexVar="rowIndex"
currentPageReportTemplate="Showing {startRecord}-{endRecord} out of {totalRecords}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
style="font-size:12px;"
var="group" widgetVar="targetTables" value="#{chooseTargetSDDialogBean.listGroupTemp}" id="targetTable">
<p:column headerText="No" width="5%">
<h:outputText value="#{rowIndex+1}" />
</p:column>
<p:column headerText="Target SD" width="40%">
<h:outputText value="#{group.name}" />
</p:column>
<p:column headerText="Description" width="45%">
<h:outputText value="#{group.description}" />
</p:column>
<p:column headerText="Delete" width="10%">
<center>
<p:commandButton icon="ui-icon-trash" action="#{chooseTargetSDDialogBean.deleteChooseGroupTargetSD(group)}" update="targetTable" immediate="true"/>
</center>
</p:column>
</p:dataTable>
</h:panelGrid>
<p:commandButton value="Cancel"
style="position: relative; bottom: -15px;" icon="ui-icon-circle-close"
process="#this" action="/prpk/master_prpk.xhtml?faces-redirect=true" />
<p:commandButton value="Next"
style="float:right; position: relative; bottom: -15px;" icon="ui-icon-arrow-1-e"
action="#{PRPKUserNonItBean.save}" process="#this">
<!-- <p:confirm header="Confirmation"
message="Are you sure the data correct ?" icon="ui-icon-alert" /> -->
</p:commandButton>
</h:form>
</ui:define>
and this xhtml for the second page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
template="/user_templates/template.xhtml">
<ui:define name="metadata">
</ui:define>
<ui:define name="content">
<h:form id="formId" style="margin-top:35;">
<p:contextMenu>
<p:menuitem value="© Indomaret" />
</p:contextMenu>
<p:breadCrumb>
<p:menuitem value="PRPK" />
<p:menuitem value="PRPK" />
<p:menuitem value="List PRPK" />
<p:menuitem value="Add New PRPK"
url="/prpk/prpk_new.xhtml?faces-redirect=true" />
<p:menuitem value="#{pRPKUserNonItBean.header}" />
</p:breadCrumb>
<h:panelGrid style="margin-left:5;margin-top:20;">
<h2>PIC PRPK *</h2>
</h:panelGrid>
<h:panelGrid style="margin-left:0;margin-bottom:20;margin-top:5;">
<p:commandButton value="Select PIC PRPK" icon="ui-icon-circle-plus"
action="#{pRPKUserNonItBean.showPicPRPKDialog}" immediate="true">
<p:ajax event="dialogReturn" update="roleTbl" />
</p:commandButton>
<p:dataTable var="prpk" id="roleTbl"
value="#{chooseNonITUserDialogBean.listUserTemp}">
<p:column headerText="Name">
<h:outputText value="#{prpk.name}" />
</p:column>
<p:column headerText="Department">
<h:outputText value="#{prpk.departmentName}" />
</p:column>
<p:column headerText="Head user">
<h:outputText value="#{prpk.headUserName}" />
</p:column>
<p:column headerText="Delete" width="10%">
<center>
<p:commandButton icon="ui-icon-trash"
action="#{chooseNonITUserDialogBean.deleteUser(prpk)}"
update="roleTbl"
immediate="true" />
</center>
</p:column>
</p:dataTable>
</h:panelGrid>
<h:panelGrid columns="3" cellpadding="5" style="margin-left:10;">
<p:outputLabel value="Request" for="requestTxt"
style="display:block; width:100px;" />
<p:inputTextarea id="requestTxt" required="true"
style="width:700; height:25" value="#{pRPKUserNonItBean.prpkRequest}" />
<p:message for="requestTxt" display="icon"></p:message>
<p:outputLabel value="Background" for="backgroundTxt" />
<p:inputTextarea id="backgroundTxt" style="width:700; height:25"
value="#{pRPKUserNonItBean.prpkBackground}" />
<p:message for="backgroundTxt" display="icon"></p:message>
<p:outputLabel value="Benefit Analysis" for="beNalTxt" />
<p:inputTextarea id="beNalTxt" style="width:700; height:25"
value="#{pRPKUserNonItBean.prpk_analysisBenefit}" />
<p:message for="beNalTxt" display="icon"></p:message>
</h:panelGrid>
<h:panelGrid columns="2" style="margin-left:120;">
<p:commandButton value="Back"
style="height:25; font-weight:bold; margin-left:5;"
icon="ui-icon-circle-close" process="#this"
action="/prpk/prpk_new.xhtml?faces-redirect=true" />
<p:commandButton id="submitBtn" value="#{pRPKUserNonItBean.buttonName}"
style=" font-weight:bold;margin-left:10;"
type="submit" icon="ui-icon-disk" action="#{pRPKUserNonItBean.saveEdit}"
update="formId" />
<p:defaultCommand target="submitBtn" />
</h:panelGrid>
<p:dialog modal="false" widgetVar="successDialog" header="Info"
closable="false">
<h:panelGrid columns="1" cellpadding="2">
<h:outputText value="Save data berhasil" />
<center>
<p:commandButton value="Ok"
action="/prpk/master_prpk.xhtml?faces-redirect=true"
onclick="PF('successDialog').hide()" />
</center>
</h:panelGrid>
</p:dialog>
<p:dialog modal="false" widgetVar="failedDialog" header="Info"
closable="false">
<h:panelGrid columns="1" cellpadding="2">
<h:outputText value="Save data failed" />
<center>
<p:commandButton value="Ok" action="#"
onclick="PF('failedDialog').hide()" />
</center>
</h:panelGrid>
</p:dialog>
</h:form>
</ui:define>

Disable/Delete Not Existing Validation

I implement a <h:form> to edit Employee data which gets preloaded from the database. The preload works fine - all fields get filled with data. The <h:form id="editEmployeeForm"> is surrounded by a <h:form> which contains a <p:dataTable>.
When I do an edit on Employee data and click the "Speichern"-button nothing happens. <p:messages> says all my fields are empty what is obviously a wrong validation because all fields are prefilled. Then I deleted all <p:message> tags from my <h:inputText> tags to check whether the doSaveEmployeeEdit() gets called at all. But nothing happens - no error in console, etc. Even a simple System.out.println() doesn't get printed from the doSaveEmployeeEdit() at all.
Below the <p:dialog> what I have at the time:
<h:form id="editEmployeeForm">
<p:dialog header="Angestellten ändern" id="employeeEditDialog" widgetVar="employeeEditDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" closeOnEscape="true">
<p:outputPanel id="employeeDataEdit" rendered="#{not empty employeeEditController.employee}">
<h:panelGrid columns="2">
<p:outputLabel for="usernameEdit" value="Benutzername: " />
<p:inputText id="usernameEdit" value="#{employeeEditController.employee.username}" disabled="true" />
</h:panelGrid>
<p:separator/>
<h:panelGrid columns="6">
<p:outputLabel for="firstnameEdit" value="Vorname: " />
<p:inputText id="firstnameEdit" value="#{employeeEditController.employee.firstName}" />
<p:outputLabel for="lastnameEdit" value="Nachname: " />
<p:inputText id="lastnameEdit" value="#{employeeEditController.employee.lastName}" />
<p:outputLabel for="birthdayEdit" value="Geburtsdatum: " />
<p:inputMask mask="99/99/9999" id="birthdayEdit" value="#{employeeEditController.employee.birthday}" />
<p:outputLabel for="locationEdit" value="Wohnort: " />
<p:inputText id="locationEdit" value="#{employeeEditController.employee.location}" />
<p:outputLabel for="streetEdit" value="Straße: " />
<p:inputText id="streetEdit" value="#{employeeEditController.employee.streetName}" />
<p:outputLabel for="postcodeEdit" value="Postleitzahl: " />
<p:inputMask id="postcodeEdit" mask="9999?9" slotChar=" " value="#{employeeEditController.employee.postcode}" />
<p:outputLabel for="phonenumberEdit" value="Telefonnummer: " />
<p:inputMask id="phonenumberEdit" mask="9?99999999999" slotChar=" " maxlength="12" value="#{employeeEditController.employee.phoneNumber}" />
<p:outputLabel for="emailEdit" value="Email: " />
<p:inputText id="emailEdit" validatorMessage="Ungültiges Email-Format!" value="#{employeeEditController.employee.email}">
<f:validateRegex pattern="^$|^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*#[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
</p:inputText>
</h:panelGrid>
<p:separator/>
<h:panelGrid columns="6">
<p:outputLabel for="familyStatus" value="Familienstatus: " />
<p:selectOneMenu id="familyStatus" value="#{employeeEditController.employee.familyStatus}" style="width:150px">
<f:selectItem itemLabel="Wähle Familienstatus" itemValue="#{employeeEditController.employee.familyStatus}" />
<f:selectItems value="#{enumController.familyStatus}" />
</p:selectOneMenu>
<p:outputLabel for="Religion" value="Religion: " />
<p:selectOneMenu id="Religion" value="#{employeeEditController.employee.religion}" style="width:150px">
<f:selectItem itemLabel="Wähle Religion" itemValue="#{employeeEditController.employee.religion}" />
<f:selectItems value="#{enumController.religions}" />
</p:selectOneMenu>
<p:outputLabel for="Role" value="Rolle: " />
<p:selectOneMenu id="Role" value="#{employeeEditController.employee.workRole}" style="width:150px">
<f:selectItem itemLabel="Wähle Arbeitsrolle" itemValue="#{employeeEditController.employee.workRole}" />
<f:selectItems value="#{enumController.workRoles}" />
</p:selectOneMenu>
</h:panelGrid>
<p:separator/>
<h:panelGrid columns="3">
<p:commandButton value="Speichern" action="#{employeeEditController.doSaveEmployeeEdit()}" />
<p:commandButton value="Neu laden" action="#{employeeEditController.doReloadEmployee()}" />
<p:commandButton value="Abbruch" onclick="PF('employeeEditDialog').hide()" />
</h:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
What can be the reason that html or whatever still do the validation and don't call the doSaveEmployeeEdit()?
UPDATE:
I made a new xhtml-file with same outputs - no validation anymore. But my controller method doesn't get called.
My children.xhtml:
<h:body>
<body class="theme-blue sidebar-mini sidebar-collapse">
<div class="wrapper">
<div class="content-wrapper" style="min-height: 1126px;">
<section class="content">
<div class="box">
<div class="box-body">
<h:form id="childForm">
<p:dataTable id="childTable" var="child" value="#{childController.children}">
<p:column headerText="Vorname">
<h:outputText value="#{child.firstName}" />
</p:column>
<p:column headerText="Nachname">
<h:outputText value="#{child.lastName}" />
</p:column>
<p:column headerText="Geburtsdatum">
<h:outputText value="#{child.birthday}" />
</p:column>
<p:column style="width:32px;text-align: center">
<p:commandButton update=":childForm:childEdit" oncomplete="PF('childEditDialog').show()" icon="ui-icon-note" title="Bearbeiten">
<f:setPropertyActionListener value="#{child}" target="#{childEditController.childEdit}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Kind bearbeiten" widgetVar="childEditDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:messages autoUpdate="true" />
<p:outputPanel id="childEdit" style="text-align:center;">
<p:panelGrid columns="2" rendered="#{not empty childEditController.childEdit}" columnClasses="label,value">
<p:outputLabel id="primParent" value="primäres Elternteil:" />
<p:inputText for="primParent" value="#{childEditController.childEdit.primaryParent.id}" disabled="true" />
<p:outputLabel id="firstName" value="Vorname:" />
<p:inputText for="firstName" value="#{childEditController.childEdit.firstName}" />
<p:outputLabel id="lastName" value="Nachname:" />
<p:inputText for="lastName" value="#{childEditController.childEdit.lastName}" />
<p:outputLabel id="birthDay" value="Geburtsdatum:" />
<p:inputText for="birthDay" value="#{childEditController.childEdit.birthday}" />
<p:outputLabel id="emgNum" value="Notfallkontakt:" />
<p:inputText for="emgNum" value="#{childEditController.childEdit.emergencyNumber}" />
<p:outputLabel id="imgName" value="Bildname:" />
<p:inputText for="imgName" value="#{childEditController.childEdit.imgName}" />
<p:outputLabel for="gender" value="Geschlecht: " />
<p:inputText id="gender" value="#{childEditController.childEdit.gender}" disabled="true" />
<p:separator />
<h:panelGrid columns="3">
<p:commandButton value="Speichern" action="#{childEditController.doSaveChild}" update=":childForm:childTable" />
<p:commandButton value="Abbruch" onclick="PF('childEditDialog').hide()" immediate="true" />
</h:panelGrid>
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</div>
</div>
</section>
</div>
</div>
</body>
</h:body>
My childEditController:
#Component
#Scope("request")
public class ChildEditController {
#Autowired
private ChildService childService;
private Child childEdit;
public Child getChildEdit() {
return childEdit;
}
public void setChildEdit(Child childEdit) {
this.childEdit = childEdit;
}
public void doSaveChild(){
childEdit = childService.saveChild(childEdit);
childEdit = null;
}
}

p:chart does not update

I am trying to update a <p:chart> upon hitting the submit button but the graph is always staying the same. I googled this and I was told to use an Ajax update command which I was already doing. Here is my Code:
.xhtml
<body>
<ui:define name="content">
<h:form id="chartForm">
<p:growl id="msgs" showDetail="true" />
<p:panel header="Select a Location" style="margin-bottom:10px;">
<h:panelGrid columns="4" cellpadding="5">
<p:outputLabel for="facility" value="Facility: " />
<p:selectOneMenu id="facility" value="#{visualization.facility}" converter="#{facilityConverterBean}" style="width:150px">
<p:ajax event="change" process="#this" partialSubmit="true" listener="#{visualization.onFacilityChange()}" update="component" />
<f:selectItem itemLabel="Select Facility" noSelectionOption="true" />
<f:selectItems value="#{visualization.facilities}" var="facility" itemLabel="#{facility.name}" itemValue="#{facility}" />
</p:selectOneMenu>
<p:outputLabel for="component" value="Components: " />
<p:selectOneMenu id="component" value="#{visualization.component}" converter="#{componentConverterBean}" style="width:150px">
<f:selectItem itemLabel="Select Component" noSelectionOption="true" />
<f:selectItems value="#{visualization.components}" var="comp" itemLabel="#{comp.name}" itemValue="#{comp}" />
</p:selectOneMenu>
<p:outputLabel for="datetimefrom" value="Datetime from" />
<p:calendar id="datetimefrom" value="#{visualization.dateFrom}" pattern="dd/MM/yyyy HH:mm" />
<p:outputLabel for="datetimeto" value="Datetime to" />
<p:calendar id="datetimeto" value="#{visualization.dateTo}" pattern="dd/MM/yyyy HH:mm" />
<h:outputLabel for="recordcount" value="Record count" />
<p:spinner id="recordcount" value="#{visualization.recordCount}" stepFactor="25" />
</h:panelGrid>
<p:separator />
<p:commandButton value="Submit" actionListener="#{visualization.fetchDataRecords()}" update="chartForm:chartTab:lineChartTemperatures" icon="ui-icon-check" />
</p:panel>
<p:tabView id="chartTab">
<p:tab title="Diagramm">
<p:chart id="lineChartTemperatures" type="line" model="#{lineChart.dateModel}" style="margin-bottom: 1px" responsive="true" />
</p:tab>
<p:tab title="DataTable">
<h:panelGrid>
<h:outputText value="....not implemented" />
</h:panelGrid>
</p:tab>
</p:tabView>
</h:form>
</ui:define>
</body>
fetchDataRecords()
public void fetchDataRecords(){
List<BhkwRecord> data = bhkwService.getRecordsFromTo(component.getId(), dateFrom, dateTo);
//System.out.println("Amount of records fetched: " + data.size());
lineChart.updateBhkwChartRuecklauf(data);
}
Method where another series is added to the graph
public void updateBhkwChartRuecklauf(List<BhkwRecord> data) {
//data not used here, just added simulated data to test
LineChartSeries series3 = new LineChartSeries();
series3.setLabel("Series3");
series3.set("2014-01-01 00:10:50", 54);
series3.set("2014-01-01 01:12:50", 20);
series3.set("2014-01-01 04:14:50", 60);
series3.set("2014-01-01 06:17:50", 30);
dateModel.addSeries(series3);
}
So normally, after button hit, the method should add another series of data to the graph and get updated but nothing is happening. I also tried update="#form" which wouldn't work either. Does anyone have an idea what I am doing wrong?
<p:tab title="Diagramm">
<p:outputPanel id="chartPnl>
<p:chart id="lineChartTemperatures" type="line" model="#{lineChart.dateModel}" style="margin-bottom: 1px" responsive="true" />
</p:outputPanel>
</p:tab>
You can try to put chart in another -like outputPanel- component and update it in commandButton.
<p:commandButton value="Submit" actionListener="#{visualization.fetchDataRecords()}" update="chartForm:chartTab:chartPnl" icon="ui-icon-check" />

Missing value in modal dialog in edit mode

I'm newbie in Java and PrimeFaces (I have worked only with c# and visual sudio).
When I try to edit a row, column value isn't displayed in modal dialog.
I've tried different solution, same result.
Can someone help me?
<ui:include src="/includes/header.xhtml" />
<!-- Container -->
<div id="container">
<div class="shell">
<div id="main" style="vertical-align: middle;">
<br /> <br />
<form>
<p:dataTable var="loc" value="#{location.loc}" rowKey="#{loc.code}" id='loca'>
<p:column width="100">
<p:commandButton icon="ui-icon-plus" type="button" id="add" onclick="PF('newDialog').show()" update="Newform:NewLocation"/>
<p:commandButton icon="ui-icon-pencil" type="button" update="updForm:updDisplay" onclick="PF('updDialog').show()" id="edit" ajax="true">
</p:commandButton>
<p:commandButton icon="ui-icon-trash" />
</p:column>
<p:column headerText="Code">
<h:outputText value="#{loc.code}" />
</p:column>
<p:column headerText="Ip">
<h:outputText value="#{loc.address}" />
</p:column>
<p:column headerText="Descrizione">
<h:outputText value="#{loc.description}" />
</p:column>
</p:dataTable>
</form>
<p:dialog widgetVar="newDialog" header="Insert Location" width="430" height="220" modal="true">
<h:form id="Newform">
<p:outputPanel id="NewLocation">
<h:panelGrid columns="2">
<h:outputLabel value="Code" />
<p:inputText value="#{loc.Code}"></p:inputText>
<h:outputLabel value="description" />
<p:inputText value="#{loc.description}"></p:inputText>
<h:outputLabel value="Address" />
<p:inputText value="#{loc.address}"></p:inputText>
</h:panelGrid>
<p:commandButton value="Save" onclick="newDialog.close()">
</p:commandButton>
</p:outputPanel>
</p:dialog>
<p:dialog widgetVar="updDialog" header="Location" width="430" height="220" modal="true">
<h:form id="updForm">
<p:outputPanel id="updDisplay">
<h:inputHidden value="#{loc.code}" />
<h:panelGrid columns="2">
<h:outputLabel value="Description" />
<p:inputText value="#{loc.description}"></p:inputText>
<h:outputLabel value="Address" />
<p:inputText value="#{loc.address}"></p:inputText>
</h:panelGrid>
<p:commandButton value="Update" onclick="updDialog.close()">
</p:commandButton>
<p:commandButton value="Delete" onclick="updDialog.close()">
</p:commandButton>
<p:growl id="growl" showDetail="true" />
</p:outputPanel>
</h:form>
</p:dialog>
MangedBean:
#ManagedBean (name="Locations")
#SessionScoped
public class Locations {
#EJB
cslocationBeanRemote locationsBean;
private List<cslocationModel> ListLocations;
#SuppressWarnings({"unchecked", "rawtypes"})
#PostConstruct
public void init() {}
public List<cslocationModel> getListLocations() {
try {
ArrayList orderBy = new ArrayList();
orderBy.add(cslocationModel.ORDERcodASC);
setListLocations((List<cslocationModel>) locationsBean.find(null,
null, null, orderBy));
} catch (Exception ecc) {
ecc.printStackTrace();
}
return ListLocations;
}
public void setListLocations(List<cslocationModel> ListLocations) {
this.ListLocations = ListLocations;
}
}
Thank you.

JSF buttons doesn't send data to bean

I have some JSF page and some bean, in cae that it is editing curent ellement i use update otherwice i use save methods.
I tryed to debug and think methods on buttons never executes
Here is my JSF page:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>Manage panel</title>
</h:head>
<h:body>
<h3>Add/edit patient</h3>
<h:form>
<c:set var="patient" value="#{manageBean.patient}" />
<c:choose>
<c:when test="#{patient!=null}">
<p:panel id="panel1" header="Patient" style="margin-bottom:10px;">
<h:panelGrid columns="2">
<h:outputLabel for="name" value="First name" />
<p:inputText id="firstName" required="true" value="#{patient.firstName}" />
<h:outputLabel for="name" value="Family name" />
<p:inputText id="familyName" required="true" value="#{patient.familyName}" />
<h:outputLabel for="name" value="Sex" />
<p:selectOneMenu id="sex" value="#{patient.sex}">
<f:selectItems value="#{manageBean.sex}"/>
</p:selectOneMenu>
<h:outputLabel for="name" value="Birthday date" />
<p:calendar value="#{patient.birthdayDate}" mode="inline" id="birthdayDate"/>
<h:outputLabel for="name" value="Nationality" />
<p:selectOneMenu id="nationality" value="#{patient.nationality}">
<f:selectItems value="#{manageBean.nationality}"/>
</p:selectOneMenu>
<h:outputLabel for="name" value="Adress" />
<p:inputText id="adress" required="true" value="#{patient.adress}" />
<h:outputLabel for="name" value="Phone number" />
<p:inputMask id="phoneNumber" required="true" value="#{patient.phoneNumber}" mask="(999) 999-9999"/>
</h:panelGrid>
</p:panel>
<p:commandButton value="Update" type="submit" action="#{manageBean.update(patient)}" />
</c:when>
<c:otherwise>
<p:panel id="panel2" header="Patient" style="margin-bottom:10px;">
<h:panelGrid columns="2">
<h:outputLabel for="name" value="First name" />
<p:inputText id="firstName" required="true" value="" />
<h:outputLabel for="name" value="Family name" />
<p:inputText id="familyName" required="true" value="" />
<h:outputLabel for="name" value="Sex" />
<p:selectOneMenu id="sex" value="">
<f:selectItems value="#{manageBean.sex}"/>
</p:selectOneMenu>
<h:outputLabel for="name" value="Birthday date" />
<p:calendar mode="inline" id="birthdayDate"/>
<h:outputLabel for="name" value="Nationality" />
<p:selectOneMenu id="nationality" value="">
<f:selectItems value="#{manageBean.nationality}"/>
</p:selectOneMenu>
<h:outputLabel for="name" value="Adress" />
<p:inputText id="adress" required="true" value="" />
<h:outputLabel for="name" value="Phone number" />
<p:inputMask id="phoneNumber" required="true" value="" mask="(999) 999-9999"/>
</h:panelGrid>
</p:panel>
<p:commandButton value="Save" action="#{manageBean.save(firstName, familyName, sex, birthdayDate, nationality, adress, phoneNumber)}" />
</c:otherwise>
</c:choose>
</h:form>
</h:body>
</html>
Here is my bean methods:
public String update(Patient patient) {
Session session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.update(patient);
tx.commit();
} catch (HibernateException ex) {
if (tx != null) {
tx.rollback();
}
ex.printStackTrace();
} finally {
session.close();
}
return "go_home";
}
public String save(String fitstName, String familyName, Sex sex, Date birthdayDate, Nationality nationallity, String adress, String phoneNumber){
Session session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Patient patient = new Patient();
patient.setFirstName(fitstName);
patient.setFamilyName(familyName);
patient.setSex(sex);
patient.setBirthdayDate(birthdayDate);
patient.setNationality(nationallity);
patient.setAdress(adress);
patient.setPhoneNumber(phoneNumber);
session.save(patient);
tx.commit();
} catch (HibernateException ex) {
if (tx != null) {
tx.rollback();
}
ex.printStackTrace();
} finally {
session.close();
}
return "go_home";
}
Once u give the value attribute in your input tags it ll directly bind the given values to the java class. Create the class variables in ur java class and bind the input tags. EX:-
In your bean class create variables like
private String firstName
and create the getter and setter methods
<f:view>
<h3>Add/edit patient</h3>
<h:form>
<p:panel id="panel1" header="Patient" style="margin-bottom:10px;">
<h:panelGrid columns="2">
<h:outputLabel for="name" value="First name" />
<p:inputText id="firstName" required="true" value="#{manageBean.firstName}" />
<h:outputLabel for="name" value="Family name" />
<p:inputText id="familyName" required="true" value="#{manageBean.familyName}" />
<h:outputLabel for="name" value="Sex" />
<p:selectOneMenu id="sex" value="#{manageBean.sex}">
<f:selectItems value="#{manageBean.sex}"/>
</p:selectOneMenu>
<h:outputLabel for="name" value="Birthday date" />
<p:calendar value="#{manageBean.birthdayDate}" mode="inline" id="birthdayDate"/>
<h:outputLabel for="name" value="Nationality" />
<p:selectOneMenu id="nationality" value="#{manageBean.nationality}">
<f:selectItems value="#{manageBean.nationality}"/>
</p:selectOneMenu>
<h:outputLabel for="name" value="Adress" />
<p:inputText id="adress" required="true" value="#{manageBean.adress}" />
<h:outputLabel for="name" value="Phone number" />
<p:inputMask id="phoneNumber" required="true" value="#{manageBean.phoneNumber}" mask="(999) 999-9999"/>
</h:panelGrid>
</p:panel>
<p:commandButton value="Update" type="submit" action="#{manageBean.update}" />
</h:form>
Create a new jsp page and copy-paste these codes inside body tag.
In your java class create the variables and getter setter methods.
Update should be a method which returns a string.

Resources