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 :

Person.java Entity

class Person  {
@Composition
@OneToMany(mappedBy="Person")
private List<> badHabit; 

@Composition
@OneToMany(mappedBy="Person")
 private List<> goodHabit;
}

BadHabit.java Entity

class BadHabit{
@ManyToOne
@JoinColumn(name="fk_term_id")
protected HabitTerm habitTerm;

@ManyToOne
@JoinColumn(name="fk_person_id")
protected Person person;
}

Habit.java Entity

class Habit{

@Column(name="term_name")
protected String termName;

@Column(name="term_id")
protected String termId;
}

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

PersonEdit.xml

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

<collectionDatasource id="habitDs" class="com.example.entity.Habit" 
datasourceClass="com.example.web.HabitDataSource"/>
</dsContext>

<layout>

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

</layout>

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.

Thanks,
S

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.

Regards,
Daniil

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?

Thanks,
S

Unfortunately no, it’s not possible