org.mentawai.core
Class BaseAction

java.lang.Object
  extended by org.mentawai.core.BaseAction
All Implemented Interfaces:
Action, StickyAction
Direct Known Subclasses:
BaseAjaxtagAction, BaseLoginAction, LogoutAction, ProtectedBaseAction, SingleInstanceBaseAction

public abstract class BaseAction
extends java.lang.Object
implements StickyAction

The abstract base implementation of a Mentawai action. It also privides access to input, output, session context and application context through protected data members.

Author:
Sergio Oliveira

Field Summary
protected  Context application
           
protected  Context cookies
           
protected  Input input
           
protected  java.util.Locale loc
           
protected  Output output
           
protected  Context session
           
 
Fields inherited from interface org.mentawai.core.Action
ALREADY, BLOCKED, CREATED, ERROR, INDEX, JSP, LIST, MAIN, NULL, REMOVED, SHOW, SUCCESS, TEST, UPDATED
 
Constructor Summary
BaseAction()
          Creates a BaseAction.
 
Method Summary
 void addError(int error_id)
          Adds an error to the action with the given number.
 void addError(int error_id, MessageContext msgContext)
          Adds an error to the action with the given number and context.
 void addError(Message error)
          Adds an error to the action.
 void addError(java.lang.String error_id)
          Adds an error to the action with the given number.
 void addError(java.lang.String field, int error_id)
          Adds an error to the action with the given number for the given field.
 void addError(java.lang.String field, int error_id, MessageContext msgContext)
          Adds an error to the action with the given number and context for the given field.
 void addError(java.lang.String field, Message error)
          Adds an error to the action for the given field.
 void addError(java.lang.String error_id, MessageContext msgContext)
          Adds an error to the action with the given number and context.
 void addError(java.lang.String field, java.lang.String error_id)
          Adds an error to the action with the given number for the given field.
 void addError(java.lang.String field, java.lang.String error_id, MessageContext msgContext)
          Adds an error to the action with the given number and context for the given field.
 void addMessage(int msg_id)
          Adds a message to the action with the given number.
 void addMessage(int msg_id, MessageContext msgContext)
          Adds a message to the action with the given number and context.
 void addMessage(Message msg)
          Adds an message to the action.
 void addMessage(java.lang.String msg_id)
          Adds a message to the action with the given number.
 void addMessage(java.lang.String msg_id, MessageContext msgContext)
          Adds a message to the action with the given number and context.
 void adhere()
          Adhere to the session, so the instance of this action will persist until disjoin is called.
 void ajax(java.lang.Object value)
          Shortcut for output.setValue(AjaxConsequence.KEY, value)
 Context application()
           
 Context cookies()
           
 void disjoin()
          Remove this action from session and discard its instance losing all state (instance variables) associated with it.
 java.lang.String execute()
           
 java.lang.Object findValue(java.lang.String key)
           
static java.lang.Object findValue(java.lang.String key, Action action)
           
 Context getApplication()
          Gets this action application context.
 java.lang.String getContextPath()
           
 Context getCookies()
          Gets the cookie context for this action.
 Input getInput()
          Gets the action input.
 java.util.Locale getLocale()
          Gets the use locale for this action.
static java.util.Map<java.lang.String,java.lang.String> getMessageTokens(Action action, java.lang.String field)
           
protected  java.util.Map<java.lang.String,java.lang.String> getMessageTokens(java.lang.String field)
          This method will generate dynamic tokens for the success/error messages (dynamic messages).
 Output getOutput()
          Gets the action output.
 Context getSession()
          Gets this action session context.
 java.util.Locale getUserLocale()
           
 java.lang.Object getUserSession()
           
 Input input()
           
 boolean isEmpty(java.lang.String s)
           
 boolean isLogged()
           
 boolean isPost()
           
static boolean isPost(Action action)
           
 java.util.Locale loc()
           
 void onRemoved()
          This method will be called if the session has expired or if it has been invalidated and there are sticky actions still sticked to the session.
 Output output()
           
 void replaceUserSession(java.lang.Object newUser)
           
 Context session()
           
 void setApplication(Context context)
          Sets the application context for this action.
 void setCookies(Context context)
          Sets the cookie context for this action.
 void setInput(Input input)
          Sets the input for this action.
 void setLocale(java.util.Locale loc)
          Sets the user locale for this action.
