Vaadin : How to change favicon? - vaadin

How can I change favicon of my pages in Vaadin ? I would like to change favicon of my pages but I have no idea where is the place to change it ? Has somebody experience on it ?

First, create a theme directory: /WebContent/VAADIN/themes/mynewtheme
Then, put your custom favicon.ico in this directory. You also need to set theme property in your application :
public class MyNewApplication extends Application {
#Override
public void init() {
...
...
setTheme("mynewtheme");
}
}

Here is a more detailed version of the similar Answer posted by Greg Ballot. My Answer here relates to Vaadin 7, current as of 7.5.3.
Custom Theme
In Vaadin 7.5, you can drop your favicon graphics image file into your own custom theme. If using the Vaadin plugin for various IDEs (NetBeans, Eclipse) or the Maven archetypes, a custom theme named mytheme should have already been created for you. Drop your image file into that mytheme folder.
The main part of your Vaadin 7 app, your subclass of UI, must specify that it uses your custom theme. Again, if using the IDE plugins and/or Maven archetype, this should have already been configured for you. The easiest way is an Java Annotation on the UI subclass.
#Theme ( "mytheme" ) // Tell Vaadin to apply your custom theme, usually a subclass of the Valo or Reindeer theme.
#Title ( "PowerWrangler" ) // Statically specify the title to appear in web browser window/tab.
#SuppressWarnings ( "serial" ) // If not serializing such as "sticky sessions" and such, disable compiler warnings about serialization.
#Push ( PushMode.AUTOMATIC ) // If using Push technology.
public class MyVaadinUI extends UI
{
…
Favicon Usage/Behavior Not Standard
Remember that favicon behavior is not standardized. Favicons developed haphazardly, mostly out of a sense of fun. The exact behavior depends on the particular browser and particular server. Other than the particular folder location, none of this is special to Vaadin.
Image File Formats
Originally the ICO file format was used exclusively. Since then most browsers have evolved to accept any of several formats including JPEG, TIFF, and PNG.
Image Size/Resolution
Originally favicons were intended to be very small bitmap icons. Some browsers have made various uses of the favicon in situations where you may want to provide a higher-resolution image. But remember that smaller files load faster without keeping your users waiting.
Favicon File Name
Some browsers or servers may handle other file names or name extensions, but I've found it easiest to name my file exactly favicon.ico -- even if using a different format! I usually use a PNG file but name it with the .ico extension. While I cannot guarantee this practice works one every server and browser, I’ve not encountered any problem.
Existing Favicon File
Recent versions of Vaadin have included a Vaadin-related icon in a favicon.ico file in a configured project. So you must replace that file with your own. In Vaadin 7.5.3 the file contains four sizes, the largest looking like this:
Older versions did not add a file, so you drop in your own.
IDE Screen Shots
Here are a pair of screen shots. One is the project (logical) view in NetBeans 8, while the other is a files (physical) view.

In case of custom icon name (Vaadin 7):
public class MyServlet extends VaadinServlet implements SessionInitListener {
#Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
getService().addSessionInitListener(this);
}
#Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
event.getSession().addBootstrapListener(new BootstrapListener() {
#Override
public void modifyBootstrapPage(BootstrapPageResponse response) {
response.getDocument().head()
.getElementsByAttributeValue("rel", "shortcut icon")
.attr("href", "./VAADIN/themes/mynewtheme/custom.ico");
response.getDocument().head()
.getElementsByAttributeValue("rel", "icon")
.attr("href", "./VAADIN/themes/mynewtheme/custom.ico");
}
#Override
public void modifyBootstrapFragment(BootstrapFragmentResponse response) {
}
});
}
}
EDIT
It is better to use the BootstrapListener as a static nested class: link

Vaadin 23.x (plain spring/war application, no springboot!):
Derive an implementation of com.vaadin.flow.component.page.AppShellConfigurator:
#Theme(value = "mytheme")
#PWA(name = "My application", shortName = "MyApp", iconPath = "icons/favicon.ico" )
public class AppShellConfiguratiorImpl implements AppShellConfigurator {
#Override
public void configurePage(AppShellSettings settings) {
settings.addFavIcon("icon", "icons/favicon.ico", "16x16");
}
}
And put your favicon.ico into src\main\webapp\icons (in order that it is encluded in <war-root>/icons/favicon.ico)
A servlet container (3.0 plus, e.g. Tomcat 8.5) will pick up this class automagically and load it.

