graphic image "src/value" from database - database

i use primefaces on jsf framework, i have in my database a field that save the url source of where the image was saved for example:
Table Person:
id: integer
name: varchar
img: varchar ("C:\images\person\person1.jpg")
so, in my method in java y return that url string but when i put to the graphic image label
it load like this http://localhost:8080/..../C:\images\person\person1.jpg
any ideas???
<p:graphicImage value="#{person.img}"/>
this line is in pure html
<img src="C:\images\person\person1.jpg" alt=""/>

It seems that you're expecting that image to be served by the default servlet or as a JSF resource since it's on your filesystem. This won't happen unless that imagine is part of your web-app.
In order to serve it, return a StreamedContent object from your method, something like this return new StreamedContent(new FileInputStream(getPathFromDatabase()));. Note that the returned property should be available in session scope or request scope, because the image is served by the Primefaces resource handler in a separate request. This means that if you return the StreamedContent object from a view scoped bean, it won't be available on subsequent requests.

The value attribute of graphicImage is a relative url (or a binary stream if you implement StreamedContent), relative to your context.
That means it is appended to the url of your application, resulting in something like: http://hostname:port/appname/relative_image_url.

Related

not able to dynamically update the view when data is changing

I have a set of files in a server which I am looping though and constructing a JSOn and saving it as a separate file. I am using python for this. Works quite well. Now the scope is the number of files in the directory will increase/ change throughout the day..and I am running the script every 10 min to rewrite the json...the file name stays same and i am calling it in a single page html document using angular.js..Again fairly simple...But now I am having problem when the JSON is changing I am not seeing any change on the page unless I reload the page. Could I do something about this?
With angular I am using
$http('something.json').success(callback function with some argument data)
and in the markup something like
<ul>
<li ng-repeat="x in data">{{x.id}}</li>
</ul>
Your call to $http is one-time operation which happens after page load like this:
$http('something.json').success(function(data){
$scope.data = data;
});
angular is kickstarted
ng-controller containing $http request is evaluated and request for 'something.json' is sent
...
when your json arrives, your success function is called with data from json
view (html template) is updated with new data
Angular keeps your model (eg $scope.data) and UI (expressions in template) up to date, but it doesn't update external resources.
If you want to periodically poll for changes in 'something.json'
you can use $timeout service as suggested in JaKXz's comment.

.Net Winfoms WebBrowser control - When content loaded from Stream, how to permit submit operation?

I am using the WebBrowser control on a Windows Forms application in Visual Studio 2010 - targeting .Net framework 3.5.
I have loaded the contents of the WebBrowser control via setting the DocumentStream property. The stream content is from the response to an Http (POST) request to a third party web page which is called in code using the HttpWebRequest object. We need to use the POST request verb type. The form is populated with data based on the request parameters.
Within the Windows application, the user needs to fill out a few additional text fields and then submit. Having been loaded via the stream, the page has no knowledge of full url of the original page. Therefore the submit fails (displays the name of the page in the WebBrowser control).
Is there any way to give the control the full path to the document such that the Submit operation will have the correct context? Setting WebBrowser.Url property does not work as this simply results in navigation to the page without the data displayed as it is not passed any parameters.
Below is the code (so far):
//Class to call website to make http post
var webBridge = new WebCallHandler();
//Make the request. Response returned as string
var result = webBridge.MakeHttpRequest();
//Get string as stream
var byteArray = Encoding.ASCII.GetBytes(result);
var stream = new MemoryStream(byteArray) { Position = 0 };
//webBrowser1.Url = new Uri(URL);
webBrowser1.DocumentStream = stream;
//Need to set the context of the page like "http://example.com/somepage.aspx"
var dom = webBrowser1.Document.DomDocument;
If you have filled the result variable (which seems to be a string), you should rather easily be able to modify the contents.
Using e.g. Regular Expressions or HTML Agility Pack to search for the
<form ... action="relative-url" ...
and replace it with
<form ... action="http://somedomain.com/relative-url" ...
then pass it to the DocumentStream property of your browser.
I searched the string being returned from the HttpWebrequest for the form element action attribute. This only showed the name of the page received from the httpWebRequest. I modified it in code to be the full url.
Thanks for your comment Kevin. This was the prompt that helped.

get_serving_url usage in template? (=gae issue 3688)

