How To

AJAX & REST

Add the annotation @EnableWebMvc to your configurer

Create a RestController and make sure that Spring finds it (@ComponentScan)

@RestController
public class AjaxController {
  @RequestMapping(value = "my/path/to/ajax")
  public Object handleAjax(@RequestParam String value) {
    ModelAndView model = new ModelAndView();
    model.addObject("suppliedValue", value);
    return model;
  }
}

Get the url to the AjaxController in JSP via the taglib

<api:controller var="ajaxUrl" resource="/my/path/to/ajax" />

Start sending requests to ${ajaxUrl} (i.e. with JQuery) and work with it.

Enable / Disable parts in your JSP

In your configurer

@Override
public void configureConfigurationTemplate(final ConfigurationTemplateConfigurer configurer) {
   configurer
    .withBooleanKey("plugin.debug").withDefault(Boolean.FALSE)
    .withDescription(Locale.ENGLISH, "Enable debug output");
}

In your JSP

<api:config key="plugin.debug" var="debugging" />
<c:if test="${debugging}">
  Debugging mode is enabled.
</c:if>

Locale

Let Spring inject the ApiShopContextFactory.

Mcs mcs = apiShopContextFactory.getDefaultShopContext().getMcs();
Locale locale = new Locale(mcs.getLanguage(), mcs.getCountry());

Path to plugin

In JSP simply use the controllerTag or resourceTag whenever possible.

In Java you can use servletContext.getContextPath() where the ServletContext needs to get injected first.

Session

Just add the following code to your configurer. Create a class (i.e. SessionData) with your session data that ideally implements Serializable.

@Bean
@Scope("session")
public AtomicReference<SessionData> getSessionData() {
  return new AtomicReference<SessionData>(new SessionData());
}
@Inject
private Provider<AtomicReference<String>> stringForSession;