我希望将2个模型(用户和用户数据)组合起来获取请求参数,但结果我看到了一个空白屏幕。我的代码中有什么问题?
Register对象是ModelAttribute
users和userData模型有一些字段。
数据模型
public class Register {
private Users users;
private UserData userData;
//getters and setters
}
register.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"/>
<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);
}
答案 0 :(得分:2)
我解决了问题..
在
<input class="btn btn-primary btn-large" type="submit" value="Register"/>
我将
转换为 
问题解决了。