Groovy Documentation

org.grails.plugin.vaadin
[Groovy] Class VaadinRequest

java.lang.Object
  org.grails.plugin.vaadin.VaadinRequest

class VaadinRequest

An internal construct for mimicking a user's request to display a particular Vaadin 'page'. However note that this is in no way connected with the JavaEE ServletRequest.

The main benefit is that it brings to Vaadin familiar Grails concepts, i.e.: controllers, actions, views, params, models, flash

The intention is that anyone familiar with Grails should have no problem understanding how to put together a Vaadin project, since all the concepts are familiar. In fact, the standard scaffolded Vaadin Controllers are almost identical to the Grails controllers - they do all of the same things. The Vaadin Views actually create the Vaadin layouts and components.

Moreover, by using the controller/action paradigm, we can easily add standard browser-history behaviour, by automatically adding fragments such as '#book/show/15' to the browser URI whenever we call a Vaadin 'request'.

One might think: Vaadin is not a normal web Http Request/Response-type framework, why is it necessary to structure a Vaadin app in terms of 'requests'? The answer is that generally you will still want to identify a particular set of layouts and components as belonging to a particular 'page' or 'screen' of your user interface. E.g. a user's 'profile' screen, or the 'home' screen etc.

With the Vaadin 'request' and 'dispatcher' constructs, you can wire together such 'pages' (consisting of contollers and views) as easily as is currently possible with normal Grails applications.

See Grails g:link for the set of parameters available for a request. Note that this class also supports an 'instance' as a parameter, which is the actual domain instance (as opposed to an id or a set or params). This is one benefit of Vaadin over Grails Requests!

Authors:
Francis McKenzie


Nested Class Summary
static enum VaadinRequest.Type

The request can be a top-level browser page or error page, or an include within the page.

 
Field Summary
protected String action

protected Map attributes

protected String controllerName

protected boolean dispatched

Indicates if this request has been dispatched

protected boolean external

Indicates if this request has been redirected to external

protected Map flash

protected Map model

protected Map params

protected boolean redirected

Indicates if this request has been redirected

protected VaadinRequest.Type type

protected def uid

For debugging, a unique id for this instance

protected String url

protected Object view

protected boolean viewIsName

 
Property Summary
String fragment

This request's fragment equivalent

def log

Application vaadinApplication

Vaadin Application for this request

 
Constructor Summary
VaadinRequest(Application application)

Create an empty request

VaadinRequest(Application application, String fragment, VaadinRequest.Type type = Type.PAGE)

Create a request with specified fragment

VaadinRequest(Application application, Map props, VaadinRequest.Type type = Type.PAGE)

Create a request with the specified properties

 
Method Summary
protected void finishRequest(Object resultObj)

Updates the model after dispatching a request to a controller, but before calling the required view.

static Map fromFragment(String fragment)

Converts the specified fragment into request props - for example '#book/show/15'

String getAction()

The requested action - for example 'show'

Map getAttributes()

The request attributes - for example [foo:'bar']

String getController()

The requested controller - for example 'book'

Map getFlash()

The flash message and error - for example [message:"Book 15 created!"]

String getId()

The id of the domain instance - for example '15'

Object getInstance()

The domain instance itself - for example Book(15)

Map getModel()

The request model - for example [bookInstance:bookInstance]

Map getParams()

The request params - for example [id:15]

Map getProperties()

Get properties of this request.

VaadinRequest.Type getType()

If true, this is a browser page request.

String getUrl()

The external Url - only applies if this request has been redirected to external.

Object getView()

The requested view - could be Gsp name, Gsp text or any Vaadin Component.

String getViewFullName()

Gets view uri of this request (minus params), for example book/show.

boolean isDispatched()

Indicates if this request has been dispatched

boolean isExternal()

Indicates if this request has been redirected to an external Url

boolean isRedirected()

Indicates if this request has been redirected

boolean isViewIsName()

If true, view is a Gsp name.

void redirect(Map args)

Used by VaadinControllers to redirect the current 'request' to another controller or action.

void render(Object view)

Used by VaadinControllers to render a particular view.

void render(String view)

Used by VaadinControllers to render a particular view.

void render(Component view)

Used by VaadinControllers to render a particular view.

void render(Map args)

Used by VaadinControllers to render a particular view.

void setController(Object controller)

The requested controller - for example 'book'

protected void setId(String id)

Set the id this request - for example '15'

protected void setInstance(Object instance)

Set the domain instance for this request - for example Book(15)

protected void setParams(Map params)

Set the params for this request - for example [id:15]

void setProperties(Map props)

Set properties of this request

protected void startRequest(VaadinRequest activeRequest, String currentController, String defaultPage)

Initialises this 'request' based on the 'request' that is currently active, and using the specified set of defaults (in case neither this request or the active request have a particular property).

static String toFragment(Map props)

Converts this 'request' into a URI fragment - for example '#book/show/15'

String toString()

This request object represented as a string

VaadinRequest valueOf(String name)

Returns the enum constant of this type with the specified name.

VaadinRequest[] values()

Returns an array containing the constants of this enum type, in the order they are declared.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

action

protected String action


attributes

protected Map attributes


controllerName

protected String controllerName


dispatched

protected boolean dispatched
Indicates if this request has been dispatched


external

protected boolean external
Indicates if this request has been redirected to external


flash

protected Map flash


model

protected Map model


params

protected Map params


redirected

protected boolean redirected
Indicates if this request has been redirected


