NOTiFY
NOTiFY

Reputation: 1403

'Drag and Drop' Event method on p:dataTable not called

I downloaded the PrimeFaces showcase-6.2.war and deployed it on JBoss WildFly 12.0.0.Final running on EE 8. The drag and drop 'DataTable' example works fine.

For a test/PoC I have replicated the showcase example (exactly) just using some of my own data. Which populates & displays in the DataTable.

However, when I drag an item to the 'Selected Pane' I get the error:

SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-1) javax.el.MethodNotFoundException: Method not found: class com.notifywell.controller.NOTiFYwellController.onIngredientDrop(org.primefaces.event.DragDropEvent)

The XHTML that calls this is:

<p:droppable for="fieldsetSelectedIngredients" tolerance="touch" activeStyleClass="ui-state-highlight" datasource="dataTableAvailableIngredients" onDrop="handleDrop">
    <p:ajax listener="#{nOTiFYwellController.onIngredientDrop}" update="dropArea dataTableAvailableIngredients" />
</p:droppable>

PrimeFace ShowCase :

<p:ajax listener="#{dndCarsView.onCarDrop}" update="dropArea availableCars" />

My Java 'backing bean' with the method ''onIngredientDrop":

@Model
@Path("/")
@ViewScoped // OmniFaces 3.1
@Named("nOTiFYwellController")
//@ManagedBean(name="nOTiFYwellController") // Deprecated
public class NOTiFYwellController implements Serializable {
     .....

    public void onIngredientDrop(DragDropEvent ddEvent) {
        Ingredient ingredient = ((Ingredient) ddEvent.getData());

        logger.info("***** onIngredientDrop ddEvent = {}", ddEvent.getData());
    }
}

PrimeFace ShowCase:

public void onCarDrop(DragDropEvent ddEvent) {
        Car car = ((Car) ddEvent.getData());

        droppedCars.add(car);
        cars.remove(car);
}

The error is due to the p:ajax listener not passing the DragDropEvent parameter.

In the PF ShowCase example, the parameter isn't required. How can I get the 'DragDropEvent' in my backing bean?

If I make the 'onIngredientDrop' method with no parameters it gets called and displays a (revised) log message.

My environment:

PrimeFace 6.2.3 JSF 2.3 JBoss WildFly 12.0.0.FINAL Java version 1.8.0_66 (build 1.8.0_66-b17) Google Chrome Version 66.0.3359.117 (Official Build) (64-bit) macOS High Sierra 10.13.4

TIA

Upvotes: 1

Views: 675

Answers (1)

NOTiFY
NOTiFY

Reputation: 1403

Your code contains a contradiction: @Model = @Named +@RequestScoped and the additional @Named is taking the default class name. So please make up your mind.... And an @Path on a bean that is used from JSF is also uncommon. Maybe you need to put more code in a service class and call that class from either a @Path+@Model annotated class and Also from a @Named and @ViewScoped. At the same time that would be weird that you want the usage from two different scoped beans – Kukeltje

Solved by @Kukeltje suggestion.

Yes, the error was mixing the annotations for a JSF backing bean in my @Model Controller.

I moved the method 'onIngredientDrop' to a 'dedicated' JSF backing bean and included in my WAR for deployment.

// @ManagedBean(name = "ingredientBean") // Deprecated
@Named
@ViewScoped
public class IngredientBean implements Serializable {

    /**
     *
     */
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     *
     */
    private List<Ingredient> droppedIngredients = new ArrayList<Ingredient>();

    /**
     * @param ddEvent DragDropEvent
     */
    public void onIngredientDrop(DragDropEvent ddEvent) {
        Ingredient ingredient = ((Ingredient) ddEvent.getData());

        logger.info("***** onIngredientDrop ingredient = {}", ingredient.toString());

        //droppedIngredients.add(Ingredient);
    }
}

WildFly console output:

12:10:04,021 INFO [com.notifywell.jsf.IngredientBean] (default task-3) ***** onIngredientDrop ingredient = Ingredient{id='5aec3dc5c0a118606e42a11b', ingredientName='Folic Acid'}

Upvotes: 1

Related Questions