Форма отправляется с одной строкой, но при добавлении другой строки просто появляется страница ошибки whitelabel - PullRequest
0 голосов
/ 01 февраля 2019

Так что не уверен, когда это перестало работать в моем приложении, но у меня есть форма, которая имеет много полей ввода, и при отправке захватывает все и отправляет информацию кому-то по электронной почте.Форма также позволяет добавить целый новый раздел политики, так что вы можете иметь 2 или 3 или столько, сколько вам нужно, входных данных политики.В последнее время форма будет работать, только если включен / заполнен только один раздел политики.Если вы добавите второй и, следовательно, имеете более одного раздела политики и нажмете кнопку «Отправить», он просто перейдет на страницу ошибки whitelabel.Он действует так, как будто он даже не входит в функцию отправки, поэтому мне трудно отлаживать.Также выглядит, что если у вас есть исходный раздел политики и заполните его, нажмите «добавить политику» для второго раздела ввода и заполните второй раздел политики, затем вернитесь и нажмите «добавить политику», чтобы появился третий раздел.не будет работать!Если вы заполнили первый раздел политики и дважды нажали «Добавить политику», он без проблем добавит две строки политики, но все равно не отправит все три.Это должно быть ошибкой в ​​моем разделе политики добавления, так как электронное письмо отправляется нормально только с одним разделом политики ... Есть ли какие-либо предложения или мысли относительно того, что привело к тому, что раздел политики AMS360 не отправлялся, если добавлено более одной политики?

Это ошибка, которую я получаю: это приложение не имеет явного сопоставления для / error, поэтому вы видите это как запасной вариант.Произошла непредвиденная ошибка (тип = неверный запрос, статус = 400).Проверка не удалась для object = 'policyForm'.Количество ошибок: 1

, но, как я уже сказал, прекрасно работает, когда включен только один раздел политики.

контроллер:

@Controller
@SessionAttributes("loggedUser")
public class DirectBindController {
    @Autowired
    ResourceWebsiteUserRepository userRepository;

    @Autowired
    private EmailService emailService;

    @Autowired
    DocumentRepository documentRepository;

    @Autowired
    StorageService storageService;


    @ModelAttribute("loggedUser")
    public ResourceWebsiteUser user(){
        return userRepository.findByEmail(SecurityContextHolder.getContext().getAuthentication().getName());
    }

    @GetMapping("/directBind")
    public String getDirectBind(Model model){
        DirectBind directBind = new DirectBind();
        List<String> businessAgencies = new ArrayList<String>();
        businessAgencies.add("Personal");
        businessAgencies.add("Commercial");
        businessAgencies.add("Life");
        businessAgencies.add("Benefits");
        businessAgencies.add("Health");
        businessAgencies.add("Non P and C");
        model.addAttribute("businessAgencies", businessAgencies);


        List<Ams360Policy> ams360Policies = new ArrayList();
        Ams360Policy ams360Policy = new Ams360Policy();
        ams360Policies.add(ams360Policy);
        model.addAttribute("ams360Policies", ams360Policies);

        List<String> billTypeList = new ArrayList<String>();
        billTypeList.add("Direct Bill");
        billTypeList.add("Agency Bill");
        model.addAttribute("billTypeList", billTypeList);
        ams360Policy.setBillTypeOptions(billTypeList);

        directBind.setDirectBox(true);
        directBind.setServiceLevel(true);

        model.addAttribute("directBind", directBind);

        return "directBind";
    }

    @RequestMapping(value="/directBindAjax", method=RequestMethod.POST)
    public @ResponseBody Document docSend(@ModelAttribute(value="newDoc") Document document, Model model,  @RequestPart("upfile") MultipartFile upfile) throws IOException {
        document.setStorage(storageService.storer(upfile));

        List<Object> attachments = new ArrayList<>();
        attachments.add(upfile);

        return document;
    }

