WebWork handles the processing of checkbox checkbox Action

xiaoxiao2021-03-06  45

WebWork's processing of the page, such as the form element like checkbox, if we just simply set the Boolean value of the field, just like the following processing method, such as If the user selects this check box, the browser will send "user.lockedout = true" in the query string, and OGNL executes action.getuser (). setLockedout (TRUE). If the user does not select the check box, the browser will not send the query string, so at the beginning, make sure that LockedOut is false: private boid setlockedout = false; public void setlockedout (Boolean Lockedout) {m_lockedout = lockedout;}

But more cases, we use it as a check (multiple options), there are two cases to set a collection with checkbox: Yi. CHECKBOX NAME stores many permissions in a STRING type set collection Checkbox's HTML is as follows: ratio, one user selection two, the browser will send this query string: user.priv = boss & user.priv = admin. OGNL will process the query string: action.getuser (). SetPriv (String [] {"boss", "admin"}). The method in action will be like this: set m_privileges = new hashset ();

Public void setpriv (string [] privs) {for (int i = 0; i * action with list collection: private list xlist = new xworklist (user.class) public list getXlist () {return xlist;} ii . * action with map collection: private map xmap = new xworkmap (user.class) public list getXMAP ) {RETURN XMAP;} III. * Action is handled in object [] array (note the length of the array must be determined in advance, can not dynamically change the size of the array): Private Object [] xaRray = new object [3] public object [] getxArray () {return xarray;}

The following is an example of a slightly complicated point to deepen the understanding of the List collection process, and other processing methods are similar to the same work. MultiSelect.jsp file <% @ Page PageEncoding = "GB2312" ContentType = "text / html; charset = GB2312"%> <% @ taglib prefix = "ww" URI = "Webwork"%>

<% int i = 0;%> <% string cname = "xlist [" i "] .id "; i ;%>
multiselect_result.jsp file <% @ Page PageEncoding = "GB2312" ContentTyPe = "text / html; charset = GB2312"%> <% @ Taglib prefix = "ww" uri = "Webwork"%> < Body> Your choice is:

Multiselectrivity.java file

package com.wzj.rbac.webwork.action; import java.util.List; import com.opensymphony.xwork.Action; import com.opensymphony.xwork.util.XWorkList; import com.wzj.framework.spring.resource.BeanLocator Import com.wzj.rbac.serviceFacade.userService; import com.wzj.rbac.domain.object.user; / ** * @Desc checkbox Select Submit anction class * @Author chikai
* @Link chikai * @version $ multiselectrivity.java 2004-12-5 19:11:54 $ * @ ver $ project xwork * / public class multiseelectrically implements action {private final static String PRE_SUCCESS = "pre_success"; // the list of users private list ulist; // selected user private list xlist = new XWorkList (User.class); private UserService uService; // page to perform an action to determine private String actionEvent; public String Execute () throws exception {if (ActionEvent! = null && ActionEvent.equals ("Viewselect")) {for (int S = 0; s

XWork.xml file:

/ multiselect_result.jsp / multiselect.jsp < / xwork>

转载请注明原文地址:https://www.9cbs.com/read-84099.html

New Post(0)