[SOLVED] "Drag n drop" DataTable Event on EE8 & JSF 2.3

UI Components for JSF
Post Reply
NOTiFY
Posts: 393
Joined: 25 May 2016, 22:57

02 May 2018, 23:31

I downloaded the 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:

Code: Select all

<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:

Code: Select all

<p:ajax listener="#{dndCarsView.onCarDrop}" update="dropArea availableCars" />
The Java 'backing bean' with the method ''onIngredientDrop":

Code: Select all

@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:

Code: Select all

public void onCarDrop(DragDropEvent ddEvent) {
        Car car = ((Car) ddEvent.getData());
  
        droppedCars.add(car);
        cars.remove(car);
}
I had to use the OmniFaces @ViewScoped as the standard one caused the error:
WELD-001303 No active contexts for scope type
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.

TIA
Last edited by NOTiFY on 04 May 2018, 18:04, edited 1 time in total.
PF 13.0.0--Jakarta. Jakarta Faces 4.0.1/Kotlin Multiplatform 1.9.10
Mojarra 4.0.2, OmniFaces 4.2
WildFly 29.0.1.Final 'preview' Jakarta EE 10.0.0
JDK 20.0.2, Kotlin 1.9.10, Gradle 8.3 Groovy DSL, MongoDB 7.0.0
IntelliJ IDEA 2023.2.1, macOS Ventura 13.5.1

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

03 May 2018, 20:22

Code: Select all

@Model
@Path("/")
@ViewScoped
@Named("nOTiFYwellController")
Contains a contradiction. @Model = @Named +@RequestScoped

And the @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

NOTiFY
Posts: 393
Joined: 25 May 2016, 22:57

04 May 2018, 13:17

Thank you. 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 included in my WAR for deployment

Code: Select all

@ManagedBean(name = "ingredientBean")
@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'}
PF 13.0.0--Jakarta. Jakarta Faces 4.0.1/Kotlin Multiplatform 1.9.10
Mojarra 4.0.2, OmniFaces 4.2
WildFly 29.0.1.Final 'preview' Jakarta EE 10.0.0
JDK 20.0.2, Kotlin 1.9.10, Gradle 8.3 Groovy DSL, MongoDB 7.0.0
IntelliJ IDEA 2023.2.1, macOS Ventura 13.5.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 32 guests