    @RequestMapping(value="/directBind", params="addPolicy")
    public String addPolicy(final DirectBind directBind, Model model){
        List<Ams360Policy> ams360Policies =  directBind.getAms360Policies();
        Ams360Policy ams360Policy = new Ams360Policy();
        ams360Policies.add(ams360Policy);
        model.addAttribute("ams360Policies", ams360Policies);

        List<String> billTypeList = new ArrayList<String>();
        billTypeList.add("Direct Bill");
        billTypeList.add("Agency Bill");
        model.addAttribute("billTypeList", billTypeList);

        List<String> businessAgencies = new ArrayList<String>();
        businessAgencies.add("Personal");
        businessAgencies.add("Commercial");
        businessAgencies.add("Life");
        businessAgencies.add("Benefits");
        businessAgencies.add("Health");
        businessAgencies.add("Non P and C");
        model.addAttribute("businessAgencies", businessAgencies);


        return "directBind";
    }

    @RequestMapping(value = "/directBind", params="removeRow")
    public String removeRow(final DirectBind directBind, final HttpServletRequest req, Model model){
        final Integer rowId = Integer.valueOf(req.getParameter("removeRow"));
        List<Ams360Policy> ams360Policies =  directBind.getAms360Policies();
        model.addAttribute("ams360Policies", ams360Policies);
        directBind.setAms360Policies(ams360Policies);

        Ams360Policy ams360Policy = new Ams360Policy();
        List<String> billTypeList = new ArrayList<String>();
        billTypeList.add("Direct Bill");
        billTypeList.add("Agency Bill");
        model.addAttribute("billTypeList", billTypeList);
        ams360Policy.setBillTypeOptions(billTypeList);


        List<String> businessAgencies = new ArrayList<String>();
        businessAgencies.add("Personal");
        businessAgencies.add("Commercial");
        businessAgencies.add("Life");
        businessAgencies.add("Benefits");
        businessAgencies.add("Health");
        businessAgencies.add("Non P and C");
        model.addAttribute("businessAgencies", businessAgencies);
        directBind.getBusinessAgencyList();

        directBind.getAms360Policies().remove(rowId.intValue());
        model.addAttribute("directBind", directBind);

        return "directBind";
    }

    @RequestMapping(value="/directBind",  params="send")
    public String send(Model model, @ModelAttribute(value="directBind") DirectBind directBind){
        Mail mail = new Mail();
        mail.setFrom("no-reply@info.com");
        mail.setTo(new String[]{"user@info.com"});
        mail.setSubject("AMS360 and PMA Data Checklist");

        Map<String, Object> mailModel = new HashMap<String, Object>();
        mail.setModel(mailModel);

        try {
            emailService.sendSimpleMessage(mail, directBind);
        } catch (Exception e) {
            e.printStackTrace();
            return ("redirect:/?sentMessageFail");
        }

        File[] files = new File(storageService.getFormDirect()).listFiles();
        for(File file : files){
            file.delete();
        }
        return ("redirect:/?sentMessage");
    }


    @RequestMapping(value="/email")
    public String email(){
        return "emailMessage";
    }

}

Служба электронной почты:

@Service
public class EmailService {

    private JavaMailSender javaMailSender;

    @Autowired
    public EmailService(JavaMailSender javaMailSender){
        this.javaMailSender = javaMailSender;
    }

    @Autowired
    public StorageService storage;

    @Autowired
    private SpringTemplateEngine templateEngine;



    public void sendSimpleMessage(Mail mail, DirectBind directBind) throws MessagingException, IOException {
        MimeMessage message = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message,
                MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
                StandardCharsets.UTF_8.name());

        helper.addAttachment("Mail_Icon.png", new ClassPathResource("static/images/Mail_Icon.png"));

        Context context = new Context();
        context.setVariables(mail.getModel());
        context.setVariable("directBind",directBind);
        String html = templateEngine.process("emailMessage", context);

        helper.setTo(mail.getTo());
        helper.setText(html, true);
        helper.setSubject(mail.getSubject());
        helper.setFrom(mail.getFrom());


