Dreana
Dreana

Reputation: 587

All bean attributes are assigned null

I'm writing an application using Spring Boot. I'd like to create an instance of the bean LobbyBean, but after heaving filled out the form, all attributes are still null. Does anybody have an idea, why the input data doesn't get through to the controller? Any help is greatly appreciated.

Here is the (simplified) code:

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>

Upvotes: 0

Views: 71

Answers (1)

maroswal
maroswal

Reputation: 96

Replace the process="@this"on your p:commandButton with process="@form" otherwise only the commandButton will be part of the submit.

Upvotes: 1

Related Questions