More explanation needed for initializationmapping

4 posts / 0 new
Last post
Marc
Offline
Joined: 07/08/2009
More explanation needed for initializationmapping

Hello,

I refer to the reference guide mentioning  initializationmapping on page 72. I tried to build a somewhat different example, but without success.

My entity "Proposal" refers to the entity "Product" that contains a field "productSate". I want to initialize the "productState" field in my search with a constant value ,namely "active". I tried the XML below:

<bean id="Product"......

......

<list>

......

<bean class="org.jspresso.framework.model.descriptor.basic.BasicReferencePropertyDescriptor">
<property name="name" value="product" />
<property name="referencedDescriptor" ref="Product" />
<property name="mandatory" value="true" />
<property name="initializationMapping">
 <map>
  <entry key="productState" value="active" />
 </map>
</property>
</bean>

......

Of course I imagine I have to specify something different because "active" is a constant value. Also I am not sure about the key attribute "productState", that is the name of a field within Product.

 

Any more explanation on initializationmapping?

Thanks,

Marc

atao
Offline
Joined: 10/15/2008
More explanation needed for initializationmapping

Marc,

In a initializationMapping, key and value are names of entity attributes, respectively detail's one and master's one: the detail list will be filled with any entity with its atttibute having the same value as the specified master attribute.

There is no way to specify a constant as map's value.

 

Regards

Pierre

vvandens
Offline
Joined: 05/29/2008
More explanation needed for initializationmapping

Hi Marc,

Pierre is right. But our use case definitely makes sense, specially for enumeration properties. Could you raise a feature request so that we can keep track of it ? We could also have some syntax dynamically adding constraints on the LOV query (e.g. "${weight} < ${master.maxAllowedWeight}") but that's another story...

To be complete, and for the current framework state, you could also raise an error massage to the user whenever he chooses a product whose state is not "active" using a property pre-processor on the proposal product property. But I agree, it is not as user-friendly as pre-filtering the LOV.

Another option might be to have the proposal entity to provide an allowedProductState derived property returning "active" and build your product property initialization mapping with productState <-> allowedProductState. But yhis time, it is less coder-friendly...

 

HTH,

Vincent

vvandens
Offline
Joined: 05/29/2008
More explanation needed for initializationmapping

I've just published a new snapshot for 3.0.1 that handles constant values for LOV initialization mapping. Note that the signature has been changed to return Map<String, Object> instead of Map<String, String>. This won't change anything for the Spring config files though.

Whenever the value of the mapping is a string, Jspresso tries to resolve it as a property name on the owning entity. If this is not a valid property name, then it treats it as a constant value.

Whenever the value of the mapping is not a string, then it is handled as a constant value.

 

Regards,

Vincent