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

  • Home
  • SEARCH
  • 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 8230585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:11:08+00:00 2026-06-07T17:11:08+00:00

I have created image using svg and javascript I want user to be able

  • 0

I have created image using svg and javascript I want user to be able to save it. How do I send this to bean and save it?

view code:

<script>
        var svg = $('#map').html().replace(/>\s+/g, ">").replace(/\s+</g, "<");
            // strips off all spaces between tags

            canvg('cvs', svg, {        
                ignoreMouse: true, 
                ignoreAnimation: true
            });  
         var canvas  = document.getElementById('cvs');
         var img = canvas.toDataURL("image/png"); 
   </script>

<h:body>
        <center><div id="map"></div></center>
        <a href="#" id="saveBtn">SAVE</a>
        <canvas id="cvs" width="0" height="0" ></canvas>​  
        <h:form id="formId">
            <h:inputText id="inputId" value="#{bean.property}" />
            <h:commandButton id="buttonId" value="Button" action="#{bean.action}" />
        </h:form>
    </h:body>
  • 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-07T17:11:10+00:00Added an answer on June 7, 2026 at 5:11 pm

    You can send the dataURL to the backing bean via an hidden input field like this:

     <h:form>
        <h:inputHidden id="dataURL" value="#{userBean.dataURL}" />
        <h:commandButton value="Submit" action="#{userBean.submit}"/>
     </h:form>
    

    and set the value of the inputHidden value from your javascript like this:

    var dataURL = canvas.toDataURL("image/png");
    var hidden = document.getElementById("dataURL");
    hidden.value = dataURL;
    

    UPDATE: The toDataURL method returns a string and you can save the same as string in the backing bean, the string is base64 encoded so it can be decoded back into an image and saved to disk at the root of the webapp:

    public class UserBean implements Serializable {
        private String dataURL;
        public String getDataURL() {
        return dataURL;
    }
    public void setDataURL(String dataURL) {
        this.dataURL = dataURL;
    }
        public void submit(){
          ExternalContext external = FacesContext.getCurrentInstance().getExternalContext();
          ServletContext servletContext = (ServletContext) external.getContext();
          String filename = servletContext.getRealPath("cloud.png");
          BASE64Decoder decoder = new BASE64Decoder();
          byte[] decodedBytes = decoder.decodeBuffer(dataURL.split("^data:image/(png|jpg);base64,")[1]);
          BufferedImage imag=ImageIO.read(new ByteArrayInputStream(decodedBytes));
          ImageIO.write(imag, "png", new File(filename));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a DeclarativeServiceLibrary using VS2010 beta 2, Please check this image of
I have problem with dynamically created image (JavaScript). I want to change the innerHTML
i have created a disk image using disk utility. but i want to add
I have created a custom button using this code setup : function(ed) { ed.addButton('Tittle',
I have a greyscale image which was created from a RGB image using farmula:
Using Eclipse IDE. The line: getClass().getResource(/res/bitmaps/image.png); returns null . I have created the res
i have created one image but problem is that when i save image from
I have created a Windows CE6 Image through Platform Builder, and I now want
I have created a custom server control and trying to add an image using
I have created a image div in html and below is the code <div

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.