Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.astamuse.asta4d.sample.handler.form;
 
 import java.util.List;
 
    public CascadeEditHandler() {
        super(CascadeForm.class"/templates/form/cascade/");
    }
    public String handle(ExtraInfo extrathrows Exception {
        saveExtraDataToContext(extra);
        return super.handle();
    }
    @Override
    protected boolean treatCompleteStepAsExit() {
        return true;
    }
    @Override
    protected CascadeForm createInitForm() {
        ExtraInfo extra = getExtraDataFromContext();
        PersonForm pform = null;
        JobForm[] jforms = null;
        switch (extra.action) {
        case "add":
            pform = new PersonForm();
            jforms = new JobForm[0];
            break;
        case "edit":
            pform = PersonForm.buildFromPerson(PersonDbManager.instance().find(extra.id));
            List<JobExperencejobs = JobExperenceDbManager.instance().find("personId"pform.getId());
            List<JobFormjobFormList = ListConvertUtil.transform(jobsnew RowConvertor<JobExperenceJobForm>() {
                @Override
                public JobForm convert(int rowIndexJobExperence job) {
                    return JobForm.buildFromJob(job);
                }
            });
            jforms = jobFormList.toArray(new JobForm[jobFormList.size()]);
            break;
        }
        pform.setAction(extra.action);
        CascadeForm cf = new CascadeForm();
        cf.setPersonForm(pform);
        cf.setJobForms(jforms);
        cf.setJobLength(jforms.length);
        return cf;
    }
    @Override
    protected void updateForm(CascadeForm form) {
        PersonForm pform = form.getPersonForm();
        JobForm[] jobs = form.getJobForms();
        switch (pform.getAction()) {
        case "add":
            PersonDbManager.instance().add(pform);
            for (JobForm job : jobs) {
                job.setPersonId(pform.getId());
                JobExperenceDbManager.instance().add(job);
            }
            DefaultMessageRenderingHelper.getConfiguredInstance().info("data inserted");
            break;
        case "edit":
            PersonDbManager.instance().update(pform);
            for (JobForm job : jobs) {
                job.setPersonId(pform.getId());
                if (job.getId() == null) {
                    JobExperenceDbManager.instance().add(job);
                } else {
                    JobExperenceDbManager.instance().update(job);
                }
            }
            DefaultMessageRenderingHelper.getConfiguredInstance().info("update succeed");
            break;
        default:
            //
        }
    }
New to GrepCode? Check out our FAQ X