ActionResult , exception with new Jodd version

67 Views Asked by At

I have some code which works Ok with jodd 3.9.1 and I want to upgrade it to jodd version 4.1.4. but I have some errors:

Example:

@POST @Action
public String save(){
    ... some code for validation
    if (!valid){
        return VTOR_JSON;     //Error
    }
    service.store(Object);
    return NONE;            //Error

}

Exception:

jodd.madvoc.MadvocException: Invalid result name:vtor_json     (or  Invalid result name:none)
    at jodd.madvoc.component.ResultsManager.lookup(ResultsManager.java:181)
    at jodd.madvoc.component.MadvocController.render(MadvocController.java:183)
    at jodd.madvoc.ActionRequest.lambda$createExecutionArray$0(ActionRequest.java:208)
    at jodd.madvoc.ActionRequest.invoke(ActionRequest.java:237)
    at jodd.madvoc.component.MadvocController.invoke(MadvocController.java:154)
    at jodd.madvoc.MadvocServletFilter.doFilter(MadvocServletFilter.java:108)

What is the problem?

How to solve this?

2

There are 2 best solutions below

0
igr On

Let me explain:)

With Jodd v4 we don't have anymore the VTOR_JSON type of results - those that return strings. (The string constant is still there, but it is not used). We had to remove this way of returning results as it is not scalable - simply can not add easily different result types.

How to fix it?

We are back to basic :) VTOR_JSON was returning the JSON with the error. So now you have few options (as you can see here):

  • return an object annotated with @RenderWith annotation;
  • put a @RenderWith annotation on the action;
  • return a PathResult helper object;
  • specify the result in the action configuration.

In a short, you should do this by yourself - but don't worry its super easy. For example, you can return:

if (!valid) {
    return JsonResult.of(violations());
}
return null;

If null is not working, try returning new NoneActionResult() (sorry, we will add more convenient way).

Checkout the results package: results.

Sorry for this transition, it is really for good purpose. We will add more helpers like JsonResult. And of course, if you need any support, let us know.

0
Solic On

igr, Thanks for your answer.

I try your sugestion and that's works.

But, I have some additional code:

Example:

public Object save(){
    if (!authorized()){
        return   Redirect.to(AuthAction.ALIAS_ACCESS_DENIED);   //don't work
    }
    if (!valid){
        return JsonResult.of(vtor.getViolations());    //work
    }
    ....
    return null;        //work
}

Here is debug output

38675 [DEBUG] j.m.r.AbstractTemplateViewActionResult.render:79 - new target: /accessDenied:
38676 [DEBUG] j.m.r.ServletDispatcherActionResult.targetExists:99 - target check: /accessDenied.jspf
38676 [DEBUG] j.m.r.ServletDispatcherActionResult.targetExists:99 - target check: /accessDenied.jsp
38676 [DEBUG] j.m.r.AbstractTemplateViewActionResult.render:90 - target found: /accessDenied.jsp

But , never redirect to accessDenied.html.

I try with Object but it doesn't work.

Any suggest?


I found the solution:

if (!valid){
    return JsonResult.of(VtorUtil.createViolationsJsonString(request, vtor.getViolations())).value();

}

It's very easy like you said, igr ;-)