        File[] files = new File(storage.getFormDirect()).listFiles();
            for(File file : files){
                helper.addAttachment(file.getName(), file);
        }
        javaMailSender.send(message);
    }
}

HTML:

 <form  class="ui form" th:object="${directBind}" th:action="directBind" method="post"  style="padding:0 10px;">
        <h4>Customer Setup</h4>
        <div class="row">
            <label >Contact Name (First/Last):</label>
            <input type="text" th:field="*{contactName}" required="true" />
        </div>
        <div class="row">
            <label for="formAddress">Address:</label>
            <input type="text" id="formAddress" th:field="*{formAddress}" required="true"/>
        </div>
        <div class="row">
            <label for="phoneNumber">Phone Number:</label>
            <input type="text" id="phoneNumber" th:field="*{phoneNumber}" required="true"/>
        </div>
        <div class="row">
            <label for="email">Email:</label>
            <input type="email" id="email" th:field="*{email}" required="true"/>
        </div>
        <div class="row">
            <label for="website" style="margin-top: 1em;"> Website:</label>
            <input type="text" id="website" th:field="*{website}" required="true"/>
        </div>
        <div class="row">
            <label for="nameInsured">Name Insured:</label>
            <input type="text" id="nameInsured" th:field="*{insuredName}" required="true"/>
        </div>
        <div class="row">
            <label>Business with Agency:</label>
            <div th:each="businessAgency : ${businessAgencies}">
                <input type="checkbox" th:field="*{businessAgencyList}" th:value="${businessAgency}"/>
                <label th:text="${businessAgency}">Business with Agency</label>
            </div>

        </div>
        <div class="row">
            <label>Executive:</label>
            <th:block th:switch="${loggedUser==null or loggedUser.client==null }">
                <span th:case="false" th:text="${loggedUser.client.getExecutive()}"></span>
                <span th:case="true"> Not Applicable </span>
            </th:block>
            <th:block th:switch="${loggedUser==null or loggedUser.client==null }">
                <input th:case="false" type="hidden" name="executive" class="executive" th:value="${loggedUser.client.getExecutive()}" />
                <input th:case="true" type="hidden" name="executive" class="executive" value="Not Applicable" />
            </th:block>

            <label style="font-size: 1.25rem; margin-left: 10px;">
                 <input type="checkbox" id="directBox"  th:field="*{directBox}"/>
            Direct </label>
        </div>

        <div class="row" style="display: inline-block; margin-top:0;">
            <p>Service Level:</p>
            <label>
                    <input class="checkbox" type="checkbox" id="serviceLevel"  th:field="*{serviceLevel}"/>
                Affiliate Serviced</label>
        </div>
        <div class="row">
            <label for="affiliateRep">Affiliate Designated Representative:</label><i class="tooltipped material-icons" data-position="top" data-tooltip="Agency Employee (Producer or Account Manager) who owns the account.">info_outline</i>
            <input type="text" id="affiliateRep" th:field="*{affiliateRep}" required="true" />
        </div>

        <div id="amsSection">
            <h4 style="display: inline;">AMS360 Policy Setup</h4>
            <input type="submit" formnovalidate="formnovalidate"  name="addPolicy" class="btn btn-default" style="margin-left: 1rem; margin-bottom: 1rem;" value="Add Another Policy Line"/>
        </div>
        <div class="col-sm-12">
            <hr/>

            <table class="table table-striped AMSTable" data-classes="table-no-bordered" data-striped="true" data-show-columns="true" data-pagination="true">
                <thead>
                <tr>
                    <th>Policy Number</th>
                    <th>Policy Term Start Date</th>
                    <th>Policy Term End Date</th>
                    <th>Line of Coverage</th>
                    <th style="width:150px;">Parent Company<i class="tooltipped material-icons" data-position="top" data-tooltip="Parent Company indicates Standard Carrier, Wholesaler, or MGA">info_outline</i></th>
                    <th style="width:150px;">Writing Company<i class="tooltipped material-icons" data-position="top" data-tooltip="Writing Company indicates carrier paper specific to policy">info_outline</i></th>
                    <th>Bill Type</th>
                    <th style="width:150px;">Quote Premium<i class="tooltipped material-icons" data-position="top" data-tooltip="Annual premium for line of coverage">info_outline</i></th>
                    <th>Commission</th>
                    <th><a class="trigger btn btn-docModal"><span class="fa fa-upload"></span></a></th>


                </tr>
                </thead>
                <tbody>
                <tr name="newRow" th:each="ams360Policy,stat : ${ams360Policies}" th:value="${stat.index}">
                    <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyNumber}" required="true" /></td>
                    <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyTermDateStart}" placeholder="MM/DD/YYYY" required="true"/></td>
                    <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].policyTermDateEnd}"  placeholder="MM/DD/YYYY" required="true"/></td>
                    <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].lineOfCoverage}" required="true" /></td>
                    <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].parentCompany}" required="true" /></td>
                    <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].writingCompany}" required="true" /></td>
                    <td id="billTypeCell">
                        <div class="billTypeDiv" th:each="billType : ${billTypeList}">
                            <input class="bto" type="checkbox" th:field="*{ams360Policies[__${stat.index}__].billTypeOptions}" th:value="${billType}" value="off"/>
                            <label th:text="${billType}" id="billTypeLabel"></label>
                        </div>
                    </td>
                    <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].quotePremium}" required="true"/></td>
                    <td> <input type="text" class="form-control" th:field="*{ams360Policies[__${stat.index}__].commission}"  placeholder="%"/></td>
                    <td class="text-right"> <button type="Submit" formnovalidate="formnovalidate" name="removeRow" th:value="${stat.index}" class="btn btn-danger" ><span class="fa fa-trash"></span></button></td>
                </tr>
                </tbody>
            </table>

            <table>
                <tr>
                    <td id="appendFile"></td>
                </tr>
            </table>

        </div>


        <h4>PMA Setup</h4>
        <div class="row" sec:authorize="hasAnyRole('ADMIN','USER')">
            <label>Sub Brand:</label>
            <th:block th:switch="${loggedUser==null or loggedUser.client==null }">
                <span th:case="false" th:text="${loggedUser.client.getLegalName()}" ></span>
                <span th:case="true">Not Applicable</span>
            </th:block>
            <th:block th:switch="${loggedUser==null or loggedUser.client==null}">
                <input th:case="false" type="hidden" name="subBrand"  class="subBrand" th:value="${loggedUser.client.getLegalName()}" />
                <input th:case="true" type="hidden" name="subBrand"   class="subBrand" value="Not Applicable" />
            </th:block>
        </div>

            <div class="row">
            <label for="descriptionOfOps">Description of Operations:</label>
            <input type="text" id="descriptionOfOps" th:field="*{descriptionOfOps}" required="true" />
        </div>

        <div class="formFooter">
            <input id="send"  type="submit" value="send" name="send" class="btn btn-success finish" data-loading-text="Sent!" disabled="true" />
        </div>
    </form>

