Provide custom Validator for #Size - java-ee-6

How could I provide a custom validator implementation for a built-in constraint like #Size? in a JavaEE6 JSF Web Application

Implement a ConstraintValidator<MyType, Size>, register it via an XML based constraint mapping:
<constraint-mappings
xmlns="http://jboss.org/xml/ns/javax/validation/mapping" version="1.1">
<constraint-definition annotation="javax.validation.constraints.Size">
<validated-by include-existing-validators="false">
<value>org.mycompany.MySizeValidator</value>
</validated-by>
</constraint-definition>
</constraint-mappings>
and add this mapping to META-INF/validation.xml:
<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration" version="1.1">
<constraint-mapping>path/to/mapping.xml</constraint-mapping>
</validation-config>
You can learn more in the Hibernate Validator reference guide.

Related

How to display a simple wicket message with one simple parameter with StringResourceModel

I have one Wicket text property in the WicketApplicationProperties.properies
<entry key="dataMniejszaNizMinimalna">Wybrano datę, która jest mniejsza niż minimalna akceptowalna data '${minimalnaData}'. Nie można zapisać danych."</entry>
How to substitute a parameter {minimalnaData} with a use of a class
StringResourceModel. I don't want to create any models i want to just display a message with provided one attribute. The Wicket StringResourceModel is so complicated.
new StringResourceModel(resourceKey).setParameters(params)
how to provide this one parameter is a simplest way.
The simplest way could be:
new StringResourceModel(resourceKey, this, Model.ofMap(Map.of("minimalnaData", "some value")))
The model object could be a Java Bean or a java.util.Map.
StringResourceModel also supports java.text.MessageFormat. You can use its #setParameters() method to pass an array of values for the placeholders.
I think wicket:message should fit your need. Take a look at the wiki:
https://cwiki.apache.org/confluence/display/WICKET/Wicket%27s+XHTML+tags
You can nest components within textual content.

How to add field to custom view of SugarCRM 7

I have same problem as of How to add standard field to custom layout of SugarCRM 7
I have created a custom view(followed these steps http://www.insightful.com.au/sugarcrm-how-do-i/creating-custom-button-sugar-7) in SugarCRM7 but not getting how should I add standard fields to this layout
I am new to SugarCRM7 and seeking for help :(
You can use metadata to provide the list of fields and then use the {{field}} Handlebars helper in your template to insert them into your HTML.
To see examples of how to use field helper see dashablelist.hbs or preview.hbs in Sugar 7.5.

How to write custom XML tag parsers in STS?

I want to extend the STS to support my own custom XML tags by write a custom eclipse plugin.
For ex:
...
<bean id="demoBean" class="demo.JavaBean"/>
<myrpc:service interface="demo.MyService" ref="demoBean" />
...
myrpc:service means it will pulish the "demoBean" as a rpc service of interface "demo.MyService"
And now the SpringExplorer can list the "demoBean" as a node, but cannot recoginze the myrpc:service.
I want extend the STS to support these things.
Which extension point should be contributed?
How to do this?

Seam file component in javaee6

I'm trying to replicate the loading of a property file of seam in javaee6 but still don't know where to start.
In seam we can load a property file as a seam component by defining it in the components.xml:
<component name="propertyBean" class="PropertyBean" scope="application" auto-create="true" startup="true">
<property name="filename">myPropertyFile.properties</property>
<property name="reload">true</property>
</component>
And then we can access it in code:
PropertyBean.getInstance().getProperty("myProperty");
Is there a javaee6 feature that will replicate this functionality? Or in spring it's called PropertyPlaceholder.
In c#, we can do it by adding configuration property in appsettings.xml. And access via ConfigurationManager.
Thanks,
czetsuya
Unfortunately, there's nothing like a property component manager from seam into javaee6, but I was able to find something similar, a property loader.
It works by having a qualifier:
#Qualifier
#Retention(RUNTIME)
#Target({METHOD, FIELD, PARAMETER, TYPE})
public #interface ConfiguredBy {
#Nonbinding public String value();
}
With a parameter that serves as the name of the property file.
The whole approach is describe here:
http://john-ament.blogspot.com/2010/03/writing-property-loader-in-java-ee-6.html

Using custom javax validation annotations in GWT

For the current project we're using JSR-303 annotations to validate our interface parameters.
I needed to create a custom annotation for dates, as the default #Past and #Before also take into account the time.
This is the definition of my annotation:
#Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
#Retention(RUNTIME)
#Documented
#Constraint(validatedBy = { NotInFutureValidator.class })
/**
* Annotated element must be a date before tomorrow, compared to the system's date
*/
public #interface NotInFuture {
String message() default "{be.credoc.contractRegistration.interface_v2.validation.pastignoretime}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
The implementation of the validator is pretty straight forward.
Our webapplication is written in GWT and it makes use of gwt-validation. This allows us to validate our parameters on client side by means of the same annotations.
However, when I annotate my parameters with my custom annotation and I want to validate it by making use of the GwtValidatorFactory, it doesn't give me an error when the input date is in the future.
Does anyone have experiencing defining and using their own annotations in a GWT application and can see what I'm missing?
Thanks in advance
Instead of creating new annotations you might try to re-define the validators for the existing #Past and #Future annotations by providing an XML constraint mapping like this:
<?xml version="1.0" ?>
<constraint-mappings
xmlns="http://jboss.org/xml/ns/javax/validation/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd">
<constraint-definition annotation="javax.validation.constraints.Past">
<validated-by include-existing-validators="false">
<value>x.y.z.NotInFutureValidator</value>
</validated-by>
</constraint-definition>
</constraint-mappings>
This mapping must be registered in the configuration file META-INF/validation.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd">
<constraint-mapping>META-INF/validation/custom-constraints.xml</constraint-mapping>
</validation-config>
You can learn more about custom validators for existing constraints in the Bean Validation specification and the Hibernate Validator reference guide.
Apparently we wrote our own JavaScript implementations for each custom annotation, so the solution in this case was to write such an implementation.