Select Loader demo

Description
This page displays the SelectLoader mixin.
Notice the t:mixins associated to the t:targetId attribute.


In Action
Submitted country label :
Submitted city label :



TML Source code

		<t:form>
			<t:select t:id="country" t:mixins="exanpe/selectLoader" t:targetId="city"  
					  model="countryModel" value="countryValue" encoder="countryEncoder"/>
	
			<t:select t:id="city" model="cityModel" value="cityValue"/>
			
			<t:submit/>
		</t:form>
		
		Submitted country label : ${countryValue?.name}<br/>
		Submitted city label : ${cityValue?.name}<br/>
	



Java code

    @Inject
    private SelectModelFactory selectModelFactory;

    @Property
    private SelectModel countryModel;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private Country countryValue;

    @Property
    private SelectModel cityModel;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private City cityValue;

    @Inject
    private DataService dataService;

    @SetupRender
    public void ini()
    {
        // invoke my service to find all countries, e.g. in the database
        List<Country> countries = dataService.getCountryList();

        // create a SelectModel from my list of countries
        countryModel = selectModelFactory.create(countries, "name");

        // init cityModel
        loadCitySelect();
    }

    @OnEvent(value = ExanpeEventConstants.SELECTLOADER_EVENT)
    public SelectModel populateSelect(String value)
    {
        cityModel = selectModelFactory.create(dataService.getCitiesByCountry(value), "name");
        return cityModel;
    }

    private void loadCitySelect()
    {
        if (countryValue == null)
            cityModel = new SelectModelImpl(new OptionModelImpl[0]);
        else
            cityModel = populateSelect(countryValue.getId());
    }

    public ValueEncoder<Country> getCountryEncoder()
    {
        return new CountryEncoder(dataService);
    }