所有bean属性分配为null

时间:2019-04-11 13:26:43

标签: spring-boot jsf primefaces

我正在使用Spring Boot编写应用程序。我想创建一个豆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>

1 个答案:

答案 0 :(得分:1)

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