4
respostas

Problems calling function [s:mvcUrl]

Eu dei um force update no projeto e parou de funcionar os build de link

org.apache.jasper.JasperException: javax.el.ELException: Problems calling function [s:mvcUrl]
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:598)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:514)


java.lang.IllegalArgumentException: Mapping not found: LC#cadastroUsuario
    org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMappingName(MvcUriComponentsBuilder.java:463)
    org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMappingName(MvcUriComponentsBuilder.java:433)

}

`

4 respostas

Meu controller

package br.com.kodeweave.sessao.controller;

import java.util.concurrent.Callable;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import br.com.kodeweave.dao.UsuarioDao;
import br.com.kodeweave.infra.FileSaver;
import br.com.kodeweave.models.Usuario;
import br.com.kodeweave.validation.UsuarioValidation;

@Controller
//@Scope(value=WebApplicationContext.SCOPE_REQUEST)
public class LoginController{

    @Autowired
    private UsuarioDao usuarioDao;

    @Autowired
    private FileSaver fileSaver;

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.addValidators(new UsuarioValidation());
    }


    @RequestMapping("/")
    public String index(){
        System.out.println("Entrando na home da CDC");
        return "home.jsp";
    }

    @RequestMapping("/loginForm")
    public ModelAndView loginForm() {
        ModelAndView modelAndView = new ModelAndView("kodeweaveFolder/tcc/index");
        return modelAndView;
    }
    @RequestMapping(value = "/boasvindas", method = RequestMethod.GET)
    public ModelAndView boasVindas(@RequestParam(value = "inputCpf", required = false, defaultValue = "Cícero Ednilson") String nome) {

         ModelAndView modelAndView = new ModelAndView("boasVindas");
         modelAndView.addObject("mensagem", "Olá " + nome);

         return modelAndView;
    }

    @RequestMapping("/editor")
    public String editor() {
        return "kodeweaveFolder/editor/index.jsp";
    }

    @RequestMapping("/home")
    public String home() {
        return "kodeweaveFolder/tcc/home/home.jsp";
    }

    @RequestMapping("/efetuaLogin")
    public Callable<ModelAndView> efetuaLogin(Usuario usuario, HttpSession session,
            RedirectAttributes redirectAttributes) {
        return () -> {
            Boolean existeUsuario = usuarioDao.buscar(usuario);
            if(existeUsuario) {
                session.setAttribute("usuarioLogado", usuario);
                return new ModelAndView("redirect:home");
            }
            redirectAttributes.addFlashAttribute("falha", "Usuário Inexistente");
            return new ModelAndView("redirect:loginForm");
        };
    }

    @RequestMapping("logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "redirect:loginForm";
    }


    @RequestMapping(value = "/cadastroUsuario")
    public ModelAndView cadastroUsuario(Usuario usuario) {
        ModelAndView modelAndView = new ModelAndView("kodeweaveFolder/tcc/usuario/cadastroUsuario.jsp");
        return modelAndView;
    }

    @RequestMapping(value ="/cadastroUsuario",  method = RequestMethod.POST )
    public Callable<ModelAndView> gravaUsuario(MultipartFile foto, @Valid Usuario usuario, BindingResult result,
            RedirectAttributes redirectAttributes) {
        return() ->{
            Boolean existe = usuarioDao.buscarUsuarioExistente(usuario);
            if(existe) {
                redirectAttributes.addFlashAttribute("usuarioExistente", 
                        "Usuário já cadastrado com esse login");
                 return new ModelAndView("redirect:cadastroUsuario");
            } 

            if (result.hasErrors())
                return cadastroUsuario(usuario);


            String path = fileSaver.write("arquivos-foto", foto);
            usuario.setPathFoto(path);

            usuarioDao.gravar(usuario);
            redirectAttributes.addFlashAttribute("sucesso", "Usuário cadastrado com sucesso!");

            return new ModelAndView("redirect:loginForm");
        };
    }

Oi João,

Repare no erro:

java.lang.IllegalArgumentException: Mapping not found: LC#cadastroUsuario

Talvez seja por você ter dois métodos cadastroUsuario (mesmo nome).

Existe uma forma mais indicada nestes casos.

@RequestMapping(value = "/url", name = "nomeDaAction")
public String minhaAction() {
    return "minhaJsp"
}

Você pode usar a propriedade name da annotation @RequestMapping na função mvcUrl.

${s:mvcUrl('nomeDaAction').build() }

Assim você não corre o risco de ter problemas, já que a propriedade name é única por action.

Abraço!

Tentei desse modo porém continua com o erro.

Meu jsp ta assim no momento

<!-- This snippet uses Font Awesome 5 Free as a dependency. You can download it at fontawesome.io! -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<head>
        <title>Kodeweave - Login</title>

        <!-- 

        <meta charset="utf-8">
        <spring:url value="favicon.ico"></spring:url>
        <spring:url value="bootstrap.min.css" var="bootstrapTheme"></spring:url>
        <spring:url value="jquery.min.js" var="jqueryTheme"></spring:url>
        <spring:url value="app.css" var="cssLogin"></spring:url>
        <spring:url value="bootstrap.bundle.min.js" var="bootstrapJs"></spring:url>
        <spring:url value="all.css" var="allCss"></spring:url>
         -->

        <link rel="icon" href="resources/favicon.ico">
        <link rel="stylesheet" href="resources/bootstrap.min.css">
        <link rel="stylesheet" href="resources/jquery.min.js">
        <link rel="stylesheet" href="resources/login/app.css">
            <link rel="stylesheet" href="resources/bootstrap.bundle.min.js">
        <link rel="stylesheet" href="resources/all.css">


</head>
<body>
  <div class="container">
    <div class="row">
      <div class="col-sm-9 col-md-7 col-lg-5 mx-auto">
        <div class="card card-signin my-5">
          <div class="card-body">    
            <img src="resources/login/kodeweave.png" alt="Logo kodeweave" class="logo-kodeweave">
            <h5 class="card-title text-center">Sign In</h5>
            <div id='msgErroLogin' class="alert alert-danger">${falha}</div>
            <div id='msgErroLogin' class="alert alert-success">${sucesso}</div>
            <form class="form-signin" action="efetuaLogin" method="POST">
              <div class="form-label-group">
                <input type="cpf" id="login" class="form-control" placeholder="CPF" name=login required autofocus>
                <label for="login">CPF</label>
              </div>

              <div class="form-label-group">
                <input type="password" id="senha" class="form-control" placeholder="Password" name=senha required>
                <label for="senha">Password</label>
              </div>

              <div class="custom-control custom-checkbox mb-3">
                <input type="checkbox" class="custom-control-input" id="customCheck1">
                <label class="custom-control-label" for="customCheck1">Remember password</label>
              </div>
              <button class="btn btn-lg btn-primary btn-block text-uppercase" type="submit">Sign in</button>
              <hr class="my-4">
            </form>
            <a class="custom-cadastro-usuario"  href="${s:mvcUrl('LC#cadastroUsuario').build()}">
            </a>

          </div>
        </div>
      </div>
    </div>
  </div>
</body>

Obs: Só possuo um controller com as inicais LC