0

How to setting favicon in pure java?

asked 2009-04-30 12:59:27 +0800

dariolr gravatar image dariolr
42

Please help.

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2009-05-07 00:30:50 +0800

RyanWu gravatar image RyanWu
533 2
about.me/flyworld

maybe you can use some method of page ?
http://www.zkoss.org/javadoc/3.6.0/zk/org/zkoss/zk/ui/Page.html

link publish delete flag offensive edit

answered 2009-05-15 12:59:28 +0800

dariolr gravatar image dariolr
42

Thank's RyanWu

... can you post a example?

link publish delete flag offensive edit

answered 2011-04-26 03:57:46 +0800

JGA gravatar image JGA
15

I have the same Problem. Have to set the favicon in java, but Page doesn't provide a method I think.

Can I add the favicon in the lang-addon.xml?

Because for stylesheets, it looks like this:
<stylesheet href="~./zul/css/zk.wcs" type="text/css"/>

Is there a similar way for a favicon?

link publish delete flag offensive edit

answered 2011-04-26 04:19:21 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

updated 2011-04-26 04:19:56 +0800

use page init and EL , here are simple steps to set in java per zul page.

1. add init and link for favicon, use el expression in favicon href.

<?init class="favicon.MyInit"?>
<?link rel="shortcut icon" type="image/x-icon" href="/${myFavicon}"?>
<?link rel="icon" type="image/x-icon" href="/${myFavicon}"?>

2. in page init

public class MyInit implements Initiator {
	public void doInit(Page page, Map args) throws Exception {
		page.setAttribute("myFavicon", "myFavicon.ico");
	}
}

link publish delete flag offensive edit

answered 2011-04-26 06:46:32 +0800

JGA gravatar image JGA
15

updated 2011-04-26 06:47:09 +0800

Thx for the quick reply dennis.

I found an other possibility to add the link tags. Available since zk 5.0.5.

((PageCtrl)page).addBeforeHeadTags("<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"~./images/favicon.png\">
<link rel=\"icon\" type=\"image/x-icon\" href=\"~./images/favicon.png\">");

It unfortunately doesn't work with the ~. to get the zk path. Ihe image is located in a jar file.

link publish delete flag offensive edit

answered 2011-04-26 07:46:38 +0800

JGA gravatar image JGA
15

Well, problem resolved.
I use

Executions.encodeURL("~./path/favicon.ico");

to get the correct url.

link publish delete flag offensive edit

answered 2011-05-19 04:36:19 +0800

johnnyb gravatar image johnnyb
3

@dennis - your solution with the initiator class doesn't work for me. in the rendered page the href attribute keeps empty. Instead I'm using a Controller class which extends GenericForwardComposer and where i can set the resp. favicon as a bean property.

I'm using zk 3.6.4 .

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-04-30 12:59:27 +0800

Seen: 729 times

Last updated: May 19 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More