J2EE學習筆記(6) Struts HTML Tags
來源:互聯網
上載者:User
HTML Tags
一些公用的tag attributes在HTMLTagLib裡的含義前後一致,它們是
name: ActionForm bean的執行個體名,如果name不存在,<html:form>所關聯的formBean會生效。
property: property既決定了產生的html的fieldname,也決定了該field的值 via formBean.getThisProperty
value: value決定了產生html的field的value,注意它不是bean的propertyName
<html:html>和普通<html>不同的是,1)自動加上hidden token 2)自動加上context_root
剩下的以後慢慢加。。。
訊息(錯誤)顯示
ActionMessages messages = new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("userForm.insert", info.getUserName());
messages.add("activationDate", new ActionMessage("userForm.active", info.getDateLength());
如下可以顯示所有訊息,並用<li>將它們放入一個list,再加上可定製的header/footer
<html:messages id="message" header="errors.header" footer="errors.footer">
<li><bean:write name="message"/></li>
</html:messages>
如下可以指定只顯示某種message
<html:messages id="message" property="<%= org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE %>">
<li><bean:write name="message"/></li>
</html:messages>
把Messages換成Errors就是錯誤顯示,為了簡便,經常一個<html:errors/>了事