disable the validation when input text is blank - jsf-2

I want to disable the validation when user did not enter the text.I am trying to chech whether the input text is empty. plz suggest hot to check empty for text box.
<h:inputText value="#{countryBean.usersDetailsDTO.firstName}" id="empFName" disabled="#{not(countryBean.selectedEid eq '1')}">
<f:validator validatorId="nameValidation" disabled="#{empty countryBean.usersDetailsDTO.firstName}"/>
</h:inputText>

First, using the disabled attribute in this way would not work as intended because the value of the firstName attribute would be set in the Update Model Values phase, while validation will occur prior to that in the Process Validations phase. I would expect it to disable the validator only if the firstName field were already set to null/empty on the prior request.
As for how to accomplish the task. Please see https://stackoverflow.com/a/6113982/2725716

Related

Grails : Using select tag of grails with disabled property set to true ignores the value

I need to disable a select element in grails depending on its value. The problem is when I started to add the disable property something is quite wrong with the code.
An example is when the form is sent to the backend, its as if there is no value for that select element and the value sent is null. But, when I checked the DOM, there is a selected attribute in the element. I tried to remove that disabled property because I have a feeling that it has something to do with the bug that I'm encountering and I was right because after removing it, everything worked correctly again.
this is the select tag
<g:select name="detail-entryNameId"
value="${journalEntryName.savingId}"
from="${journalEntryNameInstanceList}"
optionKey="savingId"
optionValue="displayName"
readonly="${journalEntryInstance.paymentMade}"
/>
One more thing about this element is that it can occur as many as possible, which means I have a table and in every row, that element exist so I cannot simply manipulate it.
I've also read in this post how can i make a textfield read only in grails? that "If you use disabled="true" the value will not actually be submitted in the form, so the <g:field/> tag should be used." which proves that disable attribute affects the value of the element.
How can I disable the select element and at the same time, still get its value correctly?
The problem is that in HTML the mere existence of the disabled attribute disables the tag. The value of the attribute (true/false) is ignored.
In such cases the solution is to use an <g:if> to create the tag with or without the disabled attribute according to a condition.
In your case, since you want the value even when the tag is disabled you can add a <g:hiddenField> with the same name and value as the disabled select.

Including Empty Text in TFS HTML Field (TFS 2013)

I am trying to add default empty text to an HTML field in TFS 2013. I am doing this by updating the "EmptyText" attribute for the field in the Layout options (using Process Editor).
However, regardless of what I enter here, the intended text is never displayed. It is always empty. I have the same issue with both HTML & Plain Text fields.
Is this a fundamental limitation of TFS? Or am I specifying this incorrectly?
I am not using a DEFAULT rule because I want the user to notice that the field is empty and be required to enter a value.
I can get it work correctly. Two changes made:
Edit the "Empty Text" attribute just as you mentioned above (in my case I create one custom HTML field called Custom.DetailHTML):
Add Required rule to this field to define that this field must be specified with a value:
<FieldDefinition name="DetailHtml" refname="Custom.DetailHtml" type="HTML">
<REQUIRED />
</FieldDefinition>
If you still can't get it work, please show your WIT file.

Clear a field of an existing record while accessing the form

When accessing a form I need to add a field that has to be empty even if in the backend it has value. And when the user enters a value in this field, this newly entered value should replace the old one when the form is submitted.
The code below presents my best attempt, but onload doesn't do anything here for some reason. On the other hand if I use onclick the value is cleared as soon as the field is clicked. Could you please point me to right direction on what I am doing wrong with onload or if there's alternative solution to achieve the same need?
<g:textField
class="internal-text"
name="Internal__c"
value="${Instance?.Internal__c}"
onload="if (this.value != '') {this.value = '';}"
maxlength="20"/>
Thanks!
I'd suggest adding a hidden field and use a dummy text field to set it. The text field can be blank as desired, and when it changes you copy the value to the hidden field.
<g:hiddenField name="Internal__c" value="${Instance?.Internal__c}" />
<g:textField class="internal-text" name="Internal__c_dummy" onchange="this.form.elements['Internal__c'].value = this.value" maxlength="20" />

Not sure if I have an issue with blank constraint or Dynamic Scaffolding

I have a simple Domain class that has a few properties. I want to allow one of them to be empty. I am using blank:true in my constraints block.
In Config.groovy I have set convertEmptyStringsToNull=false. That I believe will keep my form submission from setting the blank field to null and the submit failing on the implicit nullable check.
I am using Dynamic Scaffolding in my controller.
I have added some data via BootStrap.groovy. One record has a blank field and it saves as I would expect.
I then launch my app and the list shows my bootstapped records, including the one with the blank field.
When I try to create a new record, with the property that accepts blanks, I am getting a "Please fill out this field" validation error. I believe the record should save.
I'm not sure if this is an issue with the scaffolded view, an issue with the blank constraint, or me not understanding how these features should work.
Any help would be appreciated.
I guess your entry in Config.groovy is:
grails.databinding.convertEmptyStringsToNull = false
The scaffolding plugin does not take this configurationoption into account and the scaffolded view _form.gsp contains a required="" attribute
<g:textField name="name" required="" value="${fooInstance?.name}"/>
You need to remove
required=""
resulting in
<g:textField name="name" value="${fooInstance?.name}"/>
so that the browser lets you enter an empty value.

How to show a single validation message for the whole JSF form?

I have a JSF form with number of fields. PrimeFaces normally does validation in this way:
http://www.primefaces.org/showcase-labs/ui/pprAjaxValidations.jsf
But I have more than 30 fields in my JSF form, so if I did this validation, it does not look good. How can I provide only a single message like "Please fill missing values" for any field if it is missing?
Your could render the message conditionally based on FacesContext#isValidationFailed().
<h:outputText value="Please fill out missing values" rendered="#{facesContext.validationFailed}" />
Note that this would only make sense if you have only the required="true" validation enabled and you thus don't use any converters or other more specific validators for which the enduser would of course like to see a more specific message.

Resources