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 9070519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:42:10+00:00 2026-06-16T17:42:10+00:00

I have a wicket page which has a link ADD PRODUCT . On clicking

  • 0

I have a wicket page which has a link ADD PRODUCT. On clicking the link a modal window open which takes the product information.

ProductAddPanel.java

public class ProductAddPanel extends Panel {

private InlineFrame uploadIFrame = null;
private ModalWindow window;
private Merchant merchant;
private Page redirectPage;
private List<Component> refreshables;

public ProductAddPanel(String id,final Merchant mct,ModalWindow window,List<Component> refreshables,Page p) {
    super(id);
    this.window = window;
    merchant = mct;
    redirectPage = p;
    this.refreshables = refreshables;
    setOutputMarkupId(true);
}

@Override
protected void onBeforeRender() {
    super.onBeforeRender();
    if (uploadIFrame == null) {
        // the iframe should be attached to a page to be able to get its pagemap,
        // that's why i'm adding it in onBeforRender
        addUploadIFrame();
    }
}


//    Create the iframe containing the upload widget
private void addUploadIFrame() {
    IPageLink iFrameLink = new IPageLink() {
        @Override
        public Page getPage() {
            return new UploadIFrame(window,merchant,redirectPage,refreshables) {
                @Override
                protected String getOnUploadedCallback() {
                    return "onUpload_" + ProductAddPanel.this.getMarkupId();
                }


            };
        }
        @Override
        public Class<UploadIFrame> getPageIdentity() {
            return UploadIFrame.class;
        }
    };
    uploadIFrame = new InlineFrame("upload", iFrameLink);
    add(uploadIFrame);
}

}

ProductAddPanel.html

<wicket:panel>
<iframe wicket:id="upload" frameborder="0"style="height: 600px; width:    475px;overflow: hidden"></iframe>
</wicket:panel>

I am using a Iframe to upload the image. I have added a iframe to my ProductPanel.html. Because it is not possible to upload file using ajax submit.

UploadIframe.java

protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                DynamicImage imageEntry = new DynamicImage();

                if(uploadField.getFileUpload() != null && uploadField.getFileUpload().getClientFileName() != null){
                    FileUpload upload = uploadField.getFileUpload();
                    String ct = upload.getContentType();

                    if (!imgctypes.containsKey(ct)) {
                        hasError = true;
                    }

                    if(upload.getSize() > maximagesize){
                        hasError = true;
                    }

                    if(hasError == false){
                        System.out.println("######################## Image can be uploaded ################");
                        imageEntry.setContentType(upload.getContentType());
                        imageEntry.setImageName(upload.getClientFileName());
                        imageEntry.setImageSize(upload.getSize());
                        if(imageEntry != null){
                            try {
                                save(imageEntry,upload.getInputStream());
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }else{
                        target.appendJavaScript("$().toastmessage('showNoticeToast','Please select a valid image!!')");
                        System.out.println("#################### Error in image uploading ###################");
                    }
                }else{
                    System.out.println("########################### Image not Selected #####################");
                }

                MerchantProduct mp =new MerchantProduct();
                Product p = new Product();
                Date d=new Date();
                try { 

                    p.setProductImage(imageEntry.getImageName());
                    mp.setProduct(p);

                    Ebean.save(mp);


                } catch (Exception e) {
                    e.printStackTrace();
                }

                for(Component r: refreshables){
                    target.add(r);
                }

                window.close(target);
                setResponsePage(MerchantProductPage.class);
            }

public void save(DynamicImage imageEntry, InputStream imageStream) throws IOException{
    //Read the image data
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    copy(imageStream,baos);
    baos.close();
    byte [] imageData = baos.toByteArray();
    baos = null;

    //Get the image suffix
    String suffix = null;
    if("image/gif".equalsIgnoreCase(imageEntry.getContentType())){
        suffix = ".gif";
    }else if ("image/jpeg".equalsIgnoreCase(imageEntry.getContentType())) {
        suffix = ".jpeg";
    } else if ("image/png".equalsIgnoreCase(imageEntry.getContentType())) {
        suffix = ".png";
    }

    // Create a unique name for the file in the image directory and
    // write the image data into it.
    File newFile = createImageFile(suffix);
    OutputStream outStream = new FileOutputStream(newFile);
    outStream.write(imageData);
    outStream.close();
    imageEntry.setImageName(newFile.getAbsolutePath());

    }

    //copy data from src to dst
    private void copy(InputStream source, OutputStream destination) throws IOException{
        try {
                // Transfer bytes from source to destination
                byte[] buf = new byte[1024];
                int len;
                while ((len = source.read(buf)) > 0) {
                    destination.write(buf, 0, len);
                }
                source.close();
                destination.close();
                if (logger.isDebugEnabled()) {
                    logger.debug("Copying image...");
                }
            } catch (IOException ioe) {
                logger.error(ioe);
                throw ioe;
            }
        }

    private File createImageFile(String suffix){
        UUID uuid = UUID.randomUUID();
        File file  = new File(imageDir,uuid.toString() + suffix);
        if(logger.isDebugEnabled()){
            logger.debug("File "+ file.getAbsolutePath() + "created.");
        }
        return file;
    }
}

}

I am using setResonsePage() to redirect to initial page on which “Add Product” link is present. So that i get the refreshed page having new product information.

My problem is that modal window is not closing on window.close() and inside that window i am getting the refreshed page.

My requirement is that Modal window should close and page should be refreshed. I am passing the Parentpage.class in my setResponsePage().

Any help and advices appreciated! Thanks in advance.

  • 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-16T17:42:11+00:00Added an answer on June 16, 2026 at 5:42 pm

    In the ParentPage.class on which modal window is open i called setWindowClosedCallback() method in which I am adding getPage() to target so that page will refresh when modal window is closed.
    Here is the code for same

    modalDialog.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() 
       { 
               private static final long serialVersionUID = 1L; 
    
               @Override 
               public void onClose(AjaxRequestTarget target) 
               { 
                   target.addComponent(getPage()); 
               } 
       });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wicket page , which contains two Spring-managed beans , one is
I have a Wicket AuthenticatedWebApplication which has several pages and features that need to
I have a Wicket page which will dynamically display an image. Let's say the
I have a wicket MultiLineLabel which has its contents coming from database. Now I
I have a modal dialog in Wicket that contains a link. I need to
Situation In my Wicket application, I have a page which contains two tags. Each
I am new to wicket. I have a wicket application class from which has
I have created a web page in wicket and mounted it. The url looks
I have the following html: <label wicket:id=drugSearchResult.row.item.label for=drug_1>[Drug XYZ] <span wicket:id=drugSearchResult.row.item.info>[Information, Price, Other]</span> </label>
I have input text: <div><label wicket:for=name>Name</label><input type=text wicket:id=name /></div> Now I need to add

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.