Using Spring:bind to set value to java object - spring

I am using spring's bind tld to map a textbox to the java model object's property. When no value is entered in the text box and submit action is done, what value will be set in the model property? property is declared as type String. I am not setting any default value to the text box. Is empty value set or "" is set?

Submitted form values which are of type String are by default submitted as "".
You can register Spring's StringTrimmerEditor to ensure that empty values are converted to null if you like.

Related

How can I make .net core web api model validation return all validation errors including required field and numeric errors?

My client is asking if all validation errors can be displayed at once.
String properties are marked with [JsonRequired]. If more than one string property is set to null in the request, validation error messages are returned in the response for each of the null properties. I have a few non-nullable decimal properties, also marked with [JsonRequired]. If decimal (or any numeric, primitive, etc.) properties are set to null in the request, obviously a conversion error is returned.
The JSON value could not be converted to System.Decimal.
However, the required property errors from earlier aren't displayed anymore.
What I have tried is setting the type to decimal? and implementing IValidatableObject on my model class. Then I can check if the value is null and return a ValidationResult with the error description. Then I have the same issue here because the validation "stops" at the decimal? property.

Optional Input parameters in CRM action always NULL in Code Activity even if not passed?

If I ommit an optional input parameter in a CRM action call, will this parameter always be null in the Code Activity?
We have a customer which calls a particular CRM action, lets say an update action. The customer wants to be able to pass input parameters as null if the value in the corresponding field in dynamics must be deleted.
the problem i an facing now is that I cannot detect wether the input variable was effectively passed like "parameter_1 = null" or if the parameter itself was not even passed in the action call. the issue is that I cannot delete the value in crm if the input parameter was just not passed. only if the parameter was passed with the value null, I am allowed to delete the field value in crm.
Am I correct assuming that the value of a optional action input parameter is also null if the parameter is not passed at all?
Is there maybe a workaround which enables me to detect wether the value of the input parameter was passed as null instead of beeing ommitted?
something like "undefined" or similar?
You are correct. Input parameters are always present in the IPluginExecutionContext.InputParameters collection passed to the plugin handling your action.
You would need an extra "MyParameterNameSpecified" so to speak to signal if the parameter null value was actually passed.
Another option could be to use a string parameter holding the value passed in JSON-serialized form.

Get value of editbox of type date/time

I try to get the value of an editbox of type Date/Time. If I test it with
getComponent("dateField").value
or
getComponent("dateField").getSubmittedValue();
and print the output to the console. It always returns "null" if the field is empty or
the field does not contain a valide date. Because of this I can't differ between invalide input and empty input.
Is there a way to get the information if the field is empty?
It depends on the refresh phase you're testing.
getValue() will always return blank, because only content that can be converted to the underlying data type will be passed to it. Even if you disable validation, converter checks still run, because serious errors will occur if you try to put "this is not a date" into a Date/Time.
getSubmittedValue() will always be null if you're checking in Invoke Application or Render Response phases. That's because during the Update Model Values phase, the submittedValue property is passed to the value property and the submittedValue property nulled.
If you're checking in a validator, the text value entered by the user has not yet been checked against validation rules (validation) or that it can be converted to the right data type (conversion), so getValue() will return the value stored last time round and getSubmittedValue() will give the string value (e.g. "this is not a date").
So the answer is you should be able tell whether the field is empty in a validator, but bear in mind custom validators only run if you also have a required validator.

Struts 1 Textbox to integer validation

In struts 1 if you try to bind a html:text field directly to an integer in the ActionForm then there isn't a chance to validate it correctly when the user enters a non-numberic value.
If the user enters a non-numberic value, then the integer value is always parsed as 0 before it reaches the validate method.
Is there any way supported way that struts provides to handle this situation? Or do I need to always bind to a String first and then parse into an integer later on?
If I am not mistaken, any thing that comes from the UI is a string, even though you have the variable defined as an integer in your form.
So my suggestion would be to declare the variable as string and parse it according to your need.

Spring MVC: Set property to null when bind fails

Is it possible to configure Spring to set the target property to null when binding fails?
For example, my bean has a date property which can have a pre-existing value when the form is displayed. If the user enters an invalid date, I want the property to be set to null; currently it retains its previous value.
I still want the binding error of course, so I can display an error message.
I'm hoping there's a general configuration solution for this (ie. I don't want to just write code to deal with each field manually!).
Background: Retaining the old value causes odd behaviour in subsequent custom cross-field validation. Setting the property values to null would tell this validation not to execute.

Resources