Struts Recipes 的合著者 Danilo Gurovich 從 George Franciscus 停止的地方開始,介紹了易于使用的創(chuàng)建動態(tài)選擇復(fù)選框的 Struts 訣竅。
在用戶界面設(shè)計(jì)中,復(fù)選框組不如它的同類 —— 多行選擇框那樣流行。它們基本上做的是同一件事,即選擇映射到單一 name 屬性的一組選項(xiàng)。當(dāng)在組中使用時,復(fù)選框執(zhí)行的功能實(shí)際與多行選擇框一樣,但是它們占據(jù)的屏幕空間更多。當(dāng)希望用戶在選擇一個或多個選項(xiàng)之前能夠看到所有選項(xiàng)的時候,這會很有好處。
/** * A simple Action for Checkbox test. * * @author Danilo Gurovich */ public final class CheckboxTestAction extends Action { // -------------------------- OTHER METHODS --------------------------
/** * The execute method * * @param mapping ActionMapping * @param form CheckboxTestForm * @param request HttpServletRequest * @param response HttpServletRespons * @return success to the confirmation page * @throws ServletException not thrown, but could be! * @throws Exception ditto. */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, Exception {
//Save the htmlString in the session for later... HttpSession session = request.getSession(); session.setAttribute(CheckboxConstants.MOUNTAINS, selectedMountains);