JSF 2 Input Field mandatory field validation required only when a value is entered
Tag : jsf-2 , By : Nick Coats
Date : March 29 2020, 07:55 AM
With these it helps This is already the default behaviour. Your problem is caused elsewhere. Perhaps you used an int instead of Integer or String, so that it defaults to 0 instead of null. Or perhaps you used an Integer while running the webapp on Tomcat/JBoss wherein the default Apache EL implementation would implicitly coerce it to 0 instead of null. You can turn it off by adding the following VM argument: -Dorg.apache.el.COERCE_TO_ZERO=false
|
disable button in view until value is entered into field?
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Give your order button an id, and when changing the input value to enable it: $("#order-button").removeAttr('disabled');
$("#order-button").attr('disabled', 'disabled');
|
If any input field value entered zero then disable else enable
Date : March 29 2020, 07:55 AM
it fixes the issue You need to initialize count value every time ,because you want to check that value is the statement of having 0 value or not.Put it that setting value in .change() function $(document).ready(function() {
$('input').change(function() {
var count = 0;
$("input").each(function() {
if($(this).val() == "0")
{
count = 1;
}
});
if(count == 0)
{
$("#submitBtn").removeAttr("disabled","disabled");
}
else
{
$("#submitBtn").attr("disabled","disabled");
}
});
});
|
validation of the entered field
Date : March 29 2020, 07:55 AM
To fix this issue You can use Hibernate Validator to validate the @RequestParam of your controller. Add this dependency to your pom.xml <dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.10.Final</version>
</dependency>
@RestController
@RequestMapping("/")
@Validated
public class Controller {
// ...
}
@RequestMapping(value = "/convert", method = RequestMethod.GET, produces = "application/json")
public ExchangeRateDTO converting(@RequestParam("fromCurrency") @NotNull @NotBlank @Size(max = 10) String fromCurrency,
@RequestParam("toCurrency") String toCurrency,
@RequestParam("amount") String amount) throws IOException {
if (!Currency.getAvailableCurrencies().contains(Currency.getInstance(fromCurrency))) {
}
BigDecimal convertedAmount = currencyExchangeService.convert(fromCurrency, toCurrency, new BigDecimal(amount));
|
Validation not working when spaces are entered into a field
Date : March 29 2020, 07:55 AM
|