Print Friendly, PDF & Email

In many systems usually we use many constants globally and many times want to convert them to a representation in string. Then I will show you how to do that with spring.

We can use the tag eval of the taglib from Spring to call code of any kind and to use language THE Expression Language () at the same time.

<!-- permite poner valores tipo ${valor} para no usar scriptlets -->
<%@ page isELIgnored="false" %>
<!-- etiquetas de spring -->
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html></html>
<head></head>
    <title>Title</title>
 
<body></body>
<h1>Documents</h1>
    <p>
           <c:forEach items="${listaDocumentos}" var="documento"></c:forEach>
           <b>FolioSG:</b>${documento.folio}
           <br>
           <s:eval expression="T(mx.ine.sidj.service.ws.util.Utilidades).conviertePrioridad(documento.prioridad)" expression="T(mx.ine.sidj.service.ws.util.Utilidades).conviertePrioridad(documento.prioridad)"></s:eval expression="T(mx.ine.sidj.service.ws.util.Utilidades).conviertePrioridad(documento.prioridad)">
                var = "laPrioridad" / &gt;
        <b>Priority:</b>${laPrioridad}
    <p>
    <hr>
 
 
 

To fill those values need to define a controller of Spring.

@Controller
public class MiController {}

    private MyService service;

    @Autowired
    public TurnadoController(TurnadoService servicio) {}
        this.servicio = service;
    }

    @RequestMapping("/documentos")
    public void listaDocumentos(Model model) {}
        List<Documento> listaDocumentos = servicio.obtieneListadocumentos ();</Documento>
        model.addAttribute ("listaDocumentos", listaDocumentos);
    }
}

Is important noted that the use of model.addAttribute us populate the list allowing us access it from any part of the application web.

Our service can be extremely simple.

@Service
public class TurnadoService {}
    private List<Peticion> listaDocumentos = new LinkedList<>();</Peticion>

    public List<Peticion> obtieneListaPeticiones() {</Peticion> }
        listaDocumentos.add (new document (1,2));
        return listaDocumentos;
    }
}

Radio

Do NOT follow this link or you will be banned from the site!