Электронная почта HTML:

<body bgcolor="#f6f8f1">
<table width="100%" bgcolor="#f6f8f1" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <!--[if (gte mso 9)|(IE)]>
            <table width="600" align="center" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td>
            <![endif]-->
            <table bgcolor="#ffffff" class="content" align="center" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td bgcolor="#6435c9" class="header">
                        <table width="70" align="left" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td height="70" style="padding: 0 20px 20px 0;">
                                    <img class="fix" src="cid:Mail_Icon.png" width="70" height="70" border="0" alt="" />
                                </td>
                            </tr>
                        </table>
                        <!--[if (gte mso 9)|(IE)]>
                        <table width="425" align="left" cellpadding="0" cellspacing="0" border="0">
                            <tr>
                                <td>
                        <![endif]-->
                        <table class="col425" align="left" border="0" cellpadding="0" cellspacing="0" style="width: 100%; max-width: 425px;">
                            <tr>
                                <td height="70">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td class="subhead" style="padding: 0 0 0 3px;">
                                                NEW DATA CHECKLIST CREATED FOR:
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="h1" style="padding: 5px 0 0 0;" th:text="${directBind.contactName}">
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                        <!--[if (gte mso 9)|(IE)]>
                        </td>
                        </tr>
                        </table>
                        <![endif]-->
                    </td>
                </tr>
                <tr>
                    <td class="innerpadding borderbottom">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr class="emailRow">
                                <h3>Contact Name:</h3>
                                <td class="bodycopy" th:text="${directBind.contactName}">
                                </td>
                            </tr>

                            <tr class="emailRow">
                                <h3>Address:</h3>
                                <td class="bodycopy" th:text="${directBind.formAddress}">
                                </td>
                            </tr >
                            <tr class="emailRow">
                                <h3>Phone Number:</h3>
                                <td class="bodycopy" th:text="${directBind.phoneNumber}">
                                </td>
                            </tr>
                            <tr class="emailRow">
                                <h3>Email:</h3>
                                <td class="bodycopy" th:text="${directBind.email}">
                                </td>
                            </tr>
                            <tr class="emailRow">
                                <h3>Website:</h3>
                                <td class="bodycopy" th:text="${directBind.website}">
                                </td>
                            </tr>
                            <tr class="emailRow">
                                <h3>Insured Name:</h3>
                                <td class="bodycopy" th:text="${directBind.insuredName}">
                                </td>
                            </tr>
                            <tr class="emailRow">
                                <h3>Business Agency:</h3>
                                <td class="bodycopy" th:text="${directBind.businessAgencyList}">
                                </td>
                            </tr>
                            <tr class="emailRow">
                                <h3>Executive:</h3>
                                <td class="bodycopy" th:text="${directBind.executive}">
                                </td>
                            </tr>
                            <tr class="emailRow">
                                <p style="margin-bottom: 15px;">Direct, Affiliate Serviced</p>
                            </tr>

                            <tr class="emailRow">
                                <h3>Affiliate Rep:</h3>
                                <td class="bodycopy" th:text="${directBind.affiliateRep}">
                                </td>
                            </tr>
                            <tr th:each="ams360Policy : ${directBind.ams360Policies}">
                                <h3>AMS 360 Policy:</h3>
                                <p>Policy Number:</p>
                                <tr class="bodycopy" th:text="${ams360Policy.policyNumber}"></tr>

                                <p>Policy Term Start Date:</p>
                                <tr class="bodycopy" th:text="${#temporals.format(ams360Policy.policyTermDateStart, 'MM/dd/yyyy')}"></tr>

                                <p>Policy Term End Date:</p>
                                <tr class="bodycopy" th:text="${#temporals.format(ams360Policy.policyTermDateEnd, 'MM/dd/yyyy')}"></tr>

                                <p>Line of Coverage:</p>
                                <tr class="bodycopy" th:text="${ams360Policy.lineOfCoverage}"></tr>

                                <p>Parent Company:</p>
                                <tr class="bodycopy" th:text="${ams360Policy.parentCompany}"></tr>

                                <p>Writing Company:</p>
                                <tr class="bodycopy" th:text="${ams360Policy.writingCompany}"></tr>

                                <p>Bill Type:</p>
                                <tr class="bodycopy" th:text="${ams360Policy.billTypeOptions}"></tr>

                                <p>Quote Premium:</p>
                                <tr class="bodycopy" th:text="${ams360Policy.quotePremium}"></tr>

                                <p>Commission:</p>
                                <tr class="bodycopy" th:text="${ams360Policy.commission}"></tr>

                            </tr>
                            <tr class="emailRow">
                                <h3>Sub Brand:</h3>
                                <td class="bodycopy" th:text="${directBind.subBrand}">
                                </td>
                            </tr>
                            <tr class="emailRow">
                                <h3>Description of Operations:</h3>
                                <td class="bodycopy" th:text="${directBind.descriptionOfOps}">
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

            </table>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...