Class WebComponentProvider
java.lang.Object
com.vaadin.flow.server.communication.WebComponentProvider
- All Implemented Interfaces:
SessionlessRequestHandler,Serializable
Request handler that supplies the script/html of the web component matching
the given tag.
For internal use only. May be renamed or removed in a future release.
- Since:
- 2.0
- Author:
- Vaadin Ltd.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbootstrapNpm(boolean productionMode) protected StringgenerateNPMResponse(String tagName, VaadinRequest request, VaadinResponse response) Generate the npm response for the web component.booleanhandleRequest(VaadinRequest request, VaadinResponse response) Serves the script of an exported web component.protected booleanhandleWebComponentRequest(VaadinRequest request, VaadinResponse response) Handles a request for a web component script.booleanWhether bootstrap HTML fragment are cached based on component tag.voidsetCacheEnabled(boolean cacheEnabled) Enable / disable bootstrap HTML fragment caching based on component tag.
-
Constructor Details
-
WebComponentProvider
public WebComponentProvider()
-
-
Method Details
-
handleRequest
Serves the script of an exported web component. The script is the same for every user, so it is served without a session. A host page that loads the scripts of several web components in parallel then does not get a new session from each of them, leaving the browser with a cookie for a session other than the one its embedded UI was created in.Override
handleWebComponentRequest(VaadinRequest, VaadinResponse)to customize how the script is served.- Specified by:
handleRequestin interfaceSessionlessRequestHandler- Parameters:
request- the request to handleresponse- the response object to which a response can be written- Returns:
trueif a response has been written and no further request handlers should be called, otherwisefalse- Throws:
IOException- if an IO error occurred- Since:
- 25.4
-
handleWebComponentRequest
protected boolean handleWebComponentRequest(VaadinRequest request, VaadinResponse response) throws IOException Handles a request for a web component script. This is called without a session, so it must not depend onVaadinSession.getCurrent()or on the session lock.- Parameters:
request- the request to handleresponse- the response to write the script to- Returns:
trueif the request was handled,falseotherwise- Throws:
IOException- if writing the response fails- Since:
- 25.4
-
isCacheEnabled
public boolean isCacheEnabled()Whether bootstrap HTML fragment are cached based on component tag. Enabled by default.- Returns:
- true iff bootstrap fragment caching is enabled
- Since:
- 2.2
-
setCacheEnabled
public void setCacheEnabled(boolean cacheEnabled) Enable / disable bootstrap HTML fragment caching based on component tag. Calling this method has the side effect of always clearing the cache.- Parameters:
cacheEnabled- whether bootstrap fragments should be cached per tag- Since:
- 2.2
-
generateNPMResponse
protected String generateNPMResponse(String tagName, VaadinRequest request, VaadinResponse response) Generate the npm response for the web component.The script is served without a session, so this runs with no
VaadinSessionavailable. The result is cached per tag unless caching is disabled withsetCacheEnabled(boolean).- Parameters:
tagName- tag name of componentrequest- current VaadinRequestresponse- current VaadinResponse- Returns:
- npm response script
- Since:
- 2.2
-
bootstrapNpm
-