How get ContextPath with Thymeleaf th:href?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How get ContextPath with Thymeleaf th:href?

Thiago Moreno
Hi,
I did use ZXing API to read bar code in my web pages and did worked fine. But URL of server is static.

<div class="form-group">
        <label for="barCode">EAN</label> 
        <input type="text" id="barCode" name="barCode" th:field="*{barCode}" />
        <a href="http://zxing.appspot.com/scan?ret=http://localhost:8080/app/products?barCode={CODE}">Read...
</div>       



So, i will use this app in mobile, in differents customers. So, if i use static url, i will always be change every link in the pages, for every server that run app.

i try th:href="|http://zxing.appspot.com/scan?ret=@{~/products?barCode=}{CODE}|", but in all cases, just only did translated to  relative url.

There is anyway to get the context path using thymeleaf or i need send in parameter to the view and use ${url}?
Reply | Threaded
Open this post in threaded view
|

Re: How get ContextPath with Thymeleaf th:href?

Thiago Moreno
With this code, solved my problem. But, this is the only way? Or there is another way with the thymeleaf th:href ?


@GetMapping
public ModelAndView listar(HttpServletRequest request,  ProductFilter productFilter, Pageable page) {
        ModelAndView mv = new ModelAndView("products/ListProducts");
        mv.addObject("url", request.getRequestURL());
        mv.addObject("products", productService.list(productFilter, page));
        return mv;
}

<div class="form-group  col-xs-6  col-md-4">
        <label class="control-label" for="gtin">GTIN</label>
        <div class="bw-field-action"> 
                <input type="text" class="form-control" id="gtin" name="gtin" th:field="*{gtin}" />
                <div class="bw-field-action__icon">
                    <aaa th:href="|http://zxing.appspot.com/scan?ret=${url}?gtin={CODE}|">
                               
                    </aaa>
                </div>
        </div>
</div>