I'm trying to implement JSF button with AJAX which form with AJAX if some criteria is not met. I tried this example:
<h:form id="paymentform" enctype="multipart/form-data" x:data-form-output="form-output-global" x:data-form-type="contact" class="rd-mailform text-left">
<h:commandButton id="buy" class="btn btn-primary" type="submit" value="Put" action="#{dashboard.calculateProcessing}" >
<f:ajax render="@form" execute="@form" x:data-toggle="modal" x:data-target="#demoModal"/> // if #{dashboard.amount} <= 0 call modal dialog
</h:commandButton>
<div class="modal fade" id="demoModal" role="dialog">
.....
</div>
</h:form>
@Named
@SessionScoped
public class Dashboard implements Serializable {
private static final long serialVersionUID = -2363083605115312742L;
private double amount;
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}
If I edit the button this way:
<h:commandButton id="buy" class="btn btn-primary" type="submit" value="Put" action="#{dashboard.calculateProcessing}" x:data-toggle="modal" x:data-target="#demoModal" >
The dialog is display and the form is submitted.
But I can't find a solution how to not submit the form if some criteria from the Bean is not met. Can you guide me how to find a solution?
<Removed blatant begging for help, see edits>