0

我想结合 2 个模型(用户和用户数据)来获取请求参数,但结果我看到了一个空白屏幕。我的代码有什么问题?

注册对象是一个 ModelAttribute

users 和 userData 模型有一些字段。

数据模型

public class Register {
    private Users users;
    private UserData userData;
//getters and setters
}

注册.jspx

<form:form action="register" method="post" commandName="register">
            <fieldset>
                <div class="span12">
                    <legend>Sign Up as a Merchant</legend>
                </div>
                <form:input type="hidden" path="enabled" value="true"/>
                <div class="span6">
                    <div class="control-group" id="usernameCtl">
                        <label class="control-label" for="username">Username</label>
                        <div class="controls">
                            <form:input type="text" class="input-xlarge" id="username" path="users.username"/>
                            <form:errors path="users.username"/>
                        </div>
                    </div>
                    <div class="control-group" id="passwordCtl">
                        <label class="control-label" for="password">Password</label>

                        <div class="controls">
                            <form:input type="password" class="input-xlarge" id="password" path="users.password"/>
                            <form:errors path="users.password"/>
                        </div>
                    </div>
                    <div class="control-group" id="confirmCtl">
                        <label class="control-label" for="confirm">Confirm</label>
                        <div class="controls">
                            <form:input type="password" class="input-xlarge" id="confirm" name="confirm"/>
                        </div>
                    </div>
                    <div class="control-group" id="emailCtl">
                        <label class="control-label" for="email">Email</label>
                        <div class="controls">
                            <form:input type="text" class="input-xlarge" id="email" path="userData.email"/>
                            <form:errors path="userData.email"/>
                        </div>
                    </div>

                </div>
                <div class="span6">
                    <div class="control-group" id="nameCtl">
                        <label class="control-label" for="name">Name</label>
                        <div class="controls">
                            <form:input type="text" class="input-xlarge" id="name" path="userData.name"/>
                            <form:errors path="userData.name"/>
                        </div>
                    </div>
                    <div class="control-group" id="surnameCtl">
                        <label class="control-label" for="surname">Surname</label>
                        <div class="controls">
                            <form:input type="text" class="input-xlarge" id="surname" path="userData.surname"/>
                            <form:errors path="userData.surname"/>
                        </div>
                    </div>

                    <div class="control-group" id="IDNumberCtl">
                        <label class="control-label" for="streetAddress">Id Number</label>
                        <div class="controls">
                            <form:input type="text" class="input-xlarge" id="idNumber" path="userData.idNumber"/>
                            <form:errors path="userData.idNumber"/>
                        </div>
                    </div>
                    <div class="control-group" id="FactoryCtl">
                        <label class="control-label" for="city">Factory</label>
                        <div class="controls">
                            <form:select path="userData.factory">
                                <form:options itemValue="id" itemLabel="name" items="${factory}" />
                            </form:select>-->
                        </div>
                    </div>

                    <div class="control-group" id="IssueSectionCtl">
                        <label class="control-label" for="state">IssueSection</label>
                        <div class="controls">
                            <form:select path="userData.issueSection">
                                <form:options itemValue="id" itemLabel="name" items="${issueSection}" />
                            </form:select>-->
                        </div>
                    </div>

                    <input class="btn btn-primary btn-large" type="submit" value="Register"/> &nbsp; &nbsp;
                    <a href="${pageContext.request.contextPath}/" class="btn btn-large ">Cancel</a>

                </div>
            </fieldset>
        </form:form>

UsersController_Roo_Controller

@RequestMapping(method = RequestMethod.POST, produces = "text/html",value = "/register")
    public String UsersController.register(@ModelAttribute("register") Register register, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
        if (bindingResult.hasErrors()) {
            populateRegisterForm(uiModel, register);
            return "userses/register";
        }
        uiModel.asMap().clear();
        //users.setUserData(userData);
      register.getUsers().persist();
        return "redirect:/userses/" + encodeUrlPathSegment(register.getUsers().getId().toString(), httpServletRequest);
    }

@RequestMapping(params = "register", produces = "text/html")
    public String UsersController.registerForm(Model uiModel) {
        populateRegisterForm(uiModel, new Register());
        return "userses/register";
    }


void UsersController.populateRegisterForm(Model uiModel, Register register) {
        uiModel.addAttribute("factory", Factory.findAllFactorys());
        uiModel.addAttribute("issueSection", IssueSection.findAllIssueSections());
        uiModel.addAttribute("register",register);
    }
4

1 回答 1

2

我解决了问题。。

 <input class="btn btn-primary btn-large" type="submit" value="Register"/> &nbsp; &nbsp;

我转换&nbsp;&#160;

问题解决了。

于 2013-09-10T15:33:43.133 回答