Acces by java to the value of a selection field

Hello
i test the access of a partner by a java Controller
i try to rewrite the generation of the full name in Partner

I try to concatenate firstName et Name but also the titleSelect
But the titleSelect is a selection field so i retrieve an integer (1 - 2 - 3 ) instead M. Me …

this is my code

public void computeFullName(ActionRequest request, ActionResponse response) {
Partner partner = request.getContext().asType(Partner.class);
String title ="";
title = partner.getTitleSelect();

Do you have a solution to retrieve not the value of the option but more the text

thaks for your help

Hi
Sadly, this is not possible with select, ADK has an enum type which is perfect for this use case but it is not used in ABS right now.

This should work

    String value = I18n.get(
    Beans.get(MetaSelectItemRepository.class) // You can @Inject it too
        .all()
        .filter(
            "self.select.name = ? AND self.value = ?",
            "partner.title.type.select",
            partner.getTitleSelect())
        .fetchOne().getTitle()
);
1 « J'aime »

Thanks beuss for your help

Bonsoir,

Il est également possible de récupérer la valeur en utilisant MetaStore:

import com.axelor.meta.MetaStore;
import com.axelor.meta.schema.views.Selection.Option;

Option item =
MetaStore.getSelectionItem(
“partner.title.type.select”,
partner.getTitleSelect().toString());

String value = I18n.get(item.getTitle())

L’avantage de cette approche est de prendre en compte les éventuelles surcharges d’une sélection en fonction des dépendances des modules.

Cordialement

Merci gdu-axelor pour ta réponse.
Cela me va parfaitement

Bien à toi