Announcement Announcement Module
Collapse
No announcement yet.
invoke0(Native Method) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • invoke0(Native Method)

    hello!
    I was creating a method in a SomethingController.java (actually I rewrote the .create from _Roo_Controller.aj) and when I create a new entity (after executing run mvn tomcat:run) it throws an internal error. This is at the top of the stack trace:

    za.co.bsg.rnd.trf.openidlogin.web.EmployeeControll er.create(EmployeeController.java:31)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)

    this is EmployeeController.java:

    Code:
    package za.co.bsg.rnd.trf.openidlogin.web;
    
    import java.io.UnsupportedEncodingException;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.validation.Valid;
    
    import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
    import za.co.bsg.rnd.trf.openidlogin.domain.Employee;
    
    import org.springframework.ui.Model;
    import org.springframework.validation.BindingResult;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.util.UriUtils;
    import org.springframework.web.util.WebUtils;
    import org.springframework.stereotype.Controller;
    
    @RooWebScaffold(path = "employees", formBackingObject = Employee.class)
    @RequestMapping("/employees")
    @Controller
    public class EmployeeController {
    	
    	
    	@RequestMapping(method = RequestMethod.POST)
        public String create(@Valid Employee employee, BindingResult result, Model model, HttpServletRequest request) {
            if (result.hasErrors()) {
                model.addAttribute("employee", employee);            
                return "employees/create";
            }                
            return "redirect:/employees/" + encodeURLPathSegment(employee.getId().toString(), request); //this is where it throws the error
        }
    	
    	 @RequestMapping(params = "form2", method = RequestMethod.GET)
    	    public String crearForm(Model model) {		 	
    	        model.addAttribute("employee", new Employee());
    	        return "employees/create";
    	    }
    	 
    	 String encodeURLPathSegment(String pathSegment, HttpServletRequest request) {
    	        String enc = request.getCharacterEncoding();
    	        if (enc == null) {
    	            enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
    	        }
    	        try {
    	            pathSegment = UriUtils.encodePathSegment(pathSegment, enc);
    	        }
    	        catch (UnsupportedEncodingException uee) {}
    	        return pathSegment;
    	    }
    }
    help me please!!
    the main question is: what is that native method?

  • #2
    I know where is the problem... but I don't know how to fix it... roo is not generating the id for the new employee.. in fact, if I add:

    Code:
    System.out.println(employee.getId().toString());
    it shows a java.lang.NullPointerException

    Comment

    Working...
    X