How to refresh p:graphicImage which gets image from servlet? - jsf-2

I have multiple <p:graphicImage>s which gets the image from a servlet by ID. I need to refresh the image when the user has removed or changed the image, so that it disappears or changes instead of showing the old one.
How can I achieve this? Could I use JavaScript or jQuery for this?

Related

Is there a way to execute a javascript function at the end of a WebForms event?

I have a screen I am creating to manipulate a document. As part of the web form I have a table of page thumbnails on the left side with controls for the current page in the main portion of the screen. When a thumbnail is clicked an UpdatePanel in the body section is updated with the info for that page.
I have just added the ability to change the order of the pages by dragging the thumbnails up and down. This uses JqueryUI's Sortable feature with a hidden asp:Button to communicate the changes back to the server.
All of that works when used separately. However, when I click a thumbnail to select a page the table that they are in looses the sortable property. I can easily re-establish it using a JavaScript command. But how do I call a Javascript command at the end of the WebForms event?
It is strange that after clicking on a thumbnail the script is broken. But you would have to post some source code and ASPX/ASCX to investigate that.
But it is possible to execute some javascript at the end of a postback. Have a look at this documentation:
https://learn.microsoft.com/en-us/previous-versions/aspnet/bb398976(v=vs.100)
I think you want to have a look at the 'pageLoaded' or 'endRequest' events, maybe you can call your javascript from there.

Select2 - Add pending tag after losing focus

I am trying to use select2 for creating tags, but when I'm writing a new tag and I lose the focus of the field (click somewhere else, for example) what I was writing gets deleted.
Is there a way that after losing focus to the input of the select2, a new tag gets created?
From the documentation:
$('select').select2({
selectOnClose: true
});
This will capture the selection and create a tag if the user clicks elsewhere.
It looks like the browser problem that i've seen.
It seems that the tags option doesn't work correctly on ie11.
I don't have the same behavior between ie11 and chrome (and edge). If you check the example https://select2.github.io/examples.html#tags with ie, it is not possible to add tag. You can start taping letter but you lose the focus immediately.
Everything works on Chrome and Edge.
Is it this sort of problem, you've got.

How to restrict right click option on the image?

I m designing my portfolio in ruby on rails. In order to restrict the image from being copied, i wanted to disable the right click and other features of copying an image from the website. How to do it?
In most modern browsers you can disable the right-click menu for a particular image. To do so, you can use the event handler oncontextmenu="return false;" within the IMG tag that defines your image:
<IMG border=0 src="..." oncontextmenu="return false;">
For example, the context menu has been disabled for this image:
Note: In older browsers (e.g. Internet Explorer 4.x or earlier) this trick won't work. Also, the context menu will show up if the user has disabled JavaScript.
As all others already said: It's not possible in a reliable way. Only thing you can consider is to watermark your images.
You can disable the right click with javascript.
However, this is a pretty bad idea.
Since your images are sent to the browser of the visitor, they will be accessible, either by displaying the source or analyzing the HTTP requests, in the cache files, or simply screenshoting.
You should not break the user navigation by disabling the right click, your images will be copiable and there's nothing you can do about it. Deal with it.
Sadly its not possible to stop people from copying an image on your page.
Simply disabling right click would not be enough, anyone could just view the source to see the image url
http://www.hypergurl.com/norightclick.html
This guy has mentioned that we can add a transparent gif image to restrict the copy function but i am not getting how to do it. I m displaying my images inside carousel. And carousel gets very tricky sometimes. Also ive uploaded my images in cloudinary so if a person can get the URL of an image then he needs certain parameters to access it which only the owner has.

Refresh browser?

I am working with images and changing their sizes dynamically from the input I get from the user.
when I change the size of the image first time it doesnot reflect the changes when I click the refresh the page using the browser button the change gets reflected and after that tere is no need to click the refresh button
Please tell how shall I do it so that there is no need to click the refresh button of the browser ,the changes but get reflected at one shot.
Thanks
Ritz
Your browser is cacheing the image. One easy way to get around this is to append something to the image URL such as "?v=101", "?v=102", etc. where the number is a version # you track on each image.
E.g.:
http://mysite.com/image.jpg?v=101
http://mysite.com/image.jpg?v=102
http://mysite.com/image.jpg?v=103
...
Or:
http://mysite.com/imagegen.php?name=foo&v=101
http://mysite.com/imagegen.php?name=foo&v=102
http://mysite.com/imagegen.php?name=foo&v=103
...
You don't have to look at the version number in your code, but its presence on the URL makes the browser think it's a different resource and therefore load it again without having to refresh.

Stop images from caching in Rails and browser?

I have created a image crop facility that I can click on an image and crop it and it saves the new cropped image over the old one, then redirects back to the original page where the image was show.
But it still shows the old image even after a redirect and doesn't display the new one till I refresh the page.
I have tried just using an image tag and removing the asset timestamp after the image but it still displays the old image and I have also tried adding meta tags to stop browser caching but not working.
How can I solve this without having to do a refresh page?
It's probably not the best way, but I've solved this problem in the past by simply appending a timestamp to the image URL using JavaScript:
http://www.mysite.com/img/some_image.jpg?timestamp=12342312412
Next time it loads, the timestamp is set to the current time and the URL is different, so the browser does a GET for the image instead of using the cached version.
Are you using the rails image helper tag: image_tag in your views?
Rails automatically appends a timestamp based on the last modified date of the image file which is handy because it should change when you do your crop and write out the new image.
More information in the docs: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html

Resources