FileDocCategorySizeDatePackage
UserListAction.javaAPI DocExample1784Fri Oct 01 14:16:56 BST 2004com.oreilly.strutsckbk.ch14

UserListAction

public class UserListAction extends com.oroad.stxx.action.Action

Fields Summary
Constructors Summary
Methods Summary
public ActionForwardexecute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

 
 
        List usersList = (List) getServlet().getServletContext().getAttribute("users");
        
        //create a new XML document for this Action with the root 
        //element of "userList" 
        Document document = 
        new Document(new Element("userList")); 
 
        //add some data to the XML document so that the Action 
        //will produce XML in the form 
        Element users = new Element("users"); 
        
        for (Iterator k=usersList.iterator(); k.hasNext(); ) {
            Element user = new Element("user"); 
            Element name = new Element("name");
            User u = (User) k.next();
            name.addContent(new Element("firstname").setText(u.getFirstName())); 
            name.addContent(new Element("lastname").setText(u.getLastName())); 
            user.addContent(name);
            user.addContent(new Element("email").setText(u.getEmail())); 

            // add the user
            users.addContent(user);             
        }
  
        // add to the root element and save the document
        document.getRootElement().addContent(users); 
        saveDocument(request, document); 
 
        return mapping.findForward("success");