如果在相应的Java代码中引用对象
如果人们使用vaadin Designer(在Vaadin 14中)创建垂直布局类,并将其宽度设置为某个固定值(例如3%)和,一个人在相应的Java代码中对该垂直布局组件有一个引用,Vaadin将忽略宽度设置。奇怪的是,如果一个错误在Java代码中不引用垂直布局类,则此错误会消失。这是一个可说明错误的工作测试用例。目前,我的“黑客”是为了避免在我的Java代码中引用对象,或者如果必须,我认为我需要在Java代码本身中明确重置宽度逻辑。有什么想法吗?
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import '@vaadin/vaadin-ordered-layout/src/vaadin-horizontal-layout.js';
class UiTestview extends PolymerElement {
static get template() {
return html`
<style include="shared-styles">
:host {
display: block;
height: 100%;
}
</style>
<vaadin-horizontal-layout class="content" style="width: 100%; height: 100%;">
<vaadin-vertical-layout id="left" style="width: 3%;background-color:blue">
<label>left label</label>
</vaadin-vertical-layout>
<label style="flex-grow: 1;background-color:red">Label</label>
</vaadin-horizontal-layout>
`;
}
static get is() {
return 'ui-testview';
}
static get properties() {
return {
// Declare your properties here.
};
}
}
customElements.define(UiTestview.is, UiTestview);
以及相应的Java代码:
package org.vaadin;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.template.Id;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.templatemodel.TemplateModel;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.polymertemplate.PolymerTemplate;
/**
* A Designer generated component for the ui-testview template.
*
* Designer will add and remove fields with @Id mappings but
* does not overwrite or otherwise change this file.
*/
@Route("testview")
@Tag("ui-testview")
@JsModule("./src/ui-testview.js")
public class UiTestview extends PolymerTemplate<UiTestview.UiTestviewModel> {
@Id("left")
private VerticalLayout left;
/**
* Creates a new UiTestview.
*/
public UiTestview() {
}
/**
* This model binds properties between UiTestview and ui-testview
*/
public interface UiTestviewModel extends TemplateModel {
// Add setters and getters for template properties here.
}
}
If one creates a vertical layout class using Vaadin Designer (in Vaadin 14) and sets its width to some fixed value (eg 3%) and one has a reference to that vertical layout component in the corresponding java code, Vaadin will IGNORE the width setting. Curiously, this bug dissappears if one does NOT reference the vertical layout class in the java code. Here's a working test case to illustrate the bug. For now, my "hack" has been to avoid referencing the object in my java code, or if I must, then I think I need to explicitly reset the width logic in the java code itself. Any thoughts?
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import '@vaadin/vaadin-ordered-layout/src/vaadin-horizontal-layout.js';
class UiTestview extends PolymerElement {
static get template() {
return html`
<style include="shared-styles">
:host {
display: block;
height: 100%;
}
</style>
<vaadin-horizontal-layout class="content" style="width: 100%; height: 100%;">
<vaadin-vertical-layout id="left" style="width: 3%;background-color:blue">
<label>left label</label>
</vaadin-vertical-layout>
<label style="flex-grow: 1;background-color:red">Label</label>
</vaadin-horizontal-layout>
`;
}
static get is() {
return 'ui-testview';
}
static get properties() {
return {
// Declare your properties here.
};
}
}
customElements.define(UiTestview.is, UiTestview);
and the corresponding java code:
package org.vaadin;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.template.Id;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.templatemodel.TemplateModel;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.polymertemplate.PolymerTemplate;
/**
* A Designer generated component for the ui-testview template.
*
* Designer will add and remove fields with @Id mappings but
* does not overwrite or otherwise change this file.
*/
@Route("testview")
@Tag("ui-testview")
@JsModule("./src/ui-testview.js")
public class UiTestview extends PolymerTemplate<UiTestview.UiTestviewModel> {
@Id("left")
private VerticalLayout left;
/**
* Creates a new UiTestview.
*/
public UiTestview() {
}
/**
* This model binds properties between UiTestview and ui-testview
*/
public interface UiTestviewModel extends TemplateModel {
// Add setters and getters for template properties here.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,Vaadin的Java侧(至少在Vaadin 14中)并不了解模板的任何初始客户端状态。这就是为什么Java-Getters通常不会返回模板中设置的值的原因。此外,
verticallayout
setssetWidth(“ 100%”)
,一旦将模板映射到模板,它实际上可能会覆盖模板中的宽度集。这是Vaadin 18中的改进。我怀疑这会被退回到Vaadin 14。Basically the Java-side of Vaadin (at least in Vaadin 14) does not know about any initial client-side state from the template. That's why Java-getters will often not return values set in your template. Furthermore,
VerticalLayout
setssetWidth("100%")
in its constructor which may actually override a width set in your template once you map it to your template. This is something that has been improved in Vaadin 18. I doubt this will be backported to Vaadin 14.