Java tutorial
/* * SurveyPanel * Copyright (C) 2009 Serge Tan Panza * All rights reserved. * License: GNU/GPL License v3 , see LICENSE.txt * SurveyPanel is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.txt for copyright notices and details. */ package com.surveypanel.web.admin; import org.apache.commons.lang.StringUtils; import org.apache.struts2.convention.annotation.Namespace; import org.katsuo.dao.QueryFilter; import org.katsuo.domain.Field; import com.opensymphony.xwork2.Preparable; import com.surveypanel.domain.Client; import com.surveypanel.domain.Survey; import com.surveypanel.domain.SurveyTemplate; @Namespace("/admin/template") public class TemplateAction extends BaseCrudAction<SurveyTemplate> implements Preparable { private static final long serialVersionUID = -8096153688118202180L; protected String name, source; protected Long id, surveyId, clientId; protected String clientName, surveyName; public void prepare() throws Exception { if (surveyId != null && clientId != null) { Client client = entityManager.load(Client.class, new Field("id", clientId)); if (client != null) { clientName = client.getOrganisation(); } else { addActionError(getText("error.client.notfound")); } Survey survey = entityManager.load(Survey.class, new Field("id", surveyId)); ; if (survey != null) { surveyName = survey.getName(); } else { addActionError(getText("error.survey.notfound")); } } } @Override protected SurveyTemplate bind() { SurveyTemplate template = new SurveyTemplate(); template.setSource(StringUtils.trim(source)); template.setName(StringUtils.trim(name)); template.setId(id == null ? 0 : id); template.setSurveyId(surveyId); return template; } @Override protected void bind(SurveyTemplate template) { source = template.getSource(); name = template.getName(); surveyId = template.getSurveyId(); id = template.getId(); } @Override protected Field[] getPks() { return new Field[] { new Field("id", id) }; } @Override protected QueryFilter getSearchFilter() { QueryFilter paginationFilter = new QueryFilter(); paginationFilter.set("surveyId", surveyId); return paginationFilter; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSource() { return source; } public void setSource(String source) { this.source = source; } public Long getSurveyId() { return surveyId; } public void setSurveyId(Long surveyId) { this.surveyId = surveyId; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getClientName() { return clientName; } public String getSurveyName() { return surveyName; } public String getModelName() { return "template"; } public Long getClientId() { return clientId; } public void setClientId(Long clientId) { this.clientId = clientId; } @Override protected Field[] getFieldsToUpdate() { return new Field[] { new Field("name", name), new Field("source", source) }; } }