Tokenlist - Is there a way to use a different entity for lookup optionsDatasource as compare to tokenList datasource

Hi Guys,
Heres is the scenario, i have following tentative entities : Entity

class Person  {
private List<> badHabit; 

 private List<> goodHabit;
} Entity

class BadHabit{
protected HabitTerm habitTerm;

protected Person person;
} Entity

class Habit{

protected String termName;

protected String termId;

I am trying to load entity datasource Person and option datasource Habit using following :`


<datasource id="personDs" class="com.example.entity.Person" view="person-view">
  <datasource id="badHabitDs" property="badHabit"/>
  <datasource id="goodHabitDs" property="goodHabit"/>

<collectionDatasource id="habitDs" class="com.example.entity.Habit" 


<tokenList id="goodHabitTokenList" property="goodHabit" datasource="goodHabitDs">
<lookup optionsDatasource="habitDs" />


In the above situation the entity that is begin used inside optionDatasource is different then the one which is declared inside datasource attribute of tokenlist. With this apporach i am getting type cast error.
Is there any better and more effective solution for this use case.

Note : i have tried using KeyValue Entity but stuck with the same error.


Hello @desaurabh

You’re using TokenList wrong:

  • use only datasource attribute to specify CollectionDatasource to be bound with component (badHabitDs or goodHabitDs in your case)
  • use dataContainer and property attributes to specify Instance container and collection property to be bound with component.


Hi @tsarev,
Thanks for taking out time and responding to this query.

I understand the expected functionality of tokenList does not meant to facilitate this operation(that i am trying to achieve in the above example).

However, Please do consider below scenario :

Lets say if one wanted to avoid using multiple optionsDatasources for multiple distinct token lists. For instance, if there is a situation when you have a single entity that will be utilized for optionDatasource inside every tokenList but those tokeLists will have a different property as oppose to the entity of optionDatasource.

Is it possible to change or say cast the selected entity from optionDatasource before adding it to to the collection of tokenList?


Unfortunately no, it’s not possible