type

protected VaadinRequest.Type type


uid

protected def uid
For debugging, a unique id for this instance


url

protected String url


view

protected Object view


viewIsName

protected boolean viewIsName


 
Property Detail

fragment

String fragment
This request's fragment equivalent


log

def log


vaadinApplication

Application vaadinApplication
Vaadin Application for this request


 
Constructor Detail

VaadinRequest

VaadinRequest(Application application)
Create an empty request


VaadinRequest

VaadinRequest(Application application, String fragment, VaadinRequest.Type type = Type.PAGE)
Create a request with specified fragment


VaadinRequest

VaadinRequest(Application application, Map props, VaadinRequest.Type type = Type.PAGE)
Create a request with the specified properties


 
Method Detail

finishRequest

protected void finishRequest(Object resultObj)
Updates the model after dispatching a request to a controller, but before calling the required view. Called by VaadinDispatcher during the dispatch cycle. Also, sets the 'dispatched' field to true
Parameters:
resultObj - The new model (if returned by the controller)


fromFragment

static Map fromFragment(String fragment)
Converts the specified fragment into request props - for example '#book/show/15'
Parameters:
fragment - The URI fragment to convert into request props


getAction

String getAction()
The requested action - for example 'show'


getAttributes

Map getAttributes()
The request attributes - for example [foo:'bar']


getController

String getController()
The requested controller - for example 'book'


getFlash

Map getFlash()
The flash message and error - for example [message:"Book 15 created!"]


getId

String getId()
The id of the domain instance - for example '15'


getInstance

Object getInstance()
The domain instance itself - for example Book(15)


getModel

Map getModel()
The request model - for example [bookInstance:bookInstance]


getParams

Map getParams()
The request params - for example [id:15]


getProperties

Map getProperties()
Get properties of this request.
Returns:
This request as property map


getType

VaadinRequest.Type getType()
If true, this is a browser page request. Otherwise, is a request to render a frame within a page.


getUrl

String getUrl()
The external Url - only applies if this request has been redirected to external.


getView

Object getView()
The requested view - could be Gsp name, Gsp text or any Vaadin Component.


getViewFullName

String getViewFullName()
Gets view uri of this request (minus params), for example book/show.

Returns null if the view is a Gsp content string, or a Vaadin Component.

Note that if the view name starts with "/" then it is resolved using the root views directory. Otherwise "/vaadin/{controllerName}/" is prepended to the name.

Returns:
Uri of view, or null if the view is a Gsp content string, or a Vaadin Component.


isDispatched

boolean isDispatched()
Indicates if this request has been dispatched


isExternal

boolean isExternal()
Indicates if this request has been redirected to an external Url


isRedirected

boolean isRedirected()
Indicates if this request has been redirected


isViewIsName

boolean isViewIsName()
If true, view is a Gsp name. Otherwise, could be Gsp text or any Vaadin Component.


redirect

void redirect(Map args)
Used by VaadinControllers to redirect the current 'request' to another controller or action. Mimics the method of the same name provided to standard Grails controllers.

See Grails redirect for controllers

Parameters:
args - E.g. 'controller' or 'action' to redirect to


render

void render(Object view)
Used by VaadinControllers to render a particular view. Mimics the method of the same name provided to standard Grails controllers.

See Grails render for controllers

Parameters:
view - Either an args map containing view name as 'view', or Gsp content text, or a Vaadin Component.


render

void render(String view)
Used by VaadinControllers to render a particular view. Mimics the method of the same name provided to standard Grails controllers.

See Grails render for controllers

Parameters:
view - The view content text to render


render

void render(Component view)
Used by VaadinControllers to render a particular view. Mimics the method of the same name provided to standard Grails controllers.

See Grails render for controllers

Parameters:
view - The Vaadin Component to render


render

void render(Map args)
Used by VaadinControllers to render a particular view. Mimics the method of the same name provided to standard Grails controllers.

See Grails render for controllers

Parameters:
args - E.g. 'view' to render to, 'model' to use, etc.


setController

void setController(Object controller)
The requested controller - for example 'book'


setId

protected void setId(String id)
Set the id this request - for example '15'


setInstance

protected void setInstance(Object instance)
Set the domain instance for this request - for example Book(15)


setParams

protected void setParams(Map params)
Set the params for this request - for example [id:15]


setProperties

void setProperties(Map props)
Set properties of this request
Parameters:
props - New request properties


startRequest

protected void startRequest(VaadinRequest activeRequest, String currentController, String defaultPage)
Initialises this 'request' based on the 'request' that is currently active, and using the specified set of defaults (in case neither this request or the active request have a particular property).

This is called by the VaadinDispatcher at the beginning of the dispatch cycle. E.g. one of the things it does is to set the 'controller' for the new request to be the same as the 'controller' of the current active request, if it is not explicitly overridden in the request parameters.

Parameters:
activeRequest - The current active request (if any)
currentController - The default controller to use if neither this nor the active request have one
defaultPage - The default page to use if no controller is found in this request or the active request


toFragment

static String toFragment(Map props)
Converts this 'request' into a URI fragment - for example '#book/show/15'
params:
props The request properties
Returns:
The URI fragment corresponding to this 'request'


toString

String toString()
This request object represented as a string


valueOf

VaadinRequest valueOf(String name)
Returns the enum constant of this type with the specified name.


values

VaadinRequest[] values()
Returns an array containing the constants of this enum type, in the order they are declared.


 

Groovy Documentation