MultiselectInterceptorÀ¹½ØÆ÷¼ò½é
¸ÃÀ¹½ØÆ÷´¦ÀídefaultStackµÚÊ®¶þµÄλÖã¬ÊÇÓÃÓÚ´¦Àíselect±êǩûÓÐÒ»¸öoption±»Ñ¡ÖеÄÇé¿ö£¬Õâ¸öÀ¹½ØÆ÷µÄÂß¼ÓëCheckboxInterceptÀ¹½ØÆ÷·Ç³£ÀàËÆ£¬¼¸ºõÊÇһģһÑùµÄ¡£
µ±Ò»¸öselect±êÇ©(multiple="multiple")ûÓÐÒ»¸öoption±»Ñ¡ÖеÄʱºò¾ÍÏ൱ÓÚûÓÐÕâ¸öselect±êÇ©£¬Õâ¾Í³öÏÖÁËÓëcheckboxÀàËƵÄÇé¿ö¡£
ÒòΪ¸ÃÀ¹½ØÆ÷ÓëCheckboxInterceptorÀ¹½ØÆ÷¼¸ºõÊÇÒ»ÑùµÄ£¬ËùÒÔÕâÀï¼òµ¥½²Ò»Ï£º
±í1
public String intercept(ActionInvocation actionInvocation) throws Exception { Map parameters = actionInvocation.getInvocationContext().getParameters();//»ñÈ¡ÇëÇó²ÎÊýMap Map<String, Object> newParams = new HashMap<String, Object>(); Set<String> keys = parameters.keySet();//ÇëÇó²ÎÊýkey¼¯ºÏ for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) { String key = iterator.next(); if (key.startsWith("__multiselect_")) {//ÅжÏkeyÊÇ·ñÒÔ__multiselect_¿ª¹Ø String name = key.substring("__multiselect_".length()); //´ÓÇëÇó²ÎÊýMapÖÐÒƳöµ±Ç°²ÎÊý iterator.remove(); //Èç¹ûûÓÐÑ¡ÖеÄoption if (!parameters.containsKey(name)) { //Ìí¼ÓÒ»¸ö³¤¶ÈΪ0µÄString[]µ½newParamsÖÐ newParams.put(name, new String[0]); } } } //°ÑnewParamsÌí¼Óµ½ÇëÇó²ÎÊýMapÖÐ parameters.putAll(newParams); //µ÷ÓÃÏÂÒ»¸öÀ¹½ØÆ÷ return actionInvocation.invoke(); } |
Õâʱ¾Í²»×÷¹ý¶àµÄ½âÊÍÁË£¬Èç¹ûÓÐʲô¿´²»¶®µÄ¿ÉÒÔ²ÎÊýÉÏÒ»¸öCheckboxIntercepterÀ¹½ØÆ÷¡£