Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.faces.application.FacesMessage;
- import javax.faces.component.UIComponent;
- import javax.faces.context.FacesContext;
- import javax.faces.convert.Converter;
- import javax.faces.convert.ConverterException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import com.jedlab.framework.spring.SpringUtil;
- import com.webportal.app.domain.TagEntity;
- import com.webportal.app.service.TagService;
- /**
- * @author Omid Pourhadi
- *
- */
- @Component("tagConverter")
- public class TagConverter implements Converter
- {
- @Autowired
- TagService tagService;
- @Override
- public Object getAsObject(FacesContext context, UIComponent component, String value)
- {
- if (value == null || value.trim().equals("") || value.equals(SpringUtil.getMessage("Please_Select", null)))
- {
- return null;
- }
- else
- {
- try
- {
- Long tagId = Long.valueOf(value);
- return tagService.findById(TagEntity.class, tagId);
- }
- catch (NumberFormatException exception)
- {
- throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid Group"));
- }
- }
- }
- @Override
- public String getAsString(FacesContext context, UIComponent component, Object value)
- {
- if (value instanceof TagEntity)
- {
- Long id = ((TagEntity) value).getId();
- if (id == null)
- return null;
- else
- {
- return id.toString();
- }
- }
- else
- {
- if(value != null)
- return String.valueOf(value);
- return null;
- }
- }
- }
Add Comment
Please, Sign In to add comment