0

I'm making a website for spring + jsf.RowEdit event not being called

[1]

Game.java

package org.xtremebiker.jsfspring.model;

import org.springframework.stereotype.Component;

import java.util.Date;

@Component(value = "Game")
public class Game {
    private int id;
    private String name;
    private int budget;
    private int profit;
    private int number;
    private int genre;
    private int platform;
    private int status;
    private Date start;
    private Date end;

    //contsructors, getters and setters (omitted for brevity)

    public void update(Game new_game) {
        this.name = new_game.name;
        this.budget = new_game.budget;
        this.profit = new_game.profit;
        this.number = new_game.number;
        this.genre = new_game.genre;
        this.platform = new_game.platform;
        this.status = new_game.status;
        this.start = new_game.start;
        this.end = new_game.end;
    }
}

Games.java

package org.xtremebiker.jsfspring.view;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.primefaces.event.RowEditEvent;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import org.springframework.web.context.annotation.SessionScope;
import org.xtremebiker.jsfspring.model.Game;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

@Component(value = "games")
@SessionScope
public class Games {

    private List<Game> All_games = new ArrayList<Game>();


    public Games() {
        System.out.println("Created!");
        All_games.add(new Game(1, "One", 1000, 500, 8, 1, 2, 4, new Date(), new Date()));
    }

    public void onRowEdit(RowEditEvent event) {
        Game new_game = (Game) event.getObject();
        All_games.get(new_game.getId()).update(new_game);
        FacesMessage msg =
                new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO", "X/Y edit successful!");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        int i = 0;
        i++;

    }


    public List<Game> getAll_games() {
        return All_games;
    }

    public void setAll_games(List<Game> all_games) {
        All_games = all_games;
    }
}

hello.xhtml

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
    </link>

    <style>
        .container {
            display: flex;
            justify-content: space-between;
            width: 100%;
        }
    </style>
</h:head>

<h:body>
    <div class="container">
        <nav id="sidebarMenu" style="padding-right: 5px; flex: 1 1 auto;" class=" ">
            <p:menu toggleable="true">
                <p:submenu label="Игры">
                    <p:menuitem value="Список игр" url="http://www.youtube.com" />
                    <p:menuitem value="Добавить игру" url="http://www.youtube.com" />
                </p:submenu>
                <p:menuitem value="Список сотрудников" url="http://www.youtube.com" />
                <p:menuitem value="Список кандидатов" url="http://www.youtube.com" />
            </p:menu>
        </nav>
        <div style=" flex: 1 1 auto;">
            <p:dataTable value="#{games.all_games}" editable="true" var="game">

                <p:ajax event="rowEdit" listener="#{games.onRowEdit}" />

                <p:column headerText="Название">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{game.name}" />
                        </f:facet>
                        <f:facet name="input">
                            <h:inputText value="#{game.name}" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>
                <p:column headerText="Бюджет">
                    <h:outputText value="#{game.budget}"></h:outputText>
                </p:column>
                <p:column headerText="Прибыль">
                    <h:outputText value="#{game.profit}"></h:outputText>
                </p:column>
                <p:column headerText="Оценка">
                    <h:outputText value="#{game.number}"></h:outputText>
                </p:column>
                <p:column headerText="Жанр">
                    <h:outputText value="#{game.genre}"></h:outputText>
                </p:column>
                <p:column headerText="Платформа">

                    <h:outputText value="#{game.platform}"></h:outputText>
                </p:column>
                <p:column headerText="Статус разработки">
                    <h:outputText value="#{game.status}"></h:outputText>
                </p:column>
                <p:column headerText="Начало разработки">
                    <h:outputText value="#{game.start}">
                        <f:convertDateTime pattern="dd.MM.yyyy " />
                    </h:outputText>

                </p:column>

                <p:column headerText="Дата релиза">
                    <h:outputText value="#{game.end}">
                        <f:convertDateTime pattern="dd.MM.yyyy " />
                    </h:outputText>
                </p:column>
                <p:column style="width:35px">
                    <p:rowEditor />
                </p:column>
            </p:dataTable>
        </div>
    </div>
</h:body>
</html>

Does anyone know why?

And a little more text so that I can publish the post-1. And a little more text so that I can publish the post -2. And a little more text so that I can publish the post- 3. And a little more text so that I can publish the post -4.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user376237
  • 27
  • 6
  • no,still doesn't work – user376237 Dec 17 '20 at 21:16
  • I don't see an `` anywhere in your setup. When in doubt, open the browser's JS console. First thing you want to check is to make sure there's actually a transmission btw the browser and your web server. If that's happening, then you want to check what the response of your webapp is. You could be suffering from some validation or conversion error that isn't visible on the page itself. – kolossus Dec 18 '20 at 05:05

0 Answers0