Jean-Francois Leveque

ListPublisherActions en Rewrite

1 package org.legrog.web.publisher; 1 package org.legrog.web.publisher;
2 2
3 import org.legrog.entities.PublisherAction; 3 import org.legrog.entities.PublisherAction;
4 +import org.ocpsoft.rewrite.annotation.Join;
5 +import org.ocpsoft.rewrite.annotation.Parameter;
6 +import org.ocpsoft.rewrite.annotation.RequestAction;
4 import org.slf4j.Logger; 7 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
6 9
10 +import javax.annotation.PostConstruct;
11 +import javax.enterprise.context.RequestScoped;
7 import javax.faces.view.ViewScoped; 12 import javax.faces.view.ViewScoped;
8 import javax.inject.Inject; 13 import javax.inject.Inject;
9 import javax.inject.Named; 14 import javax.inject.Named;
...@@ -17,9 +22,13 @@ import java.util.stream.Collectors; ...@@ -17,9 +22,13 @@ import java.util.stream.Collectors;
17 * Permet de voir l'ensemble des actions d'un éditeur. 22 * Permet de voir l'ensemble des actions d'un éditeur.
18 */ 23 */
19 @Named 24 @Named
20 -@ViewScoped 25 +@RequestScoped
26 +@Join(path = "/ListPublisherActions/{stringId}", to = "/publisher/listPublisherActions.jsf")
21 public class ListPublisherActionsView implements Serializable { 27 public class ListPublisherActionsView implements Serializable {
22 28
29 + @Parameter
30 + String stringId;
31 +
23 transient Logger logger = LoggerFactory.getLogger(getClass()); 32 transient Logger logger = LoggerFactory.getLogger(getClass());
24 33
25 protected transient PublisherService publisherService; 34 protected transient PublisherService publisherService;
...@@ -41,13 +50,23 @@ public class ListPublisherActionsView implements Serializable { ...@@ -41,13 +50,23 @@ public class ListPublisherActionsView implements Serializable {
41 ListPublisherActionsView() { 50 ListPublisherActionsView() {
42 //no args constructor to make it proxyable 51 //no args constructor to make it proxyable
43 } 52 }
53 + @PostConstruct
54 + @RequestAction
55 + public void init() {
56 +
57 + if (stringId != null) {
58 + try {
59 + publisherId = new Integer(stringId);
60 + } catch (NumberFormatException ne) {
61 + publisherId = null;
62 + }
63 + } else {
64 + publisherId = null;
65 + }
44 66
45 - public void setView() {
46 - logger.trace("setView : publisherId = {}", publisherId);
47 publisherActions = publisherService.getAllPublisherActions(); 67 publisherActions = publisherService.getAllPublisherActions();
48 viewAll = publisherId == null; 68 viewAll = publisherId == null;
49 if (!viewAll) { 69 if (!viewAll) {
50 - logger.trace("setView : !viewAll");
51 filterOnID(); 70 filterOnID();
52 } 71 }
53 } 72 }
...@@ -81,4 +100,12 @@ public class ListPublisherActionsView implements Serializable { ...@@ -81,4 +100,12 @@ public class ListPublisherActionsView implements Serializable {
81 public void setPublisherActions(List<PublisherAction> publisherActions) { 100 public void setPublisherActions(List<PublisherAction> publisherActions) {
82 this.publisherActions = publisherActions; 101 this.publisherActions = publisherActions;
83 } 102 }
103 +
104 + public String getStringId() {
105 + return stringId;
106 + }
107 +
108 + public void setStringId(String stringId) {
109 + this.stringId = stringId;
110 + }
84 } 111 }
......
...@@ -5,10 +5,6 @@ ...@@ -5,10 +5,6 @@
5 xmlns:h="http://xmlns.jcp.org/jsf/html" 5 xmlns:h="http://xmlns.jcp.org/jsf/html"
6 xmlns:jsf="http://xmlns.jcp.org/jsf" 6 xmlns:jsf="http://xmlns.jcp.org/jsf"
7 xmlns:f="http://xmlns.jcp.org/jsf/core"> 7 xmlns:f="http://xmlns.jcp.org/jsf/core">
8 -<f:metadata>
9 - <f:viewParam name="publisherId" value="#{listPublisherActionsView.publisherId}"/>
10 - <f:viewAction action="#{listPublisherActionsView.setView}"/>
11 -</f:metadata>
12 <head> 8 <head>
13 <link rel="stylesheet" type="text/css" href="/minimal.css"/> 9 <link rel="stylesheet" type="text/css" href="/minimal.css"/>
14 </head> 10 </head>
......
...@@ -48,7 +48,7 @@ public class ListPublisherActionsViewTest { ...@@ -48,7 +48,7 @@ public class ListPublisherActionsViewTest {
48 public void showAll(@Mock PublisherService publisherServiceMock) { 48 public void showAll(@Mock PublisherService publisherServiceMock) {
49 listPublisherActionsView.setPublisherId(null); 49 listPublisherActionsView.setPublisherId(null);
50 listPublisherActionsView.setViewAll(false); 50 listPublisherActionsView.setViewAll(false);
51 - listPublisherActionsView.setView(); 51 + listPublisherActionsView.init();
52 Mockito.verify(publisherServiceMock).getAllPublisherActions(); 52 Mockito.verify(publisherServiceMock).getAllPublisherActions();
53 assertThat(listPublisherActionsView.isViewAll()).isTrue(); 53 assertThat(listPublisherActionsView.isViewAll()).isTrue();
54 assertThat(filtered).isFalse(); 54 assertThat(filtered).isFalse();
...@@ -57,9 +57,9 @@ public class ListPublisherActionsViewTest { ...@@ -57,9 +57,9 @@ public class ListPublisherActionsViewTest {
57 @Test 57 @Test
58 @DisplayName("when publisher is set, should be in filtered not all actions state") 58 @DisplayName("when publisher is set, should be in filtered not all actions state")
59 public void showFiltered(@Mock PublisherService publisherServiceMock) { 59 public void showFiltered(@Mock PublisherService publisherServiceMock) {
60 - listPublisherActionsView.setPublisherId(1); 60 + listPublisherActionsView.setStringId("1");
61 listPublisherActionsView.setViewAll(true); 61 listPublisherActionsView.setViewAll(true);
62 - listPublisherActionsView.setView(); 62 + listPublisherActionsView.init();
63 Mockito.verify(publisherServiceMock).getAllPublisherActions(); 63 Mockito.verify(publisherServiceMock).getAllPublisherActions();
64 assertThat(listPublisherActionsView.isViewAll()).isFalse(); 64 assertThat(listPublisherActionsView.isViewAll()).isFalse();
65 assertThat(filtered).isTrue(); 65 assertThat(filtered).isTrue();
......