jakarta-ecs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jnilson" <jnil...@verilytics.com>
Subject Fw: additions to ConcreteElement
Date Tue, 13 Nov 2001 22:21:02 GMT
Forgot to send render context, copied below:

Briefly the idea of RenderContext is to send to the object's output method a "context", specifically
a HttpServletRequest:

A dependency upon HttpServletRequest might be an issue for some user's as you will have to
be running ECS someplace that has access to servlets. But this is very common, it seems to
me.


Does it seem likely that users of ECS will not like adding such a dependecy? If so there are
many advantages to sending a rendercontext, namely you can start to add the ability to have
elements "look" differently depending upon the context. Here is an example from my code that
shows elements of a select box depending upon things in the RenderContext:

          public void output(RenderContext context){
            //this could be optimized to store the result in the user object until the
            //user has updated
            XML user = (XML)context.getRequest().getAttribute("user");
            String selectedOption = context.getRequest().getParameter(mSelectName);

            XML selectBoxElement = (XML)user.getElement(mSelectName);

            if(selectBoxElement == null){
              selectBoxElement = new XML(mSelectName);
              if( mOptions != null && mOptions.length > 0 ){
                  for (int i = 0; i < mOptions.length; i++) {
                    String key = mOptions[i][0];
                    String text = mOptions[i][1];
                    setUserSelectBoxElements(user, mSelectName, key, text);
                  }
                selectBoxElement = (XML)user.getElement(mSelectName);
              }else{
                 user.addElement(mSelectName,selectBoxElement);
              }
            }






Thanks,


John Nilson

//////////////////////////////////////////////////////////////////
RenderContext.java looks like this:


package org.apache.ecs;

import java.io.*;
import javax.servlet.http.*;


public class RenderContext {

    private ByteArrayOutputStream bytearrayoutputstream;
    private BufferedOutputStream bufferedoutputstream;
    private HttpServletRequest mRequest = null;

    /*package private*/ RenderContext() {

        bytearrayoutputstream = new ByteArrayOutputStream();
        bufferedoutputstream = new BufferedOutputStream(bytearrayoutputstream);
        mRequest = null;
    }

    public RenderContext(HttpServletRequest req) {

        bytearrayoutputstream = new ByteArrayOutputStream();
        bufferedoutputstream = new BufferedOutputStream(bytearrayoutputstream);
        mRequest = req;
    }

    public BufferedOutputStream getOutput(){

        return bufferedoutputstream;
    }


    public HttpServletRequest getRequest(){
      return mRequest;
    }


    public String toString(){
    String s=null;
        try {

            bufferedoutputstream.flush();
            s = bytearrayoutputstream.toString();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }

        return s;

    }

    public void close(){
        try {

            bufferedoutputstream.close();
            bytearrayoutputstream.close();
        }catch (Exception ex) {

        }

    }

}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message