Class HelloWorldConlet
java.lang.Object
org.jgrapes.core.internal.ComponentVertex
org.jgrapes.core.Component
org.jgrapes.webconsole.base.AbstractConlet<HelloWorldConlet.HelloWorldModel>
org.jgrapes.webconsole.base.freemarker.FreeMarkerConlet<HelloWorldConlet.HelloWorldModel>
org.jgrapes.webconlet.examples.helloworld.HelloWorldConlet
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
Example of a simple conlet.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Model with world’s state.Nested classes/interfaces inherited from class org.jgrapes.webconsole.base.AbstractConlet
AbstractConlet.ConletTrackingInfo
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final com.fasterxml.jackson.databind.ObjectMapper
The mapper.Fields inherited from class org.jgrapes.webconsole.base.AbstractConlet
TYPE_INSTANCE_SEPARATOR
-
Constructor Summary
ConstructorDescriptionHelloWorldConlet
(Channel componentChannel) Creates a new component with its channel set to the given channel. -
Method Summary
Modifier and TypeMethodDescriptionprotected Optional
<HelloWorldConlet.HelloWorldModel> createStateRepresentation
(Event<?> event, ConsoleConnection channel, String conletId) Creates an instance of the type that represents the conlet’s state, initialized with default values.protected void
doConletDeleted
(ConletDeleted event, ConsoleConnection channel, String conletId, HelloWorldConlet.HelloWorldModel conletState) Called byAbstractConlet.onConletDeleted(org.jgrapes.webconsole.base.events.ConletDeleted, org.jgrapes.webconsole.base.ConsoleConnection)
to propagate the event to derived classes.protected Set
<Conlet.RenderMode> doRenderConlet
(RenderConletRequestBase<?> event, ConsoleConnection channel, String conletId, HelloWorldConlet.HelloWorldModel conletState) Called byAbstractConlet.onAddConletRequest(AddConletRequest, ConsoleConnection)
andAbstractConlet.onRenderConletRequest(RenderConletRequest, ConsoleConnection)
to complete rendering the web console component.protected void
doUpdateConletState
(NotifyConletModel event, ConsoleConnection channel, HelloWorldConlet.HelloWorldModel conletModel) Called byAbstractConlet.onNotifyConletModel(org.jgrapes.webconsole.base.events.NotifyConletModel, org.jgrapes.webconsole.base.ConsoleConnection)
to complete handling the notification.void
onConsoleReady
(ConsoleReady event, ConsoleConnection connection) Trigger loading of resources when the console is ready.protected Optional
<HelloWorldConlet.HelloWorldModel> recreateState
(Event<?> event, ConsoleConnection channel, String conletId) Called when a previously created conlet (with associated state) is rendered in a new browser session for the first time.Methods inherited from class org.jgrapes.webconsole.base.freemarker.FreeMarkerConlet
doGetResource, fmConletModel, fmModel, fmModel, fmSessionModel, fmTypeModel, freemarkerConfig, processTemplate, processTemplate
Methods inherited from class org.jgrapes.webconsole.base.AbstractConlet
afterOnClosed, conletIds, conletIdsByConsoleConnection, conletViews, createNewState, doRemoveConletType, doSetLocale, generateInstanceId, l10nBundles, localizations, onAddConletRequest, onClosed, onConletDeleted, onConletResourceRequest, onDetached, onNotifyConletModel, onRenderConletRequest, onSetLocale, putInSession, readContent, readContent, removeState, resourceBundle, setPeriodicRefresh, stateFromSession, statesFromSession, supportedLocales, trackConlet, trackedConnections, type, typeFromId
Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
mapper
The mapper.
-
-
Constructor Details
-
HelloWorldConlet
Creates a new component with its channel set to the given channel.- Parameters:
componentChannel
- the channel that the component’s handlers listen on by default and thatManager.fire(Event, Channel...)
sends the event to
-
-
Method Details
-
onConsoleReady
@Handler public void onConsoleReady(ConsoleReady event, ConsoleConnection connection) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException Trigger loading of resources when the console is ready.- Parameters:
event
- the eventconnection
- the console connection- Throws:
TemplateNotFoundException
- the template not found exceptionMalformedTemplateNameException
- the malformed template name exceptionParseException
- the parse exceptionIOException
- Signals that an I/O exception has occurred.
-
createStateRepresentation
protected Optional<HelloWorldConlet.HelloWorldModel> createStateRepresentation(Event<?> event, ConsoleConnection channel, String conletId) throws IOException Description copied from class:AbstractConlet
Creates an instance of the type that represents the conlet’s state, initialized with default values.The default implementation returns
Optional.isEmpty()
, thus indicating that no state information is needed or available.This method should always be overridden if conlet instances have associated state.
- Overrides:
createStateRepresentation
in classAbstractConlet<HelloWorldConlet.HelloWorldModel>
- Parameters:
event
- the event, which may contain required information (seeAddConletRequest.properties()
)channel
- the console connection, sometimes required to send events to components that provide a backing storeconletId
- the conlet id calculated astype() + TYPE_INSTANCE_SEPARATOR + generateInstanceId(...)
- Returns:
- the state representation or
Optional.empty()
if none is required - Throws:
IOException
-
recreateState
protected Optional<HelloWorldConlet.HelloWorldModel> recreateState(Event<?> event, ConsoleConnection channel, String conletId) throws Exception Description copied from class:AbstractConlet
Called when a previously created conlet (with associated state) is rendered in a new browser session for the first time.The default implementation simply invokes
createStateRepresentation
and returns its result. Conlets with long-term state should retrieve their state from some storage. If state is returned, it is put in the browser session by the invoker.- Overrides:
recreateState
in classAbstractConlet<HelloWorldConlet.HelloWorldModel>
- Parameters:
event
- the eventchannel
- the console connectionconletId
- the conlet id- Returns:
- the state representation or
Optional.empty()
if none is required - Throws:
Exception
- if an exception occurs
-
doRenderConlet
protected Set<Conlet.RenderMode> doRenderConlet(RenderConletRequestBase<?> event, ConsoleConnection channel, String conletId, HelloWorldConlet.HelloWorldModel conletState) throws Exception Description copied from class:AbstractConlet
Called byAbstractConlet.onAddConletRequest(AddConletRequest, ConsoleConnection)
andAbstractConlet.onRenderConletRequest(RenderConletRequest, ConsoleConnection)
to complete rendering the web console component.The
- Specified by:
doRenderConlet
in classAbstractConlet<HelloWorldConlet.HelloWorldModel>
- Parameters:
event
- the eventchannel
- the channelconletId
- the component idconletState
- the conlet’s state; may benull
if the conlet doesn’t have associated state information- Returns:
- the rendered modes
- Throws:
Exception
- the exception
-
doConletDeleted
protected void doConletDeleted(ConletDeleted event, ConsoleConnection channel, String conletId, HelloWorldConlet.HelloWorldModel conletState) throws Exception Description copied from class:AbstractConlet
Called byAbstractConlet.onConletDeleted(org.jgrapes.webconsole.base.events.ConletDeleted, org.jgrapes.webconsole.base.ConsoleConnection)
to propagate the event to derived classes.- Overrides:
doConletDeleted
in classAbstractConlet<HelloWorldConlet.HelloWorldModel>
- Parameters:
event
- the eventchannel
- the channelconletId
- the web console component idconletState
- the conlet’s state; may benull
if the conlet doesn’t have associated state information- Throws:
Exception
- if a problem occurs
-
doUpdateConletState
protected void doUpdateConletState(NotifyConletModel event, ConsoleConnection channel, HelloWorldConlet.HelloWorldModel conletModel) throws Exception Description copied from class:AbstractConlet
Called byAbstractConlet.onNotifyConletModel(org.jgrapes.webconsole.base.events.NotifyConletModel, org.jgrapes.webconsole.base.ConsoleConnection)
to complete handling the notification.The default implementation does nothing.
- Overrides:
doUpdateConletState
in classAbstractConlet<HelloWorldConlet.HelloWorldModel>
- Parameters:
event
- the eventchannel
- the channelconletModel
- the conlet’s state; may benull
if the conlet doesn’t have associated state information- Throws:
Exception
-