GlassFish StandAlone does not load images, elements of the JSF into the primefaces elements and CSS

0

I have a project in netbeans that works perfectly. But, I post .war in my glassfish standalone 4.1 (This version is the same as the netbeans version)

I do the default .war of netbeans (clean and build)

In the project deployed in GFish StandAlone does not show neither photos nor the elements within the main components. In addition, the subject of primefaces does not load CSS

Shows the use of images and css in the .xhtml

<h:head>
    <h:outputStylesheet library="resources" name="css/login.css"/>
    <style type="text/css">
        body{

                background-image: url("resources/images/fondoBlanco.jpg");
                background-size: cover;
                background-repeat: no-repeat; 
                background-attachment:fixed;
        }
    </style>
</h:head>

Sample button images

    <p:commandLink action="#{loginBean.sessGmail()}" ajax="true" type="submit" >
        <h:graphicImage library="resources" name="images/iconGmailBlack.png" style="width: 150px; height: 150px; "/>
        <f:param name="idParamtro" value="#{loginBean.userLog}" />
    </p:commandLink>

All help is appreciated

    
asked by Pablo García Tamarit 25.11.2016 в 08:02
source

1 answer

1

If it works in the GF / Netbeans, it will work with the "standalone" GF unless you have set a datasource,connectionpool, Realm , if it is the case, you have to configure that manually since there are times that the glassfish-resources.xml is not taken into account ... (a little absurd but it happens). But if this is the case, some type of StackTrace should come out. You can check server log to see what is happening since you are not using Netbeans, so you have no way to see the "console". You can find the server log in:

[lugar_de_instalación]\glassfish\domains\domain1\logs

in my case:

C:\Program Files\glassfish-4.1.1\glassfish\domains\domain1\logs

This file will probably clarify why it is not working as it should, but I do not think it has much to do with the deployment descriptor web.xml since it is configured by netbeans when creating a web project.

If you modified it, make sure you have at least the following configuration, otherwise the pages will not be able to be interpreted by the browser:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 
         xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">    


     // Activar el Servlet que se encarga de 
     // crear HTML a partir de etiquetas JSF
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>        
    </servlet>

    // Vincular el "Faces Servlet" 
    // con recursos que estén acorde al "url-pattern"
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    // Establecer qué página mostrar al iniciar la app.
    <welcome-file-list>
        <welcome-file>welcome.xhtml</welcome-file>
    </welcome-file-list>

</web-app>

EDITING

JSF helps us to load external resources dynamically through the resource handler .

This works in the following way:

  • you have to create a folder called resources within WebContent or Web Pages, this will have the resources that will be used in the app.
  • To call a resource, follow the following:
  • With this structure:

    -Web Pages
        |___ WEB-INF
        |___ resources
                |__ css
                |    |_ estilosIndex.css
                |__ js
                |    |_ index.js
                |__ imagenes
                     |_ avatar.png
    

    If we want to call a resource CSS|Javascript we use:

    <h:outputStylesheet library="css" name="estilosIndex.css" />
    

    or

    <h:outputStylesheet name="css/estilosIndex.css" />
    

    No need to explicitly call the folder resources

    The same thing happens with javascript:

    <h:outputScript library="js" name="index.js" />
    

    or     

    Ok, now what happens with Primefaces or JSF% components <h:... .

    To call an image resource located in resources/ , use the attribute name

    <h:graphicImage name="imagenes/avatar.png" />
    
    <p:graphicImage name="imagenes/avatar.png" />
    

    or

    <h:graphicImage name="avatar.png" library="imagenes"/>
    
    <p:graphicImage name="/avatar.png" library="imagenes"/>
    

    The value attribute is for binary information.

    To call resources from a file css|js you have to use the resource bundle:

    body{
      background: url("#{resource['imagenes/avatar.png']}");
    }
    
        
    answered by 28.11.2016 / 17:28
    source