java.lang.IllegalArgumentException: Invalid type {}, should be {}-Resolved

Is there a way to call two classes in a controller? when i tried to do it, it gives me the following exception : java.lang.IllegalArgumentException: Invalid type {}, should be {}.
Here is my code :

public void ChangeTest(ActionRequest request , ActionResponse response) {
FirstClass fc = request.getContext().asType(FirstClass .class);
SecondClass sc = request.getContext().asType(SecondClass.class);
BigDecimal test = service.ChangeTest(fc,sc);
response.setFlash(test.toString());
}

by default, you can retreive only one kind of object through the ActionRequest. The object’s type is defined by the “model” attribute.

any example please?

if you have this form:

<form name="myform" model="com.axelor.auth.db.User" onLoad="my-action">
...
</form>

You could write inside your controller : User u = request.getContext().asType(com.axelor.auth.db.User..User.class);

So the model attribute on your form will be the object inside the request context

If inside your form you have a field which is amany-to-x relation (like User with Group) you, can access its properties like u.getGroup()....

But my service ChangeTest(a,b) is containing 2 parameters. How can i create its controller??

you can’t retreive 2 objects from a crontroller using ActionRequest so if your service requires 2 objects, get the child object (by using field getter) from the main object or use the repository to fetch it.

1 « J'aime »

Thanks for your answer. It worked!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.