Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:20:38+00:00 2026-06-02T09:20:38+00:00

I have a JSF page on which i have 8 images like. * For

  • 0

I have a JSF page on which i have 8 images like.

*For jquery viewer Only:
Please donot confuse with the JSf syntax. Behind the scenes it’s all converted to plain HTML. Like h:panelGrid convert into table element. p:graphicImage convert into img element.Actually i want to know the logic to load images using jQuery ajax. Like using jQuery i call the server, then get the images from database and when images load completely on the path, then i change the img src attribute to change the default image with the loaded one.
When page loads the on the default path there is a default image like /resources/images/no-preview.jpg. So i want that when images loaded then i replace it with like /resources/images/Image1.jpg, /resources/images/Image2.jpg and so on *
.

<h:panelGrid columns="5" width="10%" style="position: relative; top: 50px; "
             columnClasses="asteriskColumns, nameColumns" >

    <h:outputText value="*" />
    <h:outputText value="Map: " />
    <p:fileUpload id="cityMap" widgetVar="uploader" description="Image"
                  update="city" allowTypes="*.jpg;*.png;*.gif;*.jpeg;"
                  auto="true" fileUploadListener="#{cityDetail.imageUpload}"
                  style="position: relative;"  >

    </p:fileUpload>

    <p:graphicImage id="city" value="#{cityDetail.imagePath}" width="80"
                    height="50" cache="false" style="position: relative;">

        <f:event type="preRenderComponent" listener="#{cityDetail.putImage}" />

    </p:graphicImage>

    <h:commandLink value="remove" title="Remove Picture"
                   style="color: #0d5b7f;text-decoration: underline;"
                   onclick="if (! confirm('Are you sure, you want to remove picture?') ) { return false;}; return true; ">

        <f:ajax event="click" render="city" listener="#{cityDetail.removeImage}"/>

    </h:commandLink>
    .....
    7 more images in same format

</h:panelGrid>

In the constructor i am suing something like this to get images from database

public class CountryPages_Detail {
    private String imagePath = "/resources/images/no-preview.jpg";
    String path = externalContext.getRealPath("/resources/images") + "/" ;
    public CountryPages_Detail() {
        ....
        String cityMapQuery = "SELECT citymap From city Where cityid='" + cityID + "'";
        String countryMapFileName = "countryMap_" + saarcCountryId;
        // 7 more queries in same format

         ArrayList countryMapQueryArray = addCredentialsToList(externalContext, countryMapQuery, countryMapFileName, response);
         //7 more

         ArrayList mainArray = new ArrayList();
         mainArray.add(countryMapQueryArray);
         ...
         ArrayList result = ConnectionUtil.showImagesFormDatabase(mainArray);
    } //end of constructor     
} //end of class CountryPages_Detail

public static ArrayList showImagesFormDatabase(ArrayList list) {
    for (int i = 0; i < list.size(); i++) {
        ArrayList fileCredentialsList = ((ArrayList) list.get(i));
        String query = fileCredentialsList.get(0).toString();
        sqlStatement = conn.createStatement();
        resultSet = sqlStatement.executeQuery(query);
        if (resultSet != null) {
            while (resultSet.next()) {
                imageBytes = resultSet.getBytes(1);
                setResponceForDatabaseImages(fileCredentialsList);
                imageName = createFile(fileCredentialsList, imageBytes);
                if (imageName != null) {
                    imageNameList.add(imageName);
                }
            } //end of while()
        } //end of if()
    } //end of for()

    return imageNameList;

} //end of showImagesFormDatabase()

As you can see i get images from database when page loads. Get the images bytes from database, then create imagefile on the path from that bytes. But i have 8 images. If any of the image size is large then i have to wait which is frustrating.

I want that when page loads, then instead of laoding images from database i use ajax. Means my rest of the page get loads and images get load from behind the scenes and when all images get load then the images shown in the p:graphicImage. While image is loading then the loading icon should be displaying in the p:grahicImage and when image loads completely then icon gone and image should be shown.

How can i do it?

Thanks

Edit:
————————————————————————————

 <ui:define name="content">
     <h:form id="faqAddUpdateForm" prependId="false">
         <h:panelGrid columns="5" width="10%" style="position: relative; top: 50px; "
             columnClasses="asteriskColumns, nameColumns" >
         ....
         </h:panelGrid>
     </h:form>

     <h:form id="hidden" style="display:none">
                <h:commandLink id="link">
                    <f:ajax event="click" listener="#{countryPages_Detail.loadImagesUsingAjax}" />
                </h:commandLink>
     </h:form>

     <script>
         window.onload = function() {
             document.getElementById('hidden:link').onclick();
          }
      </script>
 </ui:define>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:20:41+00:00Added an answer on June 2, 2026 at 9:20 am

    You could load the images, when document is ready. However, the h:body onload does not work (as reported in BalusC’s answer here).

    The referenced answer will give you a way to get it working. You need to trigger a hidden commandLink that has an ajax listener attached. The listener should call the method that produces the images and the ajax call should update the component containing the images.

    To partially update your page on an ajax call, use the render attribute of f:ajax:

    <h:commandLink id="link">
       <f:ajax event="click" 
               render=":faqAddUpdateForm"
               listener="#{countryPages_Detail.loadImagesUsingAjax}" />
    </h:commandLink>
    

    render=":faqAddUpdateForm" will render the whole form. If that is too much, give your panelGroup that contains the images an id (e.g. “imageGroup”) and use this id in the render attribute:

    render=":faqAddUpdateForm:imageGroup"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a resources web app, which only has static content, such as images,
I have a pretty complex JSF page (we use JSF2 with facelet) in which
I have JSF 1.1 page in which I have a <h:selectOneListbox . When I
I'm trying to import this page to my JSF page which is gonna have
I have a JSF project and I already have an index.xhtml page which is
I have a JSF page that includes a tree form tag which is rendered
I have a JSF page which is outputting XHTML (from a facelet). One of
I have a JSF page which has a variable number inputText elements containing numeric
I have a JSF page that accepts a viewparam and sets a variable which
I have a JSF page on which I want to have a checkbox that,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.