Primefaces avoid submitting multiple forms - jsf

I am new to Primefaces and I am working on a requirement to open a dialog box when we click on the button.
I could able to open the dialog and submit the form. But here I am facing a new that form behind the modal dialog also get submitted when I am trying to submit the form in the modal. The form behind the modal is a pure html code and modal dialog form is written in primefaces.
Is there any chances to submit the form that is existing in the dialog and skip the form behind the dialog. Could anyone tell me the solution for this?
For clear understanding, I am submitting the code below
<form class="form-horizontal" action="${request.contextPath}/appLogin" role="form" method="POST" h:rendered="true">
<div class="form-group">
<div class="col-sm-12" align="center">
<font color="red"> <h:outputLabel
value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />
</font>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label for="username">Username</label> <input type="text"
class="form-control" name="username" id="username"
placeholder="Enter your username" />
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label for="pwd">Password</label> <input type="password"
class="form-control" name="password" id="password"
placeholder="Enter password" />
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-6">
<input type="checkbox" name="remember" id="remember" />
<h:outputText value=" Remember Me" />
</div>
<div class="col-sm-6" align="right">
<p:commandLink value="Forgot Password?" id="loginforgotpasswordlink"
onclick="clearEmailForgotPasswordPopUp();" />
</div>
</div>
</div>
</div>
</form>
<p:dialog id="emailIdDialog" modal="true" widgetVar="emailIdDialog" width="400"
header="Email Id" appendTo="#(body)" resizable="false">
<ui:include src="/faces/validateEmailId.xhtml" />
</p:dialog>
<div class="form-group">
<p:outputLabel for="emailid1" value="Email" class="col-sm-3 control-label align-right" style="border: 0px solid green;padding-right: 0px;text-align: right;"></p:outputLabel>
<div class="col-sm-9" style="border: 0px solid red;padding-left:0px;">
<p:inputText type="text" id="emailid1"
name="emailid1" required="true" requiredMessage="Please enter an email address"
placeholder="Enter your email id" style="width:100%"/>
</div>
<p:spacer height="10px"></p:spacer>
<div class="text-right" style="padding-left: 0px;">
<p:commandButton value="Submit" update="messages,:emailIdValidation" style="float: right; margin-right: 15px;">
<f:actionListener binding="#{someClassBean.validateEmail()}" />
</p:commandButton>
</div>
</div>
</h:form>
When I am clicking the form submit button in modal dialog the other form also getting submitting.

Related

How to change enable/disable a <p:calendar> and an <p:inputTextarea> when a <p:selectBooleanCheckbox> is checked or not, using primefaces?

I have this part of code:
<!-- /row -->
<div class="row" style="margin-top: 15px">
<div class="span8">
<div class="control-group">
<label class="hcg-control-label span5">Ημερομηνία Ανάκλησης Ποινής</label>
<div class="controls span7">
<p:calendar id="recallDate" styleClass="hcg-full-width cursor-pointer" pattern="dd/MM/yyyy"
value="#{penaltiesView.penalty.recallDate}" disabled="true"/>
<i class="fa fa-calendar hcg-input-icon"></i>
</div>
</div>
</div>
<!-- /span -->
</div>
<!-- /row -->
<div class="row" style="margin-top: 15px">
<div class="span8">
<div class="control-group">
<label class="hcg-control-label span5">Σχόλια Ανάκλησης Ποινής</label>
<div class="controls span7">
<p:inputTextarea rows="6" id="recallComments" styleClass="hcg-full-width" value="#{penaltiesView.penalty.recallComments}" disabled="true"/>
</div>
</div>
</div>
<!-- /span -->
</div>
<!-- /row -->
<div class="row">
<div class="span8">
<div class="control-group">
<label class="hcg-control-label span5">Ανάκληση - Ολοκλήρωση Πειθαρχικής Ποινής</label>
<div class="controls span7">
<p:selectBooleanCheckbox id="RevocationOrCompletion" styleClass="hcg-checkbox margin-bottom-10" value="#{penaltiesView.penalty.revocationOrCompletion}" disabled="#{!penaltiesView.canEdit()}" >
<p:ajax event="change" update="recallDate,recallComments"/>
</p:selectBooleanCheckbox>
</div>
</div>
</div>
<!-- /span -->
</div>
which produces the following components:
Now, what I want to do, is to make the calendar component and the Textarea to get enabled when I check the checkBox and if I uncheck it, they must be disabled again. The use of javascript due to requirements is not a valid way. I am having some difficulties on how to make this happen.
Any suggestions are appreciated.
Thank you in advance.
Your elements can't be updated because you have in your code disabled=true for calendar and textArea. If you want to change disable parameter depending on boolean checkbox than disabled value needs to be a value of boolean checkbox. Your boolean field also needs to have geters and setters.
<p:calendar id="recallDate" styleClass="hcg-full-width cursor-pointer" pattern="dd/MM/yyyy"
value="#{penaltiesView.penalty.recallDate}" disabled="#{penaltiesView.penalty.revocationOrCompletion}"/>
<p:inputTextarea rows="6" id="recallComments" styleClass="hcg-full-width" value="#{penaltiesView.penalty.recallComments}" disabled="#{penaltiesView.penalty.revocationOrCompletion}"/>
<p:selectBooleanCheckbox id="RevocationOrCompletion" styleClass="hcg-checkbox margin-bottom-10" value="#{penaltiesView.penalty.revocationOrCompletion}" disabled="#{!penaltiesView.canEdit()}" >
<p:ajax update="recallDate recallComments" process="#this"/>
</p:selectBooleanCheckbox>