Related

Vaadin #CssImport not working in jar dependency

I can't seem to get the #CssImport annotation working when the component class is in a separate jar. (Main web project is Vaadin 18)
I checked out the addon starter:
https://github.com/vaadin/addon-starter-flow
And adjusted the TheAddon class to add a css class name:
#CssImport("./theaddon.css")
public class TheAddon extends Div {
public TheAddon() {
setText("Hello");
addClassName("theaddon");
}
}
I then added the theaddon.css file to:
src\main\resources\META-INF\resources\frontend\theaddon.css
With the styles:
.theaddon {
color:Red;
}
However when I use the addon, I do not see the style applied. I do see the style if I extend the TheAddon class within my web project. So this leads me to believe there's some classpath magic that isn't happening correctly.
Argh - the issue was that the vaadin.whitelisted-packages property was set. Thus Vaadin was not scanning / finding the components when building the front-end. Correcting this property fixed it.

Rejecting published file request for file that has not been published. Tried all the options but didn't work

I am trying to implement a sample application where all the javascript (JS) & CSS files use many png files.
I referred many articles but they could not help me.
For all the png files, I get the following error,
Sample error part,
Jan 29, 2019 3:25:22 PM com.vaadin.server.communication.PublishedFileHandler handleRequest
WARNING: Rejecting published file request for file that has not been published: css/images/chartIcon.png
Jan 29, 2019 3:25:22 PM com.vaadin.server.communication.PublishedFileHandler handleRequest
WARNING: Rejecting published file request for file that has not been published: css/images/sunburst.png
Jan 29, 2019 3:25:22 PM com.vaadin.server.communication.PublishedFileHandler handleRequest
WARNING: Rejecting published file request for file that has not been published: css/images/treemap.png
Jan 29, 2019 3:25:40 PM com.vaadin.server.communication.PublishedFileHandler handleRequest
WARNING: Rejecting published file request for file that has not been published: css/images/sprite.png
The following is the folder structure that I have,
de.qsoft.manatee.web.vaadin.myapp
de.qsoft.manatee.web.vaadin.myapp.css --> Contains all CSS files
de.qsoft.manatee.web.vaadin.myapp.fileMenu --> Contains all CSS files
de.qsoft.manatee.web.vaadin.myapp.widgets --> Contains all CSS files
de.qsoft.manatee.web.vaadin.myapp.scripts --> contains all js files
de.qsoft.manatee.web.vaadin.myapp.widgets --> contains all js files
de.qsoft.manatee.web.vaadin.myapp.colorpicker --> contains all js files
SpreadJSWidget.Java
#JavaScript({
"scripts/jquery-1.11.1.min.js",
"scripts/jquery-ui-1.10.3.custom.min.js",
"spreadjs_connector.js",
"colorpicker/colorPicker.js",
"fileMenu/fileMenu.js",
"scripts/actionmanager.js",
"scripts/app.js",
"scripts/bootstrap.min.js",
"scripts/FileSaver.min.js",
"scripts/gc.spread.excelio.12.0.5.min.js",
"scripts/gc.spread.sheets.all.12.0.5.min.js",
"scripts/gc.spread.sheets.barcode.12.0.5.min.js",
"scripts/gc.spread.sheets.charts.12.0.5.min.js",
"scripts/gc.spread.sheets.pdf.12.0.5.min.js",
"scripts/gc.spread.sheets.print.12.0.5.min.js",
"scripts/gc.spread.sheets.shapes.12.0.5.min.js",
"scripts/license.js",
"scripts/resources.js",
"scripts/ribbon-data.js",
"scripts/ribbon.js",
"scripts/sample.js",
"scripts/spreadActions.js",
"scripts/util.js",
"widgets/addChartElement/chartAddChartElement.js",
"widgets/chartColorPicker/chart-colorPicker.js",
"widgets/chartLayoutPicker/chartLayoutPicker.js",
"widgets/richText/richTextEditor.js"
})
#StyleSheet({
"colorpicker/colorPicker.css",
"css/font-awesome/css/font-awesome.min.css",
"css/bootstrap-theme.min.css",
"css/bootstrap.min.css",
"css/borderpicker.css",
"css/colorpicker.css",
"css/excel2013.css",
"css/gc.spread.sheets.12.0.5.css",
"css/gc.spread.sheets.excel2013white.12.0.5.css",
"css/insp-slicer-format.css",
"css/insp-table-format.css",
"css/inspector.css",
"css/sample.css",
"css/shapes.css",
"fileMenu/fileMenu.css",
"widgets/addChartElement/chartAddChartElement.css",
"widgets/chartColorPicker/chart-colorPicker.css",
"widgets/chartLayoutPicker/chartLayoutPicker.css",
"widgets/richText/richTextWithRichEditor.css",
})
public class SpreadJSWidget extends AbstractJavaScriptExtension
{
/**
*
*/
private static final long serialVersionUID = -804316208810859887L;
public interface ValueChangeListener extends Serializable {
void valueChange();
}
ArrayList<ValueChangeListener> listeners = new ArrayList<ValueChangeListener>();
public void addValueChangeListener(ValueChangeListener listener) {
listeners.add(listener);
}
/**
*
*/
public SpreadJSWidget() {
// TODO hari: Auto-generated constructor stub
}
/*'***************************************************************************************
* Static/Inner class members
******************************************************************************************/
/*'***************************************************************************************
* Class members
******************************************************************************************/
public void setValue(String value) {
getState().value = value;
}
#Override
protected void extend(AbstractClientConnector target) {
// TODO hari: Not Yet Implemented
super.extend(target);
}
public String getValue() {
return getState().value;
}
#Override protected SpreadJSWidgetState getState() {
return (SpreadJSWidgetState) super.getState();
}
}
I tried the following step by step but i could not get expected results,
I have kept all the png files under the directory "de.qsoft.manatee.web.vaadin.myapp.css" as "de.qsoft.manatee.web.vaadin.myapp.css.images"
Under VAADIN folder, i copied all the png files as "VAADIN/css/images/"
Under VAADIN folder like "VAADIN/themes/mytheme/img/css/images"
Under VAADIN folder like "VAADIN/themes/mytheme/layouts/css/images"
#Theme("mytheme")
public class MyUI extends UI {
#Override
protected void init(VaadinRequest vaadinRequest) {
SpreadWidget widget = new SpreadWidget();
setContent(widget);
}
#WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
#VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
Please let me know where should i put all png files. Each css is refering image file as
http://localhost:8080/spreadjs/APP/PUBLISHED/css/images/AllShapes.png
What happens here is caused by a security feature. Since the files are in this case served directly from the classpath, Vaadin takes some precautions to prevent accidentally also publishing other things from the classpath, e.g. something like DatabaseConnection.java which might contain sensitive passwords.
For this reason, only files that are explicitly published using a #StyleSheet, #JavaScript or #HtmlImport annotation are available. Since there is no corresponding annotation for e.g. css/images/AllShapes.png, the server ignores those requests.
I'm aware of a couple of potential workarounds in this kind of case, but neither is really elegant:
Put the images in e.g. VAADIN/css/images and update the CSS to use an appropriate number of ../ segments to cancel out the /APP/PUBLISHED/ part of the URL. The URL in the CSS would thus be something along the lines of ../../VAADIN/css/images.AllShapes.png.
Put the CSS along with the images in VAADIN/. In that way, you don't need to change the URLs that refer to the images, but you instead need to manually load the CSS instead of relying on the convenient #StyleSheet annotation. In that case, I'd recommend using something like ui.getPage().getStyles().add(new ThemeResource("../../css/name.css"));. The ../../ part is to cancel out themes/mytheme/ that will automatically be used for a theme resource. You could do this in e.g. the attach() method (just remember to also call super.attach()). You should preferably also add some logic that only adds the dependency if it hasn't already been done previously for the same UI instance.
Use the internal LegacyCommunicationManager.registerDependency method to also register your images to be available directly from the classpath. You can find an instance to LegacyCommunicationManager using vaadinSession.getCommunicationManager().
As an unrelated note, I'd recommend combining the different scripts and CSS files into a single file of each type. The reason for this is that loading lots of small files over HTTP causes some performance overhead that can be avoided by bundling the files together.

How to set extra fields for entries using plexus-archiver

I'm working with a maven plugin that is using plexus-archiver in order to create a zip file.
Basically, I'm getting the component inject by Sisu, then I'm traversing a specified fileSet and registering the ones required:
zipArchiver.addFile(from_file, to_file);
And the zip are being generated properly.
But I need to include an extra-field for the file mime-type in some of those files that are being added to the zip.
how can I do that with plexus-archiver ?
It seems that the current plexus-archiver (3.0) doesn't support extra-fields.
I have to hack a bit in order to keep using plexus-archive.
The solution was to extend ZipArchiver class and override the method initZipOutputStream that provides an object from ZipArchiveOutputStream class.
With it I could create the entry and its extra-field:
#Override
protected void initZipOutputStream(ZipArchiveOutputStream pZOut)
throws ArchiverException, IOException {
super.initZipOutputStream(pZOut);
ZipArchiveEntry ae = new ZipArchiveEntry(pFile,
pFile.getName());
ZipExtraField zef = new ContentTypeExtraField(
Constants.MIME_STRING);
ae.addExtraField(zef);
pZOut.putArchiveEntry(ae);
pZOut.write(content);
pZOut.closeArchiveEntry();
}

Orchard - Can't find the Resource defined in ResourceManifest.cs

I have a custom there, where I try to require some of my css and js files via the ResourceManifest.cs file - I keep into running a quite weird issue tough.
I get the following error:
a 'script' named 'FoundationScript' could not be found
This is my ResourceManifest.cs:
using Orchard.UI.Resources;
namespace Themes.TestTheme
{
public class ResourceManifest : IResourceManifestProvider
{
public void BuildManifest(ResourceManifestBuilder builder)
{
var manifest = builder.Add();
manifest.DefineStyle("Foundation").SetUrl("foundation.min.css");
manifest.DefineScript("FoundationScript").SetUrl("foundation.min.js");
}
}
}
In the Layout.cshtml, I have following:
#{
Script.Require("ShapesBase");
Script.Require("FoundationScript");
Style.Include("site.css");
Style.Require("Foundation");
}
What am I missing here?
The issue here is, that the project Themes has a problem with the dynamic compile mechanism of Orchard (i don't know what is wrong exactly) because it resides in folder Themes. Even if you define a class inside the Themes assembly, it will result in an error telling you there is no such class in that assembly.
solution :
Try re-generating your theme with /CreateProject:true and /IncludeInSolution:true parameters as follows:
codegen theme TestTheme /CreateProject:true /IncludeInSolution:true /BasedOn :TheThemeMachine
It will create your theme in a separate project and orchard will pick your registered ResourceManifest.
Hope this helps.

Register Font for Multiple .AS Files

I'm embedding a few fonts in my ActionScript file as follows:
[Embed(source="DAXCOMPL.TTF", fontName="DaxCompact-Light", mimeType='application/x-font', embedAsCFF='false')]
private var MyFont:Class;
This is done in the main Canvas that is placed by the mxml. This canvas creates several smaller canvases and places them as children. I have each of these sub-canvases split up into a separate .as file for ease of use. The problem I'm running into is that I would like to use this font in these .as files without having to pass it around. Is it possible to somehow register the font globally?
I'd set it as a public static const in its own file. I do this if I need to embed a bunch of icons as well. Makes it easy to say Icons.ADD or something lie that.
package your.project.someplace
{
public final class MyFonts{
[Embed(source="DAXCOMPL.TTF", fontName="DaxCompact-Light",mimeType='application/x-font', embedAsCFF='false')]
public static const DAXCOMPL:Class;
}
}
Now anytime you need to use it, call the static class.
MyFonts.DAXCOMPL;
Oh, I had assumed you were using FLASH... but it looks like your using MXML (Flex) in which case you can just set a style in a stylesheet.
#font-face
{
src: url("DAXCOMPL.TTF");
fontFamily: DaxCompact;
}
Then in your main app file you can say <mx:Style source="myCSSFile.css"/>

Resources