Page Template is missing rather Only jsp page is comming without Template in Magnolia-bossom

£可爱£侵袭症+ 提交于 2019-12-24 21:27:08

问题


I am doing an Spring application using Magnolia CMS.

This is my controller :

@Controller
@Template(title = "Unlock Form", id = "newPositionModule:components/unlockAccount")
public class UnlockAccountComponent {

@Autowired
private LoginServiceImpl loginServiceImpl;

@Autowired
private JavaMailSender mailSender;


@RequestMapping(value = "/unlockAccount", method = RequestMethod.GET)
public String render(@ModelAttribute("resetForm")ResetForm resetForm) {

    return "components/unlockAccountForm.jsp";
}
@RequestMapping(value = "/unlockAccount", method = RequestMethod.POST)
public String reset(@ModelAttribute("resetForm")ResetForm resetForm,HttpServletRequest request,BindingResult result) {
ResetFormValidator validReset = new ResetFormValidator();
    validReset.validate(resetForm, result);
     if (result.hasErrors()) {
            return "components/unlockAccountForm.jsp";
        }
 .....
 .....
  }
 }

This page/ component is configuring within a template called e.g main .

the page content as follows :

   ----------------------------------------------
   <some header>
   ----------------------------------------------

   <form:form id="unlockAccForm" action="?" commandName="resetForm" method="POST">
    <blossom:pecid-input />
     <div class="form-group">
              <form:input path="resetMail" placeholder="Email address or mobile no." id="" class="form-control"/>
              <form:errors path="resetMail" cssClass="errorMessage" />
            </div>
     <div class="form-group">
                <button class="lgn_btn" type="submit">Unlock Account</button>
            </div>
     </form:form>
     ----------------------------------------------------------
     <some footer>
     ----------------------------------------------------------

When I am submitting the form, error message is coming as it is validating with the validator you can see in controller.

But only jsp is coming but template is missing like header and footer is missing.

To get the error message we should not redirect the page as error message won't come due to new request object formation.

can any one suggest me how to resolve this issue.

What i am missing or did anything wrong with the code.

if any one need more query or more details that i did not provide, please can ask me.

please suggest.


回答1:


This is most likely caused by a mistake in configuration of your handler mappings.

After your controller is executed and have returned a view with an error message the view is rendered directly and page rendering is skipped.

Instead what should happen is BlossomHandlerMapping should see that this is a view and not a redirect and proceed with page rendering and have the view rendered later within the page. This is called the pre-execution mechanism.

BlossomHandlerMapping must be configured as a wrapper/decorator in front of all other handler mappings for this to work. It's usually configured like this:

<bean class="info.magnolia.module.blossom.preexecution.BlossomHandlerMapping">
  <property name="targetHandlerMappings">
    <list>
      <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
        <property name="useSuffixPatternMatch" value="false" />
      </bean>
      <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
    </list>
  </property>
</bean>

Note how RequestMappingHandlerMapping is within BlossomHandlerMapping.

If you do have a BlossomHandlerMapping configured make sure that all handler mappings are within it. Also note that if you're using it will add handler mappings that won't be within BlossomHandlerMapping and pre-execution won't work.




回答2:


Assuming header and footer you are missing in response are rendered by other components in the page than the one that renders form, what you probably want is to render whole page on error not just the component. To achieve that you need to tell Blossom/Magnolia to render whole page not just the component. See Blossom documentation on view rendering for more details.
However it is also possible that you have enabled pre-execution of the components and are redirecting on error too early. You probably want to study similar example in Blossom itself and compare it to your setup to find out what exactly is wrong.

Do reply ASAP.

Because there is a deadline on your homework that you might miss? By this comment alone you might have thrown off other people who would be willing to help otherwise ;)



来源:https://stackoverflow.com/questions/29530641/page-template-is-missing-rather-only-jsp-page-is-comming-without-template-in-mag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!