Hi, 
based on the output of phase 1 I put together a proposal on how to 
divide the functionality into context tools and how to name the methods.
I grouped the functionality into 5 tools with related methods. Having
several tools leads to simpler methods names. 
I find this more elegant than having one tool with long decriptive method
names. I have added examples to give you an impression of how methods 
typically would be applied in a template.

I am looking forward to your feedback.

Gabe

PS: Please refer to version 0.3 of the API draft for more details about 
each method. I have not duplicated this information here.


-------------------------------------------------------------------------------
PROPOSAL

Context Tools for Velocity for Struts, Phase 2
----------------------------------------------


Tool 1) Handling of URLs
------------------------

Class: org.apache.velocity.tools.struts.LinkTool

Recommended name in context: link

Methods:

    public LinkTool setPath(String path)

    public LinkTool setAction(String action) 

    public LinkTool setForward(String forward)

    public LinkTool setAbsolute(String path)

    public LinkTool addQueryData(String key, Object value)

    public String getPath()

    public String getQueryData()

    public String getServerPath()

    public String getBaseRef()

    public String toString()

Examples:

    - A form action
    <form name="login" action='$link.setAction("login")'>
    produces something like
    <form name="login" action="/myapp/actions/loginaction">

    - A HREF with a forward
    <a href='$link.setForward("home")'>Home</a>
    produces something like
    <a href="/myapp/templates/index.vm">
        
    - A HREF with an absolute URL
    <a href='$link.setAbsolute("/templates/login/index.vm")'></a>
    produces something like
    <a href="http://myserver:port/myapp/templates/login/index.vm";>Login Page</a>
   
    - Create a <base> tag    
    <base href="$link.baseRef()">
    produces something like
    <base href="/myapp/templates/login/index.vm">




Tool 2) Message Resources
-------------------------

Class: org.apache.velocity.tools.struts.MessageTool

Recommended name in context: msg

Methods:

    public String get(String key)

    public String get(String key, Object args[])

    public boolean exists(String key)
    
    public Locale getLocale()

Examples:

    - A simple internationalized output string
    $msg.login014     # equivalent to $msg.get("login014")

    - A submit button with an internationalized label
    <input type="submit" name="newbutton" value='$msg.get("view35.new")'/>
    renders something like
    <input type="submit" name="newbutton" value='Neuer Patient anmelden'/>




Tool 3) Error Handling
----------------------

Class: org.apache.velocity.tools.struts.ErrorsTool

Recommended name in context: errors

Methods:

    public boolean exists() 

    public int getSize() 

    public int getSize(String property) 

    public HashMap getAll() 

    public HashMap get(String property) 

Examples:

    - To output all queued error messages:
    #if ($errors.exists() )
        <p>There are $errors.size() errors. Please verify your input.</p>    
        <ul>
        #foreach ($e in $errors.all() )
            <li>$e</li>
        #end
        </ul>
    #end

    - To output all queued error messages for a specific property 'password':
    #if ($errors.exists() )
        <ul>
        #foreach ($e in $errors.password )
            <li>$e</li>
        #end
        </ul>
    #end





Tool 4) Action Messages
-----------------------

Class: org.apache.velocity.tools.struts.MessagesTool

Recommended name in context: msgs

Methods: 

    public boolean exists();

    public int getSize();

    public int getSize(String property);

    public HashMap getAll();

    public HashMap get(String property);

Examples:

    - To output all queued action messages:
    #if ($msgs.exists() )
        <p>There are $msgs.size() messages.</p>    
        <ul>
        #foreach ($m in $msgs.all() )
            <li>$m</li>
        #end
        </ul>
    #end

    - To output all queued action messages for a specific property 'password':
    #if ($msgss.exists() )
        <ul>
        #foreach ($m in $msgs.password )
            <li>$m</li>
        #end
        </ul>
    #end

    
 
Tool 5) Action Form
-------------------

Class: org.apache.velocity.tools.struts.FormTool

Recommended name in context: form

Methods:

    public ActionForm getForm()      // was getActionForm()
 
    public String getCancelName()    // was getCancelMagicName()
    
    public String getToken()

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to