Announcement Announcement Module
Collapse
No announcement yet.
using byte[] for HTMLArea like field Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • using byte[] for HTMLArea like field

    Hi. In my web application, I want to give one big textarea like field where user can edit their text, check spelling, add image, etc. I am using HTMLArea, a custom field with all these facilities. I am having problems in saving this field in MySQL database. I am using spring-hibernate-mysql combination on tomcat webserver.

    My bean looks like:
    public class Description {

    private long id;
    private byte[] detail;

    /**
    * @hibernate.property type="org.springframework.orm.hibernate3.support.B lobByteArrayType"
    */
    public byte[] getDetail() {
    return detail;
    }
    public void setDetail(byte[] detail) {
    this.detail = detail;
    }

    /**
    * @hibernate.id generator-class="hilo"
    */
    public long getId() {
    return id;
    }
    public void setId(long id) {
    this.id = id;
    }

    }

    What jsp code can show this field please? my servlet config file is description-servlet.xml. What would be the config code?

    Can I use java.sql.Blob instead of byte[]? How can I show this in jsp when the content can be text, images?

    Thanks very much for any help.

  • #2
    You won't be able to

    You (AFAIK) cannot embed images directly in a HTML form, they need to be loaded via a seperate request using the img tag. Headers would also be different (i.e. contentType) for html/images....

    Comment


    • #3
      I'm not that experienced in Hibernate (yet) but is there any reason to not use a String property?

      If you did then to output the content you want (assuming your instance of Description is in the Model with key "description") would be
      Code:
      <c&#58;out value="$&#123;description.detail&#125;" escapeXml="false" />
      If you need to use the byte array to keep hibernate happy consider adding the following method to your Description class...
      Code:
      /**
       * No hibernate mapping this is transient.
       */
      public String getHtml&#40;&#41; &#123;
          return new String&#40; detail &#41;;
      &#125;
      you could then use the following in your JSP
      Code:
      <c&#58;out value="$&#123;description.html&#125;" escapeXml="false" />
      HTH

      Jon

      Comment


      • #4
        Hi. Thanks very much to yatesco and sharebear for replies.

        I wanted to use this replacement of html TextArea: HTMLArea(http://www.htmlarea.com/). It gives the user to add text and if anyone wants to put an image with the text, then can also do it. This htmlarea gives pure html code so if a user writes in the description field:

        <b>New user</b> to spring. one image:
        <img src="http://localhost:8080/infosys/Sunset.jpg" />

        <i>want to add another image</i>: <img src="http://localhost:8080/infosys/Sunset2.jpg" />

        -----
        Can you please suggest how can I save these information so when I will retrieve it from db I can show it exactly the same way?

        Thanks a lot for helping me.

        Best Regards.

        Comment


        • #5
          First off, from the website you posted...
          htmlarea 2 and 3 have been discontinued.
          Personally I'm liking tinyMCE at the moment but FCK-Editor (sorry don't have the link to hand) is another popular free replacement.

          Whichever editor you use doesn't really matter as they all work from the same principal...by replacing a standard (x)html <textarea>...

          To do this you need to use your Description class as the "Command" object in a SimpleFormController( of which you need to subclass and override one of the onSubmit methods to persist your data, this is all dealt with in the Spring MVC step-by-step tutorial ).

          Then in the JSP used as your formView you need something like the following. Obviously you also need to include the necessary javascript for your chosen editor in the head of the html, you may also need to modify the textarea to suit the requirements of your chosen editor.

          Code:
          <spring&#58;bind path="description.detail">
              <label for="frmDetail">Enter Description</label>
              <textarea id="frmDetail" name="detail">$&#123;status.value&#125;</textarea>
          </spring&#58;bind>

          HTH

          Jon

          Comment


          • #6
            Hi. I tried to use tinyMCE but its buttons do not work in my case. I tried to go through their forum but still couldn't make it work. I tried in firefox1.0.6 & IE. I followed their installation instruction but it does not work. Have you faced any problem with tinyMCE? I will also try to post my problem in their forum.

            I am again at this moment using that HTMLarea. In my description textarea field in jsp, I get the texts and the images entered by user as String. I have saved this to the database and when I read it for editing, it works fine. But I want to upload those images and save somewhere else. So in the string of description field, the <img src...> tag is to be modified and replaced with new URI so then I will get these images from where I store them.

            Do you think this way is ok or can you please suggest a better way?

            Thanks very much for all your help.

            Best Regards.

            Comment


            • #7
              Have you faced any problem with tinyMCE?
              Not that I remember, but I have a tinyMCE integration project to do tomorrow (although in PHP not Java) so will let you know if I hit any probelms.
              I tried to use tinyMCE but its buttons do not work in my case.
              What do you mean by not working, the images aren't displaying or the buttons do not function correctly?
              But I want to upload those images and save somewhere else. So in the string of description field, the <img src...> tag is to be modified and replaced with new URI so then I will get these images from where I store them.
              This sounds challenging, if I understand you right you want to allow people to enter <img src="http://not-my-site.com/someImage.jpg" /> and then when they submit you want to grab that image, save it on your own server and then modify the url in the image tag to point to http://my-site.com/someImage.jpg .

              This is possible, get the image url from the content using a regular expression, download the image to your server using a http client library, then replacing the original url with the new one is trivial.

              Can't understand why you would want to go through all that though, why not just leave the direct link in? If the user has the rights to use the image as they wish why not just use an image upload form to take out the complications?

              Jon

              Comment


              • #8
                Hi. Thanks very much for replying. In tinyMCE, whenever I press those buttons like html, image, etc. it shows 404 status message. I actually couldn't remember what exactly was that message but it was some sort of 'resource not available message'. But when I press button in their examples, it works fine. I think i forgot something in configuration or something.

                But at the moment I am very happy as it seems I have done the way I wanted. I couldn't do many things in my life, but I have parsed those html code generated by HTMLArea using this Jericho HTML parser and uploaded those using HTTPClient and then I saved those images in my db and replaced the original img src='...' with a request for my imagecontroller like src='/imageController.htm?id=' and then I streamed the images when the user want to edit the description.

                Whew!!! a lot of things worked for me at this time. I will now clear the piles of messed up codes. If you need I can give a outline of my codes.

                Thanks very much for all your help.

                Best Regards.

                Comment


                • #9
                  Hi. I just wanted to add that people say its not good to save images in db. I will shift these images to filesystem in an OS independent manner in my next iteration. If you have any codes or know any sources for this please give me a link.

                  Thanks. Have a nice time.

                  Comment

                  Working...
                  X