vaadin error indicator and message - vaadin

I want to make custom message in error indicator using Vaadin, like here: http://vaadin.com/download/book-of-vaadin/vaadin-7/html/img/application/errorindicator-example2.png
My application is multilingual and i want to have different message for the same error depending of chosen language. Is it possible to have different error messages for one error indicator? And if it's possible how to do it?

Using java.util.ResourceBundle will help your i18n issues. Each time when Locale is changed, you need to update your bundle as well. For example;
bundle = ResourceBundle.getBundle("messages", locale);
In order to retrieve error representation from bundle, you can use bundle.getString("error.message")
By doing this, you don't need to update code each time when locale is changed. Only the resource location where the representation strings is switched. For more information, http://docs.oracle.com/javase/tutorial/i18n/resbundle/prepare.html

Remember to add this code to your component:
myComponent.setConversionError("{1}");
This line of code sets your custom message to the error indicator. Otherwise you'll get this message:
Could not convert to {0}
where {0} is the name of your Converter's PRESENTATION class.
Infact this is the javadoc of the AbstractField.setConversionError(java.lang.String valueConversionError) API-method:
Sets the error that is shown if the field value cannot be converted to the data source type. If {0} is present in the message, it will be replaced by the simple name of the data source type. If {1} is present in the message, it will be replaced by the ConversionException message.

Related

BigDecimalField validation bug

BigDecimalField has a nice feature: it allows only digits, "+" and "-" signs, and a decimal separator defined by the current locale ("." or ","). It works fine until someone tries to enter a combination that is not a number or cannot be directly converted to the java BigDecimal type (e.g "123...45.6+++7-89--").
For sach combinations, the validation passes without any warning, and the background business object gets a null value.
Field is in the dialog and every time before opening the dialog there is a call to Binder.readBean() method (in order to set the appropriate data for editing), on "save" button in dialog I call Binder.writeBean(). Problem is that the next time I open the dialog, the problematic BigDecimalField still contains an invalid number entered,
actually Binder.readBean() stops working for that field.
There is a similar bug with IntegerField which I noticed: IntegerField validation bug.
How can I validate BigDecimalField and avoid this bug? How do i get the BigDecimalField to work again and not keep showing invalid data? Is there a elegant way to catch the NumberFormatException that probably occurs somewhere inside the vaadin api, and proces it i.e. warn the user that he has to enter a valid decimal number. Is there a way to do it via Binder?
I am using Vaadin 23.3.0
Checking format error is not yet by default on. You need to enable it by setting enforceFieldValidation=true in feature flags in src/main/resources/vaadin-featureflags.properties file.
com.vaadin.experimental.enforceFieldValidation=true
See more at: https://github.com/vaadin/platform/issues/3066

cumulocity mqtt measurement