Can't bind to 'formGroup' since it isn't a known property of 'form'. (" <div class="upload-right"> <div class="signup">

I am using Angular 7. I don't know where the error occurs in this form. It always shows form is not a known property of this method. Where did I make a mistake in the below code? I am getting this error.
Can't bind to 'formGroup' since it isn't a known property of 'form'
<form [formGroup]="newClientForm">
<fieldset>
<div class="row" style="text-align:center">
<input type="text" class="st0" placeholder="Enter name" class="form-control" name="name" formControlName="name" #name required="required" />
</div>
<br>
<div class="row" style="text-align:center">
<input type="text" class="st0" placeholder="Enter email" class="form-control" name="email" formControlName="email" #email required="required" pattern="([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?" />
</div>
<br>
<div class="row" style="text-align:center">
<input type="password" class="st0" placeholder="Password" class="form-control" name="password" formControlName="password" #password required="required" pattern=".{6,}"
title="Minimum 6 characters required" autocomplete="off" />
</div>
<br>
<div class="row" style="text-align:center">
<input type="text" class="st0" placeholder="Enter mobile" class="form-control" name="mobile" formControlName="mobile" #mobile required="required" />
</div>
<br>
<div class="row" style="text-align:center">
<!-- <input type="submit" value="Register" /> -->
<button type="submit" class="st1" value="register" (click)="register()">Register</button>
</div>
<br>
<div class="row" style="text-align:center">
<div class="forgot">
Login?
</div>
</div>
<br>
</fieldset>
</form>
Try this stackblitz link reactive form. I have created a similar form using your html code and have run it.
Things i did were very basics:
Imported ReactiveFormsModule from #angular/forms
and have created a formgroup in ts file and added all controls you used in your html.
It runs well.
Let me know if your issue is different from the solution provided.

when i try to refresh a form component from another form using <p:ajax update=""/> it shows error "Cannot find component [duplicate]

This question already has answers here:
How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
(6 answers)
Closed 4 years ago.
Can any one help me out of my problem? though i have been seen semilar problem from this site but i'm unable to fix my problem. here is my code..
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<meta charset="utf-8"/>
<meta name="viewport" content="width=device.width, initial-scale=1"/>
<meta http-equiv="X-UA-Conpatible" content="IE=edge"/>
<h:outputStylesheet library="css" name="bootstrap.css"/>
<link href="resources/css/w3.css" rel="stylesheet" type="text/css"/>
<link href="resources/css/w3-theme-teal.css" rel="stylesheet" type="text/css"/>
<div class="panel panel-info">
<!-- Default panel contents -->
<div class="panel-heading">Student Wise Fees Collection Details</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<div class="panel panel-info" >
<div class="panel-heading">Payment Details</div>
<div class="panel-body">
<div class="col-lg-12 col-md-12 col-sm-12" style="padding-top: 4%">
<h:form id="form1">
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1" style="color: blue;">Student Id:</span>
<p:inputText id="student_id" value="#{controllerBean.selectedfee.stuId}" type="text" readonly="true" style="width: 85%; color: blue;" class="form-control" placeholder="Student Id"/>
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Name:</span>
<p:inputText id="stname" type="text" readonly="true" value="#{controllerBean.selectedfee.name}" class="form-control" placeholder="Name of the student" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Program:</span>
<p:inputText id="pname" type="text" readonly="true" value="#{controllerBean.selectedfee.program}" class="form-control" placeholder="Program Name" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Session:</span>
<p:inputText id="s_name" type="text" readonly="true" value="#{controllerBean.selectedfee.session}" class="form-control" placeholder="Session Name" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Recept No:</span>
<p:inputText id="recptno" type="text" value="#{controllerBean.selectedfee.recptNo}" readonly="true" class="form-control" placeholder="Recept Number" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1">Amount:</span>
<p:inputText id="a_mnt" type="text" value="#{controllerBean.selectedfee.amount}" readonly="true" class="form-control" placeholder="Paid Amount" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 6%;">
<span class="input-group-addon" id="sizing-addon1" style="color: green;">Voucher:</span>
<p:inputText id="voucher" type="text" value="#{controllerBean.selectedfee.AIBLVoucher}" readonly="true" style="color: green;" class="form-control" placeholder="AIBL Voucher Number" />
</div>
<div class="input-group input-group-lg input-group-sm" style="padding-bottom: 4%;">
<span class="input-group-addon" id="sizing-addon1" style="color: red;">AUB Token:</span>
<p:inputText id="aub_token" type="text" value="#{controllerBean.selectedfee.stud_pay_rec_mid}" style="color: red;" readonly="true" class="form-control" placeholder="AUB TXN ID Number" />
</div>
</h:form>
</div>
</div>
</div>
</div>
<div class="col-lg-9 col-md-9 col-sm-9" >
<div class="col-lg-12 col-md-12 col-sm-12" >
<div class="panel panel-info">
<div class="panel-heading">Student's Payment Record</div>
<div class="panel-body">
<h:form id="form2">
<input type="text" class="form-control" id="task-table-filter" data-action="filter" data-filters="#task-table" placeholder="Filter Tasks" />
<p:dataTable class="table table-hover" value="#{controllerBean.listofunifees}" var="FEES_COLLECTION" selection="#{controllerBean.selectedfee}" id="task-table" rowKey="#{FEES_COLLECTION.stud_pay_rec_mid}" selectionMode="single" paginator="true" paginatorPosition="bottom" rows="7" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >
<p:ajax event="rowSelect" update=":form1" />
<p:column headerText="StuId" width="11%">
<h:outputText value="#{FEES_COLLECTION.stuId}" />
</p:column>
<p:column headerText="Student Name">
<h:outputText value="#{FEES_COLLECTION.name}" />
</p:column>
<p:column headerText="Program" width="15%">
<h:outputText value="#{FEES_COLLECTION.program}" />
</p:column>
<p:column headerText="Session" width="11%">
<h:outputText value="#{FEES_COLLECTION.session}" />
</p:column>
<p:column headerText="Rcpt No" width="10%">
<h:outputText value="#{FEES_COLLECTION.recptNo}" />
</p:column>
<p:column headerText="Amount" width="10%">
<h:outputText value="#{FEES_COLLECTION.amount}" />
</p:column>
<p:column headerText="Voucher" width="11%">
<h:outputText value="#{FEES_COLLECTION.AIBLVoucher}" />
</p:column>
</p:dataTable>
</h:form>
</div>
</div>
</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12" style="padding-top: 0px;">
<div class="col-lg-4 col-md-4 col-sm-4">
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<h:form id="form3">
<button type="button" class="btn btn-success btn-sm col-lg-5 col-md-5 col-sm-5">Save</button>
<div class="col-lg-2 col-md-2 col-sm-2"></div>
<button type="button" class="btn btn-danger btn-sm col-lg-5 col-md-5 col-sm-5">Cancel</button>
</h:form>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
</div>
</div>
</div>
</div>
</div>
</ui:composition>
When i run this code, it shows javax.faces.FacesException: Cannot find component with expression ":form1:st_id" referenced from "centrepage:form2:task-table".
Now i've got my answer. The should be ":centrepage:form1:st_id, .., ..." and so on. bottom line is update="centrepage:form1:st_id". thanks for every one

PrimeFaces.cw does not show dialog content

When i use PrimeFaces.cw..
PrimeFaces.cw("Dialog","checkoutDlg",{
id:"j_idt115",
draggable:false,
resizable:false,
modal:true,
width:"auto",
maxWidth: „1083“,
showEffect:"blind",
hideEffect:"blind",
closeOnEscape:true,
fitViewport:true,
onShow:function(){
styleDialogCheckoutBtn()
}
});
..to show a dialog, I just see the lightbox, but the content does not appear.
<p:commandButton id="btnCheckOut" styleClass="btn btn-block btn-success" value="Add to card" process="#this"
oncomplete="PrimeFaces.cw('Dialog','checkoutDlg',{ id:'checkoutDlg', draggable:false, resizable:false, modal:true, width:'auto', maxWidth: '1083', showEffect:'blind', hideEffect:'blind', closeOnEscape:true, fitViewport:true, onShow:function(){styleDialogCheckoutBtn()} }); PF('checkoutDlg').initPosition(); PF('checkoutDlg').show(); return false;"/>
Dialog content:
<p:dialog widgetVar="checkoutDlg" id="checkoutDlg">
<div class="cart-items">
<div class="row-fluid cart-head-row clearfix">
<div class="col-xs-4">
<p class="text-bold">#{msg['dashboard.cart.checkout.service']}</p>
</div>
<div class="col-xs-4">
<p class="text-bold">#{msg['dashboard.cart.checkout.details']}</p>
</div>
<div class="col-xs-3 text-right">
<p class="text-bold">#{msg['dashboard.cart.checkout.price']}</p>
</div>
<div class="col-xs-1"></div>
</div>
</div>
</p:dialog>
Can anyone tell me how to show the content of the dialog in the lightbox?

Params of button always empty even after clicking jsf

I am opening a modal which has form in it. I am trying to check if the button is clicked or not by #{empty param['buttonid']}. But it is always shows empty even when clicked.
<div class="modal fade" jsf:id="dataReset">
<div class="modal-dialog">
<form jsf:id="reset-data-form" class="form-horizontal">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="inputEmail" class="col-sm-3 control-label">Email</label>
<div class="col-sm-9">
<input type="text" class="form-control"
jsf:id="inputEmail" jsf:value="#{dataResetFacade.dataResetEmail}"
name="inputEmail" />
<h:message for="inputEmail" p:class="error-msg"/>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default"
data-dismiss="modal">#{msg['general.button.cancel']}</button>
<button class="btn btn-primary" jsf:id="reset-data-button"
jsf:action="#{dataResetFacade.resetdata}">submit
<f:ajax execute="#form" render="#form aaa bbb messages" onevent="close"/>
</button>
<h:outputText id="aaa" value="#{not empty param['reset-data-button']}"/>
<h:outputText id="bbb" value="#{empty param['reset-data-button']}"/>
</div>
</div>
</form>
</div>
</div>
Am I doing some thing wrong.
You did not specify the right request parameter name there. The request parameter name is basically the JSF component's client ID. The client ID of a JSF input and button component is represented by the HTML element's name attribute. You can find it out by just looking at the JSF-generated HTML output via rightclick, View Source in webbrowser.
Given the current view, that'll look like as below:
<button name="reset-data-form:reset-data-button" ... />
Alter parameter names accordingly:
<h:outputText id="aaa" value="#{not empty param['reset-data-form:reset-data-button']}" />
<h:outputText id="bbb" value="#{empty param['reset-data-form:reset-data-button']}" />
Alternatively, just bind the JSF UIComponent instance to an unique variable name in Facelet scope using binding attribute and then let JSF evaluate the UIComponent#getClientId().
<button jsf:binding="#{resetButton}" ... />
...
<h:outputText id="aaa" value="#{not empty param[resetButton.clientId]}" />
<h:outputText id="bbb" value="#{empty param[resetButton.clientId]}" />
Note: do not bind it to a bean property. The above code is as-is.
See also:
How does the 'binding' attribute work in JSF? When and how should it be used?

Resources