I have ValidationMessages_en_US.properties as below
requiredFirstName=First name is required
requiredLastName=Last name is required
requiredEmailAddress=Email Address is required
...
...
What I would like to do is parameterize the field name in this. So something like this
requiredField={field} is required
So that there will be only one message and I can pass in the field name. I am using this in bean validations in the jsf environment.
This is where I want to use the values:
public class SomeBean implements Serializable
{
#NotNull(message="{requiredFirstName}" )
private String firstName;
......
.....
Is there a way to do this?
Thanks
There is no way to achieve this with the current Bean Validation specification or reference implementation (Hibernate Validator). You can interpolate the validated value and the constraint parameters and with Validator 5.1 you will also be able to add custom variables via HibernateConstraintValidatorContext (see also https://hibernate.atlassian.net/browse/HV-701). However, that does not help you yet to identify your fields and set the right 'field' value.
Related
We have used cloud SDK(odata-generator-maven-plugin) and generated the VDM out of our EDMX(defined in xml) file. Now, want to refer some of the fields from VDM as a constant in our POJO class instead of re-defining as a constant in our class . I don’t find EDMX field/odataName declared as a variable with public specifier and the constant as well in VDM generated classes.
In the below example,
For example :
VDM snippet - ItemCDSViewForLineItem.java
#ODataField(odataName = "DraftUUID")
private UUID key_2;
public final static ItemCDSViewForLineItemField<UUID> KEY_2 = new ItemCDSViewForLineItemField <UUID>("DraftUUID");
Edmx snippet:
`<Property Name="DraftUUID" Type="Edm.Guid" sap:label="Key"/>`
Is there any way by which I can access or refer “DraftUUID” as a constant field in our own POJO class and reuse it ? Could you please suggest ?
Thanks
Surendra
You need to add Lombok as a dependency to your project to see the public Getters and Setters for these fields. More information can be obtained from the documentation.
To also see them in your IDE you probably need to have a plugin installed as described here.
The method EntityField#getFieldName should give you what you are looking for:
ItemCDSViewForLineItem.KEY_2.getFieldName() // returns "DraftUUID"
In the JdbcPollingChannelAdapter, I think I understand how to use the createParameterSourceNoCache() method of the ExpressionEvaluatingSqlParameterSourceFactory class in order to get a non-caching SqlParameterSource object that can be applied to the JdbcPollingChannelAdapter's select parameters via its setSelectSqlParameterSource() method.
However, when it comes to update parameters, I only see it possible to set the update parameters via a SqlParameterSourceFactory through the setUpdateSqlParameterSourceFactory() method. From what I can tell, it is not possible to set the factory to be non-caching, only to call the non-caching create method of the factory to get a non-caching source object.
I need the update parameter to be the result of a dynamically calculated custom date that changes over time. I have a static method to dynamically calculate the result, and I was hoping I could use SpEL on the JdbcPollingChannelAdapter to evaluate the update parameter dynamically in the same way that the select parameter can do. Is this possible?
You can extend it and still inject it regular way into the JdbcPollingChannelAdapter:
public class NoCacheExpressionEvaluatingSqlParameterSourceFactory
extends ExpressionEvaluatingSqlParameterSourceFactory {
#Override
public SqlParameterSource createParameterSource(Object input) {
return createParameterSourceNoCache(input);
}
}
I have autowired a class as #Autowired(required=true) private CookieDao ewp;
I am trying to use the ewp to call a function ewp.getCookieEntry(id, name );
How do I access the contents of ewp. Since it is a object I get classname#hashcode but after .toString() , I just get the classname.
If ewp is autowired, then is it the same as CookieDao ewp = new CookieDao();? If not, then what is it called and how can I extract it's values?
I believe that you need to annotate your CookieDao with #Repository to the autowired work just fine, for more information have a looks into this answer : Understanding Spring #Autowired usage
There seems be some things missing in the Spring-LDAP ODM annotations. This is a question by way of a feature request, if there is a better way to contribute such requests, please say so.
I'd like to mark an #Attribute as read-only, so it will populate the bean from LDAP for reference, but not persist it back to ldap. I'd suggest adding an attribute read-only to #Attribute, defaulting to false, for the usual case. The default attributes of * misses all the operational attributes, some of which are very useful, and transfers more data than is required, slowing down the ldap query with attributes which will never be used.
An example of this; it would be very useful, for literally read only, such as entryUUID, etag, etc., which you cannot use if you wish to persist only some fields back to ldap, as the bean fails to persist to ldap with an exception when you save the bean. But also would be usefule for general fields which you want to structurally prevent the user from ever updating.
You can get around this by not annotating read-only fields, and then manually populating the read only fields with a separate call. Very messy and kills the query speed.
Also on a related topic, query() coudl have a default list of attributes, which you have already annotated in your classes, something like :
public static String[] getBeanAttributes(Class<?> beanClass) {
ArrayList<String> attrsObj = new ArrayList<>();
for (Field field : beanClass.getDeclaredFields()) {
if (field.isAnnotationPresent(Attribute.class)) {
Attribute attr = field.getAnnotation(Attribute.class);
attrsObj.add(attr.name());
}
}
String[] attrs = attrsObj.toArray(new String[attrsObj.size()]);
return attrs;
}
Above just returns a simple String[] of your declared attributes, to pass to query.attributes() - now i realize that as a static member, query() is built before the bean class is known, but at least there could be a helper function like the above, or a method signature for query attributes() that took a bean Class signature as an argument.
I created LDAP-312 on Jira. Thanks.
I have a class marked as CollectionDataContract which has a enum member. When I place an object of this class in Appfabric, I am through. When I get it back from App fabric, it does not deserialize the enum member. But I am not sure if the enum has been missed out in Serialization part itself.
Please do help.
If you need more information let me know.
Thanks.
[CollectionDataContract]
public partial class RuleConditionList : List<IRuleCondition>, IRuleCondition
{
public LogicalOperator Operator;
}
where LogicalOperator is an enum
I think there is a problem when serializing/deserializing your object. AppFabric uses the NetDataContractSerializer class for serialization before storing the items in the cache.
You can use the NetDataContractSerializer on any type which are marked with the DataContractAttribute or SerializableAttribute, or types that implement the ISerializable interface.
So depending and your object, there should be something wrong like a private type, a private field, a missing attibute, ...
Edit
You should add DataMember to your field.
[DataMember]
public LogicalOperator Operator;
Any data member in a class marked with Collection data contract cannot be serialized by NetdataContractSerializer which is the serailization technique used by App fabric for storing data.
To make things work we have two options:
Make a wrapper for RuleConditionList
Instead of Inheriting from List, make it as a property and change the attribute as DataContract.