use of javax.faces.event.ComponentSystemEvent in project ART-TIME by Artezio.
the class ProjectsBeanTest method testSetInitialFilteredValue_notPostback.
@Test
public void testSetInitialFilteredValue_notPostback() throws NoSuchFieldException {
Employee loggedEmployee = new Employee();
setField(projectBean, "facesContext", facesContext);
setField(projectBean, "projectService", projectService);
DataTable table = createMock(DataTable.class);
ComponentSystemEvent event = new PreRenderComponentEvent(table);
ArrayList<Project> projects = new ArrayList<>();
EasyMock.expect(projectService.getManagedProjects()).andReturn(projects);
EasyMock.expect(projectService.fetchComplete(projects)).andReturn(projects);
expect(facesContext.isPostback()).andReturn(false);
table.updateValue(projects);
replay(facesContext, table, projectService);
projectBean.setInitialFilteredValue(event);
verify(facesContext, table, projectService);
}
use of javax.faces.event.ComponentSystemEvent in project ART-TIME by Artezio.
the class ProjectsBeanTest method testSetInitialFilteredValue_postback.
@Test
public void testSetInitialFilteredValue_postback() throws NoSuchFieldException {
setField(projectBean, "facesContext", facesContext);
setField(projectBean, "projectRepository", projectRepository);
ComponentSystemEvent event = createMock(ComponentSystemEvent.class);
expect(facesContext.isPostback()).andReturn(true);
replay(facesContext, event, projectRepository);
projectBean.setInitialFilteredValue(event);
verify(facesContext, event, projectRepository);
}
use of javax.faces.event.ComponentSystemEvent in project liferay-faces-bridge-impl by liferay.
the class ResourcesRenderedInHeadTestBean method preRenderHeadListener.
/**
* This method causes each head resource to render an id attribute containing the resource name or client id if the
* resource name is unavailable. See {@link ResponseWriterResourceIdImpl} and the comments below for more details.
*/
public void preRenderHeadListener(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
// Obtain all head resources.
UIComponent uiComponent = componentSystemEvent.getComponent();
List<UIComponent> children = uiComponent.getChildren();
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot uiViewRoot = facesContext.getViewRoot();
List<UIComponent> componentResources = uiViewRoot.getComponentResources(facesContext, "head");
List<UIComponent> headResources = new ArrayList<UIComponent>(children);
headResources.addAll(componentResources);
// ResponseWriter to an instance of ResponseWriterResourceIdImpl.
for (UIComponent headResource : headResources) {
String rendererType = headResource.getRendererType();
if ((headResource instanceof UIOutput) && (rendererType.equals("javax.faces.resource.Script") || rendererType.equals("javax.faces.resource.Stylesheet"))) {
headResource.subscribeToEvent(PreRenderComponentEvent.class, new ComponentSystemEventListener() {
@Override
public void processEvent(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
FacesContext facesContext = FacesContext.getCurrentInstance();
ResponseWriter responseWriter = facesContext.getResponseWriter();
if (!(responseWriter instanceof ResponseWriterResourceIdImpl)) {
facesContext.setResponseWriter(new ResponseWriterResourceIdImpl(responseWriter));
}
}
});
}
}
}
Aggregations