/*
* This file was automatically generated by MD4J.
*
* Licensed under the GNU General Public License, Version 2.0 (the "License") or above;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* *http://www.gnu.org/licenses/gpl.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package gr.abiss.md4j.sampledomain.web;
import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.text.SimpleDateFormat;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.upload.MultipartRequestHandler;
import org.apache.struts.action.Action;
import gr.abiss.md4j.dao.Page;
import gr.abiss.md4j.util.StringUtil;
import gr.abiss.md4j.sampledomain.web.CityCrudForm;
import gr.abiss.md4j.sampledomain.business.CityManagerLocal;
import gr.abiss.md4j.sampledomain.business.CityManagerUtil;
/**
* @struts.action path="/City/LoadUpdate"
* name="CityCrudForm"
* input="/global/error.jsp"
* scope="request"
* validate="false"
*
* @struts.action-forward path="/City/Update.jsp"
* name="CityLoadUpdateActionView"
*
*/
public class CityLoadUpdateAction extends Action{
private static Logger log = Logger.getLogger(CityLoadUpdateAction.class);
/**
* A static, unmodifiable Set holding the projection properties.
* If you want these created at runtime in each execute method call,
* simply set md4j:use-instance-projections to true.
*/
private static Set projectionProps = new HashSet();
static{
projectionProps.add("id");
projectionProps.add("name");
projectionProps.add("region");
projectionProps.add("population");
projectionProps.add("country.id");
projectionProps.add("country.id");
projectionProps = java.util.Collections.unmodifiableSet(projectionProps);
}
/**
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {
String fwd = "error";
try{
CityCrudForm form = (CityCrudForm) actionForm;
Serializable identifier = form.getId();
if(identifier != null){
// if we got here we will need a Session bean
CityManagerLocal manager = CityManagerUtil.getLocalHome().create();
if(this.isTokenValid(request)){
// if the token is valid the form already has user-entered data so
// we only want data to populate the drop down elements etc in the view
Map map = manager.getParentOptions();
// populate form bean option data for drop downs
form.setParentSelectOptions(map);
}
else{
// otherwise, we need to load data for both the entity the user wishes to update
// and for for the view's select options etc
Map map = manager.getWithOptions(identifier, CityLoadUpdateAction.projectionProps);
// populate form bean from map
form.copyProperties(map);
// populate form bean option data for drop downs
form.setParentSelectOptions(map);
}
request.setAttribute("CityCrudForm", form);
}
// save a token to signal results need to be rendered next time
this.saveToken(request);
fwd = "CityLoadUpdateActionView";
} catch (Exception e) {
// reset the token to avoid causing trouble
this.resetToken(request);
log.error("Failed to perform search operation, wrapping to RuntimeException", e);
throw new RuntimeException(e);
}
return mapping.findForward(fwd);
}
}