7 Replies Latest reply on Jul 9, 2009 7:18 AM by ilya_shaikovsky

    Images not shown at first page invocation

    nschweig

      Hi,

      in my application I have got some images that I use for buttons.
      For ex. like this:

      <h:form>
       <h:commandLink action="#appointmentBeanStud.showEditAppointmentOffer}" >
       <h:graphicImage value="../../../img/buttons/edit.png" />
       </h:commandLink>
      </h:form>
      


      Unfortunately when I go to the page the first time, the buttons are not shown.
      If I go to the side at the second time (by clicking the menu link) they are shown. If I now go to antother side and then come back to that side the buttons are not shown; and so on.

      I have got absolutly no idea why this happens.
      I use pngs and jpgs, it is the same.

      I use Facelets and RichFaces.
      I have got a menu.xhtml where are the links to the pages like this:

      <rich:panelMenuGroup label="#{rs.menu_appointments}">
       <rich:panelMenuItem>
       <h:commandLink value="#{rs.menu_new_appointment}" action="#{appointmentBeanInst.showNewAppointment}" />
       </rich:panelMenuItem>
      ...
      


      I would be very pleased for every idea.
      Thank you.
      NSchweig

        • 1. Re: Images not shown at first page invocation
          ilya_shaikovsky

          use

           <h:graphicImage value="#{facesContext.externalContext.requestContextPath}/img/buttons/edit.png"/>
          


          instead of your relative src's.

          • 2. Re: Images not shown at first page invocation

            In my application i am also using facelets and richfaces, my images are kept inside webcontent in "images" folder and i can accessing it by relative path like \images ..here is the snap....

            
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:rich="http://richfaces.org/rich"
             xmlns:a4j="http://richfaces.org/a4j">
            
            <head>
            
            
            <ui:insert name="pageHead">
            
            </ui:insert>
            
            
            
            </head>
            
            
            <f:loadBundle basename="language/rsw_en" var="res" />
            
            
            <f:view contentType="text/html" >
            
             <body id="bodycontainer" onload="setOnLoadFlag()" >
            
            
            <h:form id="PageForm" >
            
            <a4j:outputPanel id="statusPanel" ajaxRendered="true" >
            <a4j:status id="commonstatus" onstart="startProgress()" onstop="stopProgress()" />
            <h:graphicImage id="statusImage" value="/images/busystatus.gif" style="visibility:hidden" styleClass="statusImageStyle" />
            
            </a4j:outputPanel>
            
            
            <div id="pageMenuBar">
             <ui:insert name="menuBar">
            
             </ui:insert>
            </div>
            
            <div id="pageBody" style="padding-left: 3px;">
             <ui:insert name="pageBody">
            
             </ui:insert>
            </div>
            
            
            
            </h:form>
            
            
            </body>
            
            </f:view>
            
            </html>
            
            


            • 3. Re: Images not shown at first page invocation
              nschweig

              Hi,

              I have got the same problem as user1234.
              My images-folder ist in the web-content folder of my application.
              My application-folder with the pages, too.

              Web-Content
              - application
              -

              • 4. Re: Images not shown at first page invocation
                nschweig

                Hi,

                I have got the same problem as user1234.
                My images-folder ist in the web-content folder of my application.
                My application-folder with the pages, too.

                Web-Content
                - application
                - ....xhtml
                - img
                - .....png


                Where does the img folder has to be?

                Thank you,
                NSchweig

                • 5. Re: Images not shown at first page invocation
                  nbelaevski

                  The problem with relative images is that JSF actions by default use forwarding, i.e. do not change the path by which the page is known to the browser. Possible solutions are usage of redirect or absolute image paths.

                  • 6. Re: Images not shown at first page invocation
                    nschweig

                    Hi,

                    i have got a solution.

                    It is possible to set the root direction with the base tag (in the head-tag in the basic-template from your facelets-pages)

                    <base href="#{facesContext.externalContext.request.scheme}://#{facesContext.externalContext.request.serverName}:#{facesContext.externalContext.request.serverPort}#{facesContext.externalContext.requestContextPath}/"/>


                    That makes sense if you have a directory structure like

                    application
                    - pages
                    - img
                    - css

                    Thank your for answers.
                    NSchweig



                    • 7. Re: Images not shown at first page invocation
                      ilya_shaikovsky

                      be careful with this if planning to use rich:editor component.