Compilation error: method render in class list can

2019-09-17 16:34发布

问题:

I'm still learning Play!Framework and, as a lesson, I decided to include a new feature in a application (available in Samples, called "Computer Database").

Well this app is very simple. It has a Computer model and it has a @ManyToOne relationship with a Company model. Well, basically I decided to copy Computer model and I made a Employee model, which is basically the same. I copied Computer Model, Controller and Routes and I tried to compile unsuccessfully, as you can see below:

public static Result list(int page, String sortBy, String order, String filter) {
    return ok(
        list.render( //-- LINE IN RED!
            Employee.page(page, 10, sortBy, order, filter),
            sortBy, order, filter
        )
    );
}

Actually, I tried to compile it because I was looking for more tips, as I have other issues in my Eclipse, only in my new Controller, called "Employees". The code above is marked with:

Multiple markers at this line: Occurrence of 'render'; The method render(Page<Computer>, String, String, String) in the type list is not applicable for the arguments (Page<Employee>, String, String, String)

And only in this controller I have static methods Result update/create/save/delete pointed with a message:

The method render(Form < Computer >) in the type createForm is not applicable for the arguments (Form < Employee >)

The point is: I'm not trying to use this method with Employee obj arguments. Every single method contains: Form< Employee > employeeForm = form(Employee.class)...

My IDE is saying this method render is not applicable for the Employee Page's arguments, only for Computer Page's, which sounds totally weird for me, because, as I said, it is a generic class, a play-framework native class, and Employee and Computer are models created by me.

--

  • Employee.page's signature:

    public static Page< Employee > page(int page, int pageSize, String sortBy, String order, String filter)

--

I searched a dependency/library inconsistency, but personally I could find it. I've already tried to restart Eclipse, my server, "play clean"/"update"/etc in the console... What else could I verify?

回答1:

We solved my issue. We simply replace the code like list.render for a previously ready code called listEmployees.render and then we did the same for public static Result save and public static Result create, and in this case, for its corresponding createEmployeeForm, which was also previously done. But we were not using the Employees' views originally developed for this, because our great Eclipse IDE was pointing issues.

We simply ignored this Eclipse issue and, voilà, it runs! Then we refreshed the project and now it's right. Thanks for all attention!