I am pretty new to Cumulocity and I am trying to get data into the platform from my own device using mqtt and the smartrest templates. I can get data in using the static templates but they only support certain data types. I am struggling to create the appropriate smartrest template in the UI and the documentation doesn't go into much detail.
I get that the template name goes in the MQTT topic (or selected on login as part of the username) in s/ut/template_name and the messageId of the messages in the template get matched to the first CSV field of the MQTT publish payload. What I don't get is the template terminology. In the UI I choose API->Measurement and Method->POST and I am presented with required values $.type and $.time. My questions:
Is $.type the "measurement fragment type" name or do I have to make it "c8y_CustomMeasurement"? Can I call it whatever I want?
$.time has a value field. Is this the default value if one is not supplied in the publish?
I assume I need to add a numerical value in the optional API values. To link it to the value of the data point should I make the key "c8y_CustomMeasurement.custom.value"?
Am I way off base here?
Every time I publish to my own smartrest template the server drops the connection so I assume its an error in my template setup but I don't see a way of accessing debug messages (also nothing is published back to me on s/e or s/dt).
For the sake of an example, lets say I wish to publish a unitless, timestamped pulse count with payload format "mId,ts,value" with example data "p01,'2017-07-17 12:34:00',1234"
What you wrote so far is mostly correct just to be a bit more precise:
The topic is s/uc/template_id (not the template name, this is just a label)
The $.type refers to the 'type' fragment in the measurement JSON. It is a free text field
In 99% of cases you want to leave the $.time empty. If you set something here it is not the default but fixed to that timestamp and you cannot change it when using the template. If you leave it empty and still not send something in
Example: p01,2017-07-17T12:34:00,1234 (no quotes arounf timestamp and ISO8601 format
Example without sending time: p01,,1234 (sending empty string as time results in server time beeing set. The template is the same)
Hope these points help you to find you issue

Quickfixj not honoring custom fields in a repeating group

I am using FIXT1.1 and FIX Application version 5.0SP2.
I added some custom fields to the QuotSetAckGrp, part of MassQuoteAcknowledgement message. However, when quickfix reads the repeating group, it does not read the custom fields as part of the repeating groups. Instead, it treats the custom fields are regular parent-level fields and throws a "Tag appears more than once" session level reject.
Appreciate any inputs to help resolve the issue.
You need to modify the receiver's AppDataDictionary to match the messages that your sender is sending. Also, you need to set UseDataDictionary=Y in your config.
QF/j needs to look at the DD xml file to know what fields are in a repeating group, else it cannot know where each group member ends.
When the engine encounters a field that isn't inside the DD's repeating group definition, it assumes that the current group member ended with the previous tag.
Here's a howto for customizing your DD:
http://quickfixn.org/tutorial/custom-fields-groups-and-messages
(The above link is for QF/n, but it's nearly the same for QF/j.)
See the QuickFIX/J User FAQ, topic "I altered my data dictionary. Should I regenerate/rebuild QF/J?".
OUTGOING MSGS: The DD xml file is irrelevant when you construct
outgoing messages. You can pretty much add whatever fields you want to
messages using the generic field setters (setString, setInt, etc) and
QF will let you. The only trouble is with repeating groups. QF will
write repeating group element ordering according to the DD that was
used for code generation. If you altered any groups that are part of
outgoing messages, you DEFINITELY need to rebuild.
To rebuild QuickFIX/J to accept your custom data dictionary, please refer to the answer I gave in the following StackOverflow post.
HTH.

Modifying error messages for Command Objects embedded in controller

I am trying to modify the messages.properties file for form input validated by a Command Object that is in specified in the controller. The output I get from the standard error message (that I modified slightly to assure I was hitting that specific one) is:
email cannot be empty test class com.dashboard.RegisterController$DashboardUserRegistrationCommand
but no variant of com.dashboard.RegisterController$DashboardUserRegistrationCommand.null.message
works
I am wondering what the correct specification should be.
Try to put DashboardUserRegistrationCommand outside (below) of RegisterController but still in the same file. Then com.dashboard.DashboardUserRegistrationCommand.. should work.
i.e. com.dashboard.DashboardUserRegistrationCommand.message.nullable
The typical layout of error messages is:
${packageName}.${className}.${propertyName}.${errorCode}
So for your example it would be:
com.dashboard.DashboardUserRegistrationCommand.message.nullable
In the Grails Reference on the right hand side there is a header titled 'Constraints'. On each page of the specific constraints listed under that header the ${errorCode} value is listed at the bottom of the page.
And sometimes you have to restart a run-app to get new messages to populate in a Grails project.
Just to help others in the future, I had the same issues and my problem was the way I was defining my key, I use now:
For default messages:
default.null.message=Write a value for {0}
For commmand error messages:
my.package.UserCommand.name.nullable=Please tell us your name
It is strange that sometimes you use nullable and sometimes you use null. The best thing is going to the Grails Constraints directly and check how is it done for example:
http://grails.org/doc/latest/ref/Constraints/nullable.html

Omit attribute name from validation error message (at start of it)?

I write code in English but I'm currently doing a site which is fully translated to another language (validation error messages included). However, I have a problem because validation error messages always seem to include the name of the attribute the error is on at the start of the error, e.g.:
Title Prosimo izpolnite naziv fakultete.
I want to get rid of the Title at the start, like so:
Prosimo izpolnite naziv fakultete.
Any help is appreciated. I would rather see if this can be solved without installing any 3rd party plugins.
If it's possible to provide translations for attribute names, that would be a cool solution too, but I would still like to know how it can be done both ways (omit or translate).
There is no need to use the error_messages_for helper for errors, you can write your own helper using the record's errors attribute.
You can just iterate over the error objects and display their messages.

Resources