java - Displaying Validation Error Messages in Struts2 -
i new struts 2, have worked in struts 1 earlier.
how can bind error message ui component (e.g. text box) ? don't want error message global one.
for achieving same in struts 1:
in form validate method, used this:
actionerrors errors = new actionerrors(); if(username != null && username.length() <= 0) errors.add("username",new actionerror("error.username.required")); and in ui, displaying message:
<html:messages id="username" property="username"> <bean:write name="username"/> </html:messages> in struts 2, if extend action class actionsupport , use this:
addactionerror(gettext("please enter userid")); then seems global message can displayed in ui using:
<s:actionerror /> hence not sure how achieve same functionality in struts 2. kindly let me know on this.
the <s:fielderror> tag closest equivalent:
<s:fielderror fieldname="username" /> on java side you'd use validationaware.addfielderror add field-specific messages:
public class anyaction extends actionsupport { public void validate() { addfielderror("username", "user id required"); } } that said, low-level validations, i'd stick default xml-based mechanism when possible, since lot of work you, , makes working i18n/properties little easier.
Comments
Post a Comment