Skip to content

Commit 7a0711b

Browse files
author
Igor Polevoy
committed
#227 FlashTag is not displaying named flashes with body - added anonymous tag with body
1 parent da7a4f2 commit 7a0711b

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

activeweb-testing/src/test/java/app/controllers/FlashingController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,13 @@ public void flashByName(){
7272
}
7373

7474

75+
76+
@POST
77+
public void save3(){
78+
flash();
79+
respond("ok"); // we do not check this output
80+
}
81+
82+
public void anonymous(){
83+
}
7584
}

activeweb-testing/src/test/java/org/javalite/activeweb/FlashTagSpec.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public void shouldRenderFlashWithNestedPartial(){
8484
a(responseContent()).shouldBeEqual("<div class=\"warning\">hi, there!</div>");
8585
}
8686

87-
8887
@Test
8988
public void shouldRenderFlashByName(){
9089
controller("flashing").integrateViews().post("save1");
@@ -96,10 +95,17 @@ public void shouldRenderFlashByName(){
9695
controller("flashing").integrateViews().post("save2");
9796
controller("flashing").integrateViews().get("flash_by_name");
9897

99-
System.out.println(responseContent());
10098
a(responseContent()).shouldContain("This is an error: hi");
10199
controller("flashing").integrateViews().get("flash_by_name");
102100
a(blank(responseContent())).shouldBeTrue();
103101
}
104102

103+
@Test
104+
public void shouldRenderAnonymousFlash(){
105+
controller("flashing").integrateViews().post("save3");
106+
controller("flashing").integrateViews().get("anonymous");
107+
a(responseContent()).shouldContain("Hello, anonymous flash!");
108+
controller("flashing").integrateViews().get("anonymous");
109+
a(responseContent()).shouldNotContain("Hello, anonymous flash!");
110+
}
105111
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<@flash>Hello, anonymous flash!</@flash>

activeweb/src/main/java/org/javalite/activeweb/HttpSupport.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ protected void view(Object ... values){
123123
* @param values values to flash.
124124
*/
125125
protected void flash(Map values){
126+
checkFlasher();
126127
for(Object key:values.keySet() ){
127128
flash(key.toString(), values.get(key));
128129
}
@@ -169,10 +170,14 @@ protected void flash(String name){
169170
*/
170171
@SuppressWarnings("unchecked")
171172
protected void flash(String name, Object value) {
173+
checkFlasher();
174+
((Map) session().get("flasher")).put(name, value);
175+
}
176+
177+
private void checkFlasher(){
172178
if (session().get("flasher") == null) {
173179
session().put("flasher", new HashMap());
174180
}
175-
((Map) session().get("flasher")).put(name, value);
176181
}
177182

178183
public class HttpBuilder {

0 commit comments

Comments
 (0)