All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.imunity.vaadin.endpoint.common.plugins.attributes.components.SingleStringFieldBinder Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */
package io.imunity.vaadin.endpoint.common.plugins.attributes.components;

import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.data.binder.Binder;
import io.imunity.vaadin.elements.StringBindingValue;
import pl.edu.icm.unity.base.message.MessageSource;

import java.util.function.Supplier;


public class SingleStringFieldBinder extends Binder
{
	private final MessageSource msg;

	public SingleStringFieldBinder(MessageSource msg)
	{
		super(StringBindingValue.class);
		this.msg = msg;
	}
	
	public BindingBuilder forField(HasValue field, boolean required)
	{
		BindingBuilder bindingBuilder = forField(field);
		if (required)
			bindingBuilder.asRequired(msg.getMessage("fieldRequired"));
		return bindingBuilder;
	}

	public  void ensureValidityCatched(Supplier errorProvider) throws T
	{
		if (!isValid())
		{	
			validate();
			throw errorProvider.get();
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy