How to make an AJAX call in Magnolia Blossom?

偶尔善良 提交于 2020-01-24 00:32:07

问题


I am new to Magnolia Blossom.

I have to perform an AJAX call in my application in Blossom. We have a Controller per component. So I am unable to make an AJAX request.

Can anyone suggest how can I achieve this?


回答1:


you may define a different Servlet (and web application context), you can define a servlet that handles all the requests that start for /rest/* and then below that on your web.xml you can define the blossom servlet. All the rest is configuration, try to see how to create a webapp with 2 different contexts.




回答2:


The controllers you're using for rendering content are not accessible to requests coming in to the servlet container. Without content they're pretty useless and won't generate meaningful output. You need a separate DispatcherServlet handling these AJAX requests.

There's two ways to achieve this. You can either add a new DispatcherServlet to web.xml or you can add a servlet to your module that is installed when your module is installed.

The latter is the better choice because you won't need to have two separate ApplicationContexts. The one created in your module on startup will be the parent of both DispatcherServlets so both can access beans within it. You also won't need to update web.xml which makes module install easier and upgrades of Magnolia easier.

In your module descriptor add this snippet:

<servlets>
  <servlet>
    <name>dispatcher</name>
    <class>org.springframework.web.servlet.DispatcherServlet</class>
    <mappings>
      <mapping>/ajax/*</mapping>
    </mappings>
    <params>
      <param>
        <name>contextConfigLocation</name>
        <value>classpath:/ajax-servlet.xml</value>
      </param>
    </params>
  </servlet>
</servlets>

This, and other topics, is described in the Magnolia wiki https://wiki.magnolia-cms.com/display/WIKI/Adding+a+DispatcherServlet+to+a+Blossom+module




回答3:


Depending on what you want to get out, you can also use REST module of Magnolia. To e.g. read a title of website you can just call http://localhost:8080/magnoliaAuthor/.rest/properties/v1/website/demo-project/siteTitle more details at documentation

And you can use REST module to also very easily add your own endpoints by just annotating source code.

HTH, Jan



来源:https://stackoverflow.com/questions/30123766/how-to-make-an-ajax-call-in-magnolia-blossom

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