所有bean属性都指定为null

问题描述 投票:0回答:1

我正在使用Spring Boot编写应用程序。我想创建一个bean LobbyBean的实例,但是在填充完表单后,所有属性仍为null。有没有人知道,为什么输入数据无法通过控制器?任何帮助是极大的赞赏。

这是(简化)代码:

LobbyBean

@Component
@Scope("session")
public class LobbyBean {

@GeneratedValue
private int pin;
private QuestionSet questionSet;
private User host;
private QuestionDifficulty questionDifficulty;
private int maxNumberOfPlayers;
private boolean hasJoker;

// getters and setters for all attributes

LobbyController

@Component
@Scope("view")
public class LobbyController {

@Autowired
private GameManager gameManager;

@Autowired
private UserService userService;

private LobbyBean newLobby = new LobbyBean();

// getter and setter for newLobby

public void createLobby()
{
   newLobby.setHost(userService.getAuthenticatedUser());
   gameManager.saveLobby();
   newLobby = new LobbyBean();
}

lobbycreation.xhtml

<ui:define name="content">

    <h:form id="lobbysettings">
        <p:panel>
        <h:panelGrid id="settings" columns="2">

            <p:outputLabel value="Questionset: "/>
            <p:selectOneMenu id="questionset" value="#{lobbyController.newLobby.questionSet}">
                <f:selectItems value="#{lobbyDetailController.allQuestionSetNames}"/>
            </p:selectOneMenu>

            <p:outputLabel value="Difficulty: "/>
            <p:selectOneMenu id="difficulty" value="#{lobbyController.newLobby.questionDifficulty}" >
                <f:selectItems value="#{lobbyDetailController.allQuestionDifficulties}"/>
            </p:selectOneMenu>

            <p:outputLabel value="Max Num of Players: "/>
            <p:inputNumber decimalPlaces="0" value="#{lobbyController.newLobby.maxNumberOfPlayers}" />

            <p:outputLabel value="Joker?"/>
            <p:inputSwitch value="#{lobbyController.newLobby.hasJoker}" />

            <p:commandButton id="createLobbyButton" value="Lobby Erstellen" process="@this"
                             action="#{lobbyController.createLobby}"/>

        </h:panelGrid>
        </p:panel>
    </h:form>

</ui:define>
spring-boot jsf primefaces
1个回答
1
投票

process="@this"替换你的p:commandButton的process="@form"on,否则只有commandButton将成为提交的一部分。

© www.soinside.com 2019 - 2024. All rights reserved.