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 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  Locale loc
           
protected  MessageContext msgContext
           
protected  Output output
           
protected  Context session
           
 
Fields inherited from interface org.mentawai.core.Action
ACCESSDENIED, ADD, AJAX, ALREADY, BACK, BLOCKED, CREATED, EDIT, ERROR, EXCEPTION, HTML, INDEX, JSON, JSP, LIST, LOGIN, MAIN, NEXT, NOT_FOUND, NULL, REMOVED, SHOW, STREAM, SUCCESS, TEST, UPDATED, XML
 
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(String error_id)
          Adds an error to the action with the given number.
 void addError(String field, int error_id)
          Adds an error to the action with the given number for the given field.
 void addError(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(String error_id, Map<String,String> tokens)
           
 void addError(String field, Message error)
          Adds an error to the action for the given field.
 void addError(String error_id, MessageContext msgContext)
          Adds an error to the action with the given number and context.
 void addError(String field, String error_id)
          Adds an error to the action with the given number for the given field.
 void addError(String field, String error_id, Map<String,String> tokens)
           
 void addError(String field, 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, boolean flash)
           
 void addMessage(int msg_id, MessageContext msgContext)
          Adds a message to the action with the given number and context.
 void addMessage(int msg_id, MessageContext msgContext, boolean flash)
           
 void addMessage(Message msg)
          Adds an message to the action.
 void addMessage(Message msg, boolean flash)
           
 void addMessage(String msg_id)
          Adds a message to the action with the given number.
 void addMessage(String msg_id, boolean flash)
           
 void addMessage(String msg_id, Map<String,String> tokens)
           
 void addMessage(String msg_id, Map<String,String> tokens, boolean flash)
           
 void addMessage(String msg_id, MessageContext msgContext)
          Adds a message to the action with the given number and context.
 void addMessage(String msg_id, MessageContext msgContext, boolean flash)
           
 void adhere()
          Adhere to the session, so the instance of this action will persist until disjoin is called.
 void ajax(Object value)
          Shortcut for output.setValue(AjaxConsequence.KEY, value)
 Context application()
           
 void commit()
           
 void commit(String trans)
           
 Context cookies()
           
 void disjoin()
          Remove this action from session and discard its instance losing all state (instance variables) associated with it.
 String execute()
           
 Object findValue(String key)
           
static Object findValue(String key, Action action)
           
 Context getApplication()
          Gets this action application context.
 String getContextPath()
           
 Context getCookies()
          Gets the cookie context for this action.
 String getError(String field)
           
 Input getInput()
          Gets the action input.
 Locale getLocale()
          Gets the use locale for this action.
 String getLocalizedText(String key)
           
 String getLocalizedText(String key, boolean noPrefix)
           
static Map<String,String> getMessageTokens(Action action, String field)
           
protected  Map<String,String> getMessageTokens(String field)
          This method will generate dynamic tokens for the success/error messages (dynamic messages).
 Output getOutput()
          Gets the action output.
 String getPrettyURL(String action, String method, String... params)
           
 Context getSession()
          Gets this action session context.
 Locale getSessionLocale()
           
<E> E
getSessionObj()
           
 Locale getUserLocale()
           
<E> E
getUserSession()
           
protected  boolean hasError()
          Checks if any error has been thrown into the action.
 void init()
           
static void init(Action action)
           
 Input input()
           
 boolean isAjaxRequest()
           
static boolean isAjaxRequest(Input input)
           
 boolean isEmpty(String s)
           
 boolean isGet()
           
static boolean isGet(Action action)
           
 boolean isLogged()
           
 boolean isPost()
           
static boolean isPost(Action action)
           
 boolean isPrettyURL()
           
 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 redir(String url)
          Shortcut for output.setValue(Redirect.REDIRURL_PARAM, "url");
Use redir() consequence for ActionConfig

Example:
In Action:
redir("some.jsp?someparam=somevalue");

In ApplicationManager:
action("someAction.mtw").redir();
 void replaceSessionObj(Object newUser)
           
 void replaceUserSession(Object newUser)
           
 void rollback()
           
 void rollback(String trans)
           
 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(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 setSessionGroup(Enum<?> e)
           
 void setSessionGroup(String group)
           
 void setSessionGroups(Enum<?>... es)
           
 void setSessionGroups(String... groups)
           
 void setSessionLocale(Locale loc)
           
 void setSessionLocale(String locale)
           
 void setSessionObj(Object user)
           
 void setSessionUser(Object user)
           
 void setUserSession(Object user)
           
 void stream(Object value)
           
 void stream(Object value, int length)
           
 void stream(Object value, String filename)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

msgContext

protected MessageContext msgContext

input

protected Input input

output

protected Output output

session

protected Context session

application

protected Context application

cookies

protected Context cookies

loc

protected Locale loc
Constructor Detail

BaseAction

public BaseAction()
Creates a BaseAction.

Method Detail

init

public static void init(Action action)

init

public void init()

isEmpty

public boolean isEmpty(String s)

getPrettyURL

public String getPrettyURL(String action,
                           String method,
                           String... params)

isPrettyURL

public boolean isPrettyURL()

commit

public void commit()
            throws Exception
Throws:
Exception

commit

public void commit(String trans)
            throws Exception
Throws:
Exception

rollback

public void rollback()
              throws Exception
Throws:
Exception

rollback

public void rollback(String trans)
              throws Exception
Throws:
Exception

isPost

public boolean isPost()

isGet

public boolean isGet()

isPost

public static boolean isPost(Action action)

isGet

public static boolean isGet(Action action)

isAjaxRequest

public boolean isAjaxRequest()

isAjaxRequest

public static boolean isAjaxRequest(Input input)

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

hasError

protected boolean hasError()
Checks if any error has been thrown into the action. Or in the action that called this action in the case of a Chain.

Since:
1.16

getMessageTokens

public static Map<String,String> getMessageTokens(Action action,
                                                  String field)

getMessageTokens

protected Map<String,String> getMessageTokens(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(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(String msg_id,
                       boolean flash)

addMessage

public void addMessage(String msg_id,
                       Map<String,String> tokens)

addMessage

public void addMessage(String msg_id,
                       Map<String,String> tokens,
                       boolean flash)

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.

addMessage

public void addMessage(int msg_id,
                       boolean flash)

addError

public void addError(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(String error_id,
                     Map<String,String> tokens)

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(String field,
                     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

getError

public String getError(String field)

addError

public void addError(String field,
                     String error_id,
                     Map<String,String> tokens)

addError

public void addError(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(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(String msg_id,
                       MessageContext msgContext,
                       boolean flash)

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.

addMessage

public void addMessage(int msg_id,
                       MessageContext msgContext,
                       boolean flash)

addError

public void addError(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(String field,
                     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(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.

addMessage

public void addMessage(Message msg,
                       boolean flash)

addError

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

Parameters:
error - The error object.

addError

public void addError(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(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

getLocalizedText

public String getLocalizedText(String key)

getLocalizedText

public String getLocalizedText(String key,
                               boolean noPrefix)

getLocale

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

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

getSessionObj

public <E> E getSessionObj()

getUserSession

public <E> E getUserSession()

getUserLocale

public 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 String execute()
               throws Exception
Throws:
Exception

ajax

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

Parameters:
value -
Since:
1.13

stream

public void stream(Object value)

stream

public void stream(Object value,
                   int length)

stream

public void stream(Object value,
                   String filename)

redir

public void redir(String url)
Shortcut for output.setValue(Redirect.REDIRURL_PARAM, "url");
Use redir() consequence for ActionConfig

Example:
In Action:
redir("some.jsp?someparam=somevalue");

In ApplicationManager:
action("someAction.mtw").redir();

Parameters:
url -

getContextPath

public 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 Locale loc()

findValue

public static Object findValue(String key,
                               Action action)

findValue

public Object findValue(String key)

setSessionObj

public void setSessionObj(Object user)

setSessionUser

public void setSessionUser(Object user)

setSessionGroup

public void setSessionGroup(Enum<?> e)

setSessionGroups

public void setSessionGroups(Enum<?>... es)

setSessionGroup

public void setSessionGroup(String group)

setSessionGroups

public void setSessionGroups(String... groups)

getSessionLocale

public Locale getSessionLocale()

setSessionLocale

public void setSessionLocale(Locale loc)

setSessionLocale

public void setSessionLocale(String locale)

setUserSession

public void setUserSession(Object user)

replaceSessionObj

public void replaceSessionObj(Object newUser)

replaceUserSession

public void replaceUserSession(Object newUser)


Copyright © 2013. All Rights Reserved.