static void setMessageContext(MessageContext msgContext)
          Sets a fixed message context for all actions derived from BaseAction.
 void setOutput(Output output)
          Sets the output for this action.
 void setSession(Context context)
          Sets the session context for this action.
 void setUserSession(java.lang.Object user)
           
 void stream(java.lang.Object value)
           
 void stream(java.lang.Object value, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

input

protected Input input

output

protected Output output

session

protected Context session

application

protected Context application

cookies

protected Context cookies

loc

protected java.util.Locale loc
Constructor Detail

BaseAction

public BaseAction()
Creates a BaseAction.

Method Detail

isEmpty

public boolean isEmpty(java.lang.String s)

isPost

public boolean isPost()

isPost

public static boolean isPost(Action action)

setMessageContext

public static void setMessageContext(MessageContext msgContext)
Sets a fixed message context for all actions derived from BaseAction.

Parameters:
msgContext - The message context to use for all actions.
Since:
1.1.2

getMessageTokens

public static java.util.Map<java.lang.String,java.lang.String> getMessageTokens(Action action,
                                                                                java.lang.String field)

getMessageTokens

protected java.util.Map<java.lang.String,java.lang.String> getMessageTokens(java.lang.String field)
This method will generate dynamic tokens for the success/error messages (dynamic messages). It will basicaly place the the Input values and the Output values as tokens. The output values precedence over the input values, in other words, output values override input values.

Parameters:
field - The field to which the tokens refer to (you can pass null if the tokens do not refer to any field in particular
Returns:
A map with the tokens to use for the dynamic message

addMessage

public void addMessage(java.lang.String msg_id)
Adds a message to the action with the given number.

Parameters:
msg_id - The id of the message to show.
Since:
1.1.1

addMessage

public void addMessage(int msg_id)
Adds a message to the action with the given number.

Parameters:
msg_id - The id of the message to show.

addError

public void addError(java.lang.String error_id)
Adds an error to the action with the given number.

Parameters:
error_id - The id of the error to show.
Since:
1.1.1

addError

public void addError(int error_id)
Adds an error to the action with the given number.

Parameters:
error_id - The id of the error to show.

addError

public void addError(java.lang.String field,
                     java.lang.String error_id)
Adds an error to the action with the given number for the given field.

Parameters:
field - The name of the field containing this error message.
error_id - The id of the error to show.
Since:
1.1.1

addError

public void addError(java.lang.String field,
                     int error_id)
Adds an error to the action with the given number for the given field.

Parameters:
field - The name of the field containing this error message.
error_id - The id of the error to show.

addMessage

public void addMessage(java.lang.String msg_id,
                       MessageContext msgContext)
Adds a message to the action with the given number and context.

Parameters:
msg_id - The id of the message to show.
msgContext - The MessageContext where the message is.
Since:
1.1.1

addMessage

public void addMessage(int msg_id,
                       MessageContext msgContext)
Adds a message to the action with the given number and context.

Parameters:
msg_id - The id of the message to show.
msgContext - The MessageContext where the message is.

addError

public void addError(java.lang.String error_id,
                     MessageContext msgContext)
Adds an error to the action with the given number and context.

Parameters:
error_id - The id of the error to show.
msgContext - The MessageContext where the error is.
Since:
1.1.1

addError

public void addError(int error_id,
                     MessageContext msgContext)
Adds an error to the action with the given number and context.

Parameters:
error_id - The id of the error to show.
msgContext - The MessageContext where the error is.

addError

public void addError(java.lang.String field,
                     java.lang.String error_id,
                     MessageContext msgContext)
Adds an error to the action with the given number and context for the given field.

Parameters:
field - The name of the field containing this error message.
error_id - The id of the error to show.
msgContext - The MessageContext where the error is.
Since:
1.1.1

addError

public void addError(java.lang.String field,
                     int error_id,
                     MessageContext msgContext)
Adds an error to the action with the given number and context for the given field.

Parameters:
field - The name of the field containing this error message.
error_id - The id of the error to show.
msgContext - The MessageContext where the error is.

addMessage

public void addMessage(Message msg)
Adds an message to the action.

Parameters:
msg - The message object.

addError

public void addError(Message error)
Adds an error to the action.

Parameters:
error - The error object.

addError

public void addError(java.lang.String field,
                     Message error)
Adds an error to the action for the given field.

Parameters:
field - The name of the field containing this error message.
error - The error object.
Since:
1.1

setInput

public void setInput(Input input)
Description copied from interface: Action
Sets the input for this action.

Specified by:
setInput in interface Action
Parameters:
input - the input to be set

setOutput

public void setOutput(Output output)
Description copied from interface: Action
Sets the output for this action.

Specified by:
setOutput in interface Action
Parameters:
output - the output to be set

setSession

public void setSession(Context context)
Description copied from interface: Action
Sets the session context for this action.

Specified by:
setSession in interface Action
Parameters:
context - The context to be set

setApplication

public void setApplication(Context context)
Description copied from interface: Action
Sets the application context for this action.

Specified by:
setApplication in interface Action
Parameters:
context - The context to be set

setCookies

public void setCookies(Context context)
Description copied from interface: Action
Sets the cookie context for this action.

Specified by:
setCookies in interface Action
Parameters:
context - The cookie context to be set

setLocale

public void setLocale(java.util.Locale loc)
Description copied from interface: Action
Sets the user locale for this action.

Specified by:
setLocale in interface Action
Parameters:
loc - The user locale to set.

getInput

public Input getInput()
Description copied from interface: Action
Gets the action input.

Specified by:
getInput in interface Action
Returns:
The action input

getOutput

public Output getOutput()
Description copied from interface: Action
Gets the action output.

Specified by:
getOutput in interface Action
Returns:
The action output

getSession

public Context getSession()
Description copied from interface: Action
Gets this action session context.

Specified by:
getSession in interface Action
Returns:
The session context

getApplication

public Context getApplication()
Description copied from interface: Action
Gets this action application context.

Specified by:
getApplication in interface Action
Returns:
The application context

getCookies

public Context getCookies()
Description copied from interface: Action
Gets the cookie context for this action.

Specified by:
getCookies in interface Action
Returns:
The cookie context

getLocale

public java.util.Locale getLocale()
Description copied from interface: Action
Gets the use locale for this action.

Specified by:
getLocale in interface Action
Returns:
The user locale

getUserSession

public java.lang.Object getUserSession()

getUserLocale

public java.util.Locale getUserLocale()

isLogged

public boolean isLogged()

adhere

public void adhere()
Description copied from interface: StickyAction
Adhere to the session, so the instance of this action will persist until disjoin is called.

Specified by:
adhere in interface StickyAction

disjoin

public void disjoin()
Description copied from interface: StickyAction
Remove this action from session and discard its instance losing all state (instance variables) associated with it.

Specified by:
disjoin in interface StickyAction

onRemoved

public void onRemoved()
Description copied from interface: StickyAction
This method will be called if the session has expired or if it has been invalidated and there are sticky actions still sticked to the session. This is very useful for clean up and will be called if your action calls adhere and forget to call disjoin, leaving the actiion instance forever in the session.

Specified by:
onRemoved in interface StickyAction

execute

public java.lang.String execute()
                         throws java.lang.Exception
Throws:
java.lang.Exception

ajax

public void ajax(java.lang.Object value)
Shortcut for output.setValue(AjaxConsequence.KEY, value)

Parameters:
value -
Since:
1.13

stream

public void stream(java.lang.Object value)

stream

public void stream(java.lang.Object value,
                   int length)

getContextPath

public java.lang.String getContextPath()
Returns:
String the ContextPath

input

public Input input()

output

public Output output()

session

public Context session()

application

public Context application()

cookies

public Context cookies()

loc

public java.util.Locale loc()

findValue

public static java.lang.Object findValue(java.lang.String key,
                                         Action action)

findValue

public java.lang.Object findValue(java.lang.String key)

setUserSession

public void setUserSession(java.lang.Object user)

replaceUserSession

public void replaceUserSession(java.lang.Object newUser)


Copyright © 2005 Mentawai Team. All Rights Reserved.