How can I use the function get_serving_url to display an image referenced by an entity in a template? The situation is something like this and won't work:
{{ a.matched_images.get().get_serving_url() }}
Can you please help me how to achieve a thumbnail image with get_serving_url in a template?
This issue is acknowledged
Thanks
Fetch the URLs and zip them up with your images in a list before passing them into Django - you really shouldn't be calling API methods from inside your templates anyway. Alternately, create a method on your datastore model that does this, and pass in the entity or entities holding the blobs.
Nicklas R's thread in in the GAE Google Group explains how he actually solved it:
It works like proposed like this in template:
<img src="{{ ad.uri2view }}">
With backend function added to model:
def uri2view(self):#enable get_serving_url
return images.get_serving_url(str(self.matched_images.get().primary_image.key()))+'=s120'

JsonStore - Load single record with a restful url?

All,
I have a JsonStore backing a form panel in my extjs app. I want to have the jsonStore load a single record based on an id value, but haven't found a good way to do that yet, and still keep the url restful.
My first attempt was to add a param to the jsonstore load() method with the id in it. That only adds the id as a request param, not attached to the url:
http://my-app/users/?id=123
instead of what i want:
http://my-app/users/123
Can someone help me out with this?
You can manually construct the URL that the store uses to query for data (via the implicit HttpProxy it creates for the URL). So your loading function would look like:
function store_refresh() {
json_store.proxy.conn.url = 'http://my-app/users/' + user_id;
json_store.reload();
}

GWT, access RichTextArea by non-GWT (or "regular") javascript

I am writing a pretty simple CMS on GAE, and I want my users to be able to upload images.
I have written the part that does the actual uploading and showing the images, and here's what I'd like to do:
Show the usual form for new posts (with a widget that contains a rich text area and a format bar for it) and the list of images the user has ever uploaded (done). Then i want an image to appear in the text area when the user clicks that image.
I generate the list of images on the server, and i can't find a way to call any methods on the Rich Text Area from non-GWT javascript. And I don't really want to generate the list of images by means of AJAX, because it seems quite cumbersome and, hopefully, with the advent of HTML5 it is going to be much simpler.
Well, the question is, how can i access a RichTextArea in a widget from a normal javascript on a page, or is there another way of inserting an image into it (i.e. another is there a way to generate a list of images so that they would be in a kind of widget, but without the use of AJAX).
Thank you.
To answer your general question of getting access to your GWT code from hand written Javascript, you can use the general built in method or Ray Cromwell's gwt-exporter project. This way, you can expose the specific methods of the RichTextArea instance you're trying to access from external Javascript.
As for your other question, generating a list of Images should only require getting the urls for the images and creating a bunch of Image objects with the given URLs. Then display this list in a PopupPanel or some other widget.
Here is how i finally solved the problem (thanks to Arthur's reply above):
public class NewSection implements EntryPoint {
private static RichTextAreaWithFormatBar rta;
private Button pseudoSubmit;
#Override
public void onModuleLoad() {
invokeExternal("hello");
rta = new RichTextAreaWithFormatBar();
pseudoSubmit = new Button(">>>");
<...>
}
<some other code here>
public static void addImage(String a) {
rta.textarea().setHTML(
rta.textarea().getHTML() + "<br /><img src=\"/cms/i/"+ a +"\" alt=\"\"><br />");
}
native void invokeExternal(String int1) /*-{
$wnd.externalJsFunction(function(int1) {
#ur.g05.smc.client.NewSection::addImage(Ljava/lang/String;)(int1);
});
}-*/;
}
And here is the "hand-written" javascript in my templates:
(first the FreeMaker code for creating the image list in that same template):
<#list images as i>
<td><img src="/cms/i/${i.keyString()}.t" alt='' onclick='addImage("${i.keyString()}.p");'/><br /><p>${i.fullWidth()}·${i.fullHeight()}</p><p>${i.previewWidth()}·${i.previewHeight()}</p><p>${i.thumbWidth()}·${i.thumbHeight()}</p></td>
</#list>
And the script itself:
<script language="javascript">
var callBackFunction;
function externalJsFunction(func) {
callBackFunction = func;
}
function addImage(imgid) {
callBackFunction(imgid);
}
</script>
What in fact happens is:
First we create a list of images, adding an "onClick" listener to each of them with the url of each corresponding image as the argument. Image urls are formed from their Keys in the datastore, plus ".t" for thumbnails, ".p" for previews and nothing for full-size images.
Each image than calls the "addImage" function. But the addImage function has to know about the textarea, which it doesn't. To that end we create the "callBackFunction" variable, and the "externalJsFunction", that sets the value of that "callBackFunction" variable. And it sets it to whatever it gets as the argument.
Now, we can call that externalJsFunction from our Widget code and pass the function that adds an image to the textarea. However, i couldn't make it work while the richtextarea was not static.
That's basically it.
And thanks for replies and votes :)

Resources