Java Reference
In-Depth Information
</tr>
</table>
</s:form>
RegisterActionBean
includes a validation method to validate the aliases:
@ValidationMethod(on="save")
public void
validateAliases(ValidationErrors errors) {
if
(sizeOf(user.getAliases()) != numberOfAliases) {
errors.addGlobalError(
new
SimpleError("Please enter all aliases."));
}
else
{
for
(String alias : user.getAliases()) {
if
(alias ==
null
) {
errors.addGlobalError(
new
SimpleError("Please enter all aliases."));
break
;
}
if
(userDao.findByUsername(alias) !=
null
) {
errors.addGlobalError(
new
SimpleError(alias + " is already taken."));
}
}
}
}
public
Resolution handleValidationErrors(ValidationErrors errors){
if
(errors.hasFieldErrors()) {
errors.addGlobalError(
new
SimpleError("All fields are required."));
}
return null
;
}
private int
sizeOf(List<?> list) {
return
(list ==
null
? 0 : list.size());
}
/
*
...
*
/
private
UserDao userDao = MockUserDao.getInstance();
}
Once the registration process is complete, either because the user has
filled out the aliases or chosen to have no aliases, the action bean redi-
rects to its
done
( ) event handler, which forwards to
reg_complete.jsp
:
<p>
Registration complete!
</p>
You may now
<s:link beanclass="stripesbook.action.LoginActionBean">
login
</s:link>
.
Search WWH ::
Custom Search