v寻找发表新闻的页面
Ø news menu定义
<Item name="NewsManagement" title="news.menu.title" action="/news/listItems" roles="manager"/>
ØStruts 定义
<action
path="/news/listItems"
type="com.blandware.atleap.webapp.action.news.ListNewsItemsAction"
name="newsItemForm"
scope="request"
roles="manager"
unknown="false"
validate="false"
>
<forward
name="listNewsItems"
path=".news.listItems"
redirect="false"
/>
</action>
Øtailes定义
<!-- News -->
<definition name=".news.listItems" extends=".coreLayout" role="manager">
<put name="titleKey" value="news.listItems"/>
<put name="content" value="/WEB-INF/pages/news/listItems.jsp" />
</definition>
v发表新闻Action
Ø <html:form action="news/callCreateItem" method="POST">
<html:submit styleClass="button"><bean:message key="button.create" /></html:submit>
</html:form>
Ø <action
path="/news/callCreateItem"
type="com.blandware.atleap.webapp.action.news.CallCreateNewsItemAction"
name="newsItemForm"
scope="request"
roles="manager"
unknown="false"
validate="false"
>
<forward
name="createNewsItem"
path=".news.createItem"
redirect="false"
/>
<forward
name="listNewsItems"
path="/news/listItems.do"
redirect="true"
/>
</action>
Ø com.blandware.atleap.webapp.action.news.CallCreateNewsItemAction
public final class CallCreateNewsItemAction extends BaseAction {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
request.getSession().removeAttribute(NewsModuleWebConstants.NEWS_ITEM_SUBMITTE
D_ACTION);
ContentLocaleManager contentLocaleManager = (ContentLocaleManager)
getBean(Constants.CONTENT_LOCALE_MANAGER_BEAN);
List contentLocales =
contentLocaleManager.listContentLocales(null).asList();
request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
// save transaction token in request
saveToken(request);
return mapping.findForward("createNewsItem");
}
}
Øtiles-config.xml中的定义
<definition name=".news.createItem" extends=".coreLayout" role="manager">
<put name="titleKey" value="news.createItem"/>
<put name="content" value="/WEB-INF/pages/news/createItem.jsp" />
<putList name="pageScripts">
<add value="/scripts/core/calendar.js"/>
</putList>
<putList name="pageStyles">
<add value="/styles/core/calendar.css"/>
</putList>
</definition>
Øatleap中的新闻填写需写两屏,这是第2屏的action
<html:form action="news/callCreateItemBody" method="POST" onsubmit="return validateForm(this);">
Ø第2屏的action
<action
path="/news/callCreateItemBody"
type="com.blandware.atleap.webapp.action.news.CallCreateNewsItemBodyAction"
name="newsItemForm"
scope="request"
input="inputForward"
roles="manager"
unknown="false"
validate="false"
>
<forward
name="inputForward"
path=".news.createItem"
redirect="false"
/>
<forward
name="createNewsItemBody"
path=".news.createItemBody"
redirect="false"
/>
<forward
name="listNewsItems"
path="/news/listItems.do"
redirect="true"
/>
</action>
Ø
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
request.getSession().removeAttribute(NewsModuleWebConstants.NEWS_ITEM_SUBMITTED_ACTION);
if ( isCancelled(request) ) {
return mapping.findForward("listNewsItems");
}
if ( request.getSession().getAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY) == null ) {
ContentLocaleManager contentLocaleManager = (ContentLocaleManager) getBean(Constants.CONTENT_LOCALE_MANAGER_BEAN);
List contentLocales = contentLocaleManager.listContentLocales(null).asList();
request.getSession().setAttribute(WebappConstants.CONTENT_LOCALES_COLLECTION_KEY, contentLocales);
}
NewsItemForm newsItemForm = (NewsItemForm) form;
if ( !WebappUtil.hasCorrectValues(newsItemForm.getTitleMap()) ) {
// title must be specified
ActionMessages errors = new ActionMessages();
errors.add("title", new ActionMessage("errors.required", getMessage(request, "newsItemForm.title")));
saveErrors(request, errors);
saveToken(request);
return mapping.getInputForward();
}
saveToken(request);
return mapping.findForward("createNewsItemBody");
}
}
Ø
<definition name=".news.createItemBody" extends=".coreLayout" role="manager">
<put name="titleKey" value="news.createItemBody"/>
<put name="content" value="/WEB-INF/pages/news/createItemBody.jsp" />
</definition>
Ø点击create按钮提交建立新闻请求后的action跳转
<html:form action="news/createItem" method="POST">
Ø建立新闻的action(关键)
<action
path="/news/createItem"
type="com.blandware.atleap.webapp.action.news.CreateNewsItemAction"
name="newsItemForm"
scope="request"
input="inputForward"
roles="manager"
unknown="false"
validate="true"
>
<forward
name="inputForward"
path=".news.createItem"
redirect="false"
/>
<forward
name="listNewsItems"
path="/news/listItems.do"
redirect="true"
/>
<forward
name="callCreateItem"
path=".news.createItem"
redirect="false"
/>
</action>