jsp - Not displaying error message for a select drop down in Struts 2 -
i have following code
action:
private string yoursearchengine; private string selectedusergroupid; //with both getter , setter. public void validate(){ if("-1".equals(getyoursearchengine())){ addfielderror("yoursearchengine", gettext("select search engine")); addresslist.add("select search engine"); } if("-1".equals(getselectedusergroupid())){ addfielderror("selectedusergroupid", "select user group"); addresslist.add("select user group"); }
jsp page:
<s:select label="search engine:" headerkey="-1" headervalue="select search engines" list="searchengine" name="yoursearchengine" id="yoursearchengine" value="defaultsearchengine" tooltip="select search engines" /> <s:select label = "user group:" list = "usergrouplist" listkey = "usergroupid" listvalue = "usergroup" name = "selectedusergroupid" id="selectedusergroupid" headerkey="-1" headervalue="select group" tooltip="select group" ></s:select>
when submit form , value -1
, not display error message. can see addfielderror
code run addresslist
populated.
but not displaying error message.
by default struts2 uses xhtml
theme. theme designed display field errors on input elements bound action. if errors aren't displayed make sure have used xhtml
theme, or can add explicitely theme
attribute each select tag or form tag. can configure theme used default using struts constant.
<s:select label="search engine:" headerkey="-1" headervalue="select search engines" list="searchengine" name="yoursearchengine" id="yoursearchengine" value="defaultsearchengine" tooltip="select search engines" theme="xhtml" /> <s:select label = "user group:" list = "usergrouplist" listkey = "usergroupid" listvalue = "usergroup" name = "selectedusergroupid" id="selectedusergroupid" headerkey="-1" headervalue="select group" tooltip="select group" theme="xhtml" />
see can specify theme
in struts tags. specifying theme struts 2 should use.
you can specify theme on per struts 2 tag basis or can use 1 of following methods specify theme struts 2 should use:
- the
theme
attribute on specific tag- the
theme
attribute on tag's surrounding form tag- the page-scoped attribute named
"theme"
- the request-scoped attribute named
"theme"
- the session-scoped attribute named
"theme"
- the application-scoped attribute named
"theme"
- the
struts.ui.theme
property instruts.properties
(defaultsxhtml
)
to make effective on page make sure input
result configured action defaultstack
of interceptors.
Comments
Post a Comment