html还原ui,HtmlUIForTemplates

To register your HTML based wizard with your template, use @TemplateRegistration annotation and provide reference to your HTML page:

public class X {

@TemplateRegistration(

page = "cz/xelfi/test/x.html",

scriptEngine = "freemarker",

displayName = "JS Wizard",

folder = "Other",

content = "x.fmk"

)

public static String jsWizard() {

return "init();";

}

}

the return value of the annotated method should of type String and its content should be snippet of JavaScript code to execute inside of your specified HTML page (e.g. x.html) to create an instance of KnockoutJS model to drive the wizard. Here is the sample of the model:

function init() {

var ok = ko.observable(false);

var msg = ko.observable('');

var current = ko.observable('Init');

var data = {

'errorCode': ko.computed(function() {

if ('Init' == current()) return 0;

if (!ok()) return 1;

if (msg()) return 0;

return 2;

}),

'steps': ko.observableArray([ 'Init', 'Info', 'Summary']),

'current': current,

'ok': ok,

'msg' : msg

}

return data;

}

it defines wizard composed of three panels (observable steps) and a verification function (registered as errorCode) to check if everything is OK. In addition to that it defines proprietary text value msg which is going to be filled by the wizard and cannot be empty.

Each page of the wizard is registered as a KnockoutJS template named according to the name of the specified step. A dummy initial page:

This is Initial Page

JavaScript will ask you few questions about your mood.

an interactive page with checkbox and an input field:

This is Query Page

Is everything OK?

How do you feel?

and a simple summary page showing the specified values:

This is Summary Page

You are feeling !

The Next/Finish buttons can be controlled by the errorCode property. If it is non-zero, there is an error and these buttons are disabled. Also once can use that inside of the HTML page to display user related errors:

Please check you are OK!

Tell us how do you feel!

The L10N of the wizard is done on the level of HTML pages. The whole page gets translated into different language with appropriate suffix x_cs.html and it is then selected instead of the default one, when user runs in such locale.

When the wizard is successfully finished, all the values specified in the model are transfered to the templating engine, so they can influence the content of created files. Here is a sample x.fmt content which reuses the msg value provided by the wizard:

Hi,

I am Freemarker.

I feel ${wizard.msg}.

System of this kind is portable between existing NetBeans infrastructure (see branch WizardFor247926 in ergonomics repository) as well as demo of embedding the same wizard into browser (see on-line demo).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值