-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve sub properties in a template model (#932)
- Loading branch information
Showing
7 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...s/test-root-context/src/main/java/com/vaadin/hummingbird/uitest/ui/template/FormView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2000-2016 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.hummingbird.uitest.ui.template; | ||
|
||
import com.vaadin.annotations.EventHandler; | ||
import com.vaadin.hummingbird.template.model.TemplateModel; | ||
import com.vaadin.ui.Template; | ||
|
||
public class FormView extends Template { | ||
|
||
static final String ID_FIRST_NAME = "firstName"; | ||
static final String ID_LAST_NAME = "lastName"; | ||
static final String ID_AGE = "age"; | ||
|
||
public interface ReadonlyFormModel extends TemplateModel { | ||
public void setPerson(Person person); | ||
|
||
public Person getPerson(); | ||
} | ||
|
||
@Override | ||
protected ReadonlyFormModel getModel() { | ||
return (ReadonlyFormModel) super.getModel(); | ||
} | ||
|
||
public FormView() { | ||
Person person = new Person("Hello", "World", 32); | ||
|
||
getModel().setPerson(person); | ||
} | ||
|
||
@EventHandler | ||
public void updateModel() { | ||
Person p = getModel().getPerson(); | ||
p.setFirstName(p.getFirstName() + "!"); | ||
p.setLastName(p.getLastName() + "?"); | ||
p.setAge(p.getAge() + 1); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...sts/test-root-context/src/main/java/com/vaadin/hummingbird/uitest/ui/template/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.vaadin.hummingbird.uitest.ui.template; | ||
|
||
public class Person { | ||
private String firstName, lastName; | ||
private int age; | ||
|
||
public Person() { | ||
// Needed only for TemplateModel but can't be hidden | ||
} | ||
|
||
public Person(String firstName, String lastName, int age) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.age = age; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(int age) { | ||
this.age = age; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...t-root-context/src/main/resources/com/vaadin/hummingbird/uitest/ui/template/FormView.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div> | ||
<!-- All fields read only for now as there is no two way databinding --> | ||
<div> | ||
<div>First name</div> | ||
<input id="firstName" disabled [value]="person.firstName" /> | ||
</div> | ||
<div> | ||
<div>Last name</div> | ||
<input id="lastName" disabled [value]="person.lastName" /> | ||
</div> | ||
<div> | ||
<div>Age</div> | ||
<input id="age" disabled [value]="person.age" /> | ||
</div> | ||
<button (click)="$server.updateModel()">Update model values</button> | ||
</div> |
43 changes: 43 additions & 0 deletions
43
...sts/test-root-context/src/test/java/com/vaadin/hummingbird/uitest/ui/template/FormIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2000-2016 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.hummingbird.uitest.ui.template; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.vaadin.hummingbird.testutil.PhantomJSTest; | ||
import com.vaadin.testbench.By; | ||
|
||
public class FormIT extends PhantomJSTest { | ||
|
||
@Test | ||
public void updateServerSide() { | ||
open(); | ||
Assert.assertEquals("Hello", getValue(FormView.ID_FIRST_NAME)); | ||
Assert.assertEquals("World", getValue(FormView.ID_LAST_NAME)); | ||
Assert.assertEquals("32", getValue(FormView.ID_AGE)); | ||
|
||
findElement(By.tagName("button")).click(); | ||
|
||
Assert.assertEquals("Hello!", getValue(FormView.ID_FIRST_NAME)); | ||
Assert.assertEquals("World?", getValue(FormView.ID_LAST_NAME)); | ||
Assert.assertEquals("33", getValue(FormView.ID_AGE)); | ||
} | ||
|
||
private String getValue(String inputId) { | ||
return findElement(By.id(inputId)).getAttribute("value"); | ||
} | ||
} |