Search in sources :

Example 1 with ComponentSystemEvent

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);
}
Also used : DataTable(org.primefaces.component.datatable.DataTable) PreRenderComponentEvent(javax.faces.event.PreRenderComponentEvent) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ComponentSystemEvent(javax.faces.event.ComponentSystemEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with ComponentSystemEvent

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);
}
Also used : ComponentSystemEvent(javax.faces.event.ComponentSystemEvent) Test(org.junit.Test)

Example 3 with ComponentSystemEvent

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));
                    }
                }
            });
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ComponentSystemEventListener(javax.faces.event.ComponentSystemEventListener) UIComponent(javax.faces.component.UIComponent) ArrayList(java.util.ArrayList) UIOutput(javax.faces.component.UIOutput) ResponseWriter(javax.faces.context.ResponseWriter) ComponentSystemEvent(javax.faces.event.ComponentSystemEvent) AbortProcessingException(javax.faces.event.AbortProcessingException) UIViewRoot(javax.faces.component.UIViewRoot)

Aggregations

ComponentSystemEvent (javax.faces.event.ComponentSystemEvent)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Employee (com.artezio.arttime.datamodel.Employee)1 Project (com.artezio.arttime.datamodel.Project)1 UIComponent (javax.faces.component.UIComponent)1 UIOutput (javax.faces.component.UIOutput)1 UIViewRoot (javax.faces.component.UIViewRoot)1 FacesContext (javax.faces.context.FacesContext)1 ResponseWriter (javax.faces.context.ResponseWriter)1 AbortProcessingException (javax.faces.event.AbortProcessingException)1 ComponentSystemEventListener (javax.faces.event.ComponentSystemEventListener)1 PreRenderComponentEvent (javax.faces.event.PreRenderComponentEvent)1 DataTable (org.primefaces.component.datatable.DataTable)1