Providing text through JavaScript [message #1729594] |
Fri, 15 April 2016 18:04 |
z232 I Messages: 48 Registered: February 2016 |
Member |
|
|
Hi,
i have created a Xtext web application (version 2.9).
The ace editor library is been used for inserting text thru the persistent layer.
My next step is to provide text direct to the server but i am a little bit confused on how to do that.
kind regards
[Updated on: Thu, 20 May 2021 15:05] Report message to a moderator
|
|
|
|
Re: Providing text through JavaScript [message #1729597 is a reply to message #1729595] |
Fri, 15 April 2016 18:40 |
z232 I Messages: 48 Registered: February 2016 |
Member |
|
|
Hi Christian ,
I have tried to send a http request but without luck
I used 'PUT' method with parameters uri, url and Data .
js code:
var uri = resource_id();
var url = "http://localhost:8080/xtext-service/update?resource="+uri+".edl";
var method = "PUT";
var postData = "deltaOffset=0&deltaText=Experiment&deltaReplaceLength=0&requiredStateId=-"+resource_cntdown();
var async = true;
var request = new XMLHttpRequest();
request.onload = function () {
var status = request.status; // HTTP response status, e.g., 200 for "200 OK"
var data = request.responseText; // Returned data, e.g., an HTML document.
}
request.open(method, url, async);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); //application/json;charset=UTF-8
request.send(postData);
kind regards
[Updated on: Thu, 20 May 2021 15:05] Report message to a moderator
|
|
|
|
Re: Providing text through JavaScript [message #1729826 is a reply to message #1729598] |
Tue, 19 April 2016 11:53 |
z232 I Messages: 48 Registered: February 2016 |
Member |
|
|
Hi Christian ,
i have visited the above link (https://www.eclipse.org/forums/index.php?t=msg&th=781817&goto=1722463&#msg_1722463) and have adopted the POST code of the latter .
My Code
require(["../webjars/jquery/2.1.4/jquery.min"], function() {
jQuery(document).ready(function() {
jQuery("#post").click(function(e){
set_resource=$("#post_area_2").val(); // get text of from postarea_2
var data = {
resource : set_resource,
fullText : $("#post_area_1").val()
};
jQuery.post('http://localhost:8080/xtext-service/generate', data, function(result){
jQuery("#generator-result").text(result);
});
alert('http://localhost:8080/xtext-service/generate data resource = '
+ data.resource +" data.fullText = "+ data.fullText );
});
});
});
<textarea id="post_area_1" rows="1" cols="10">My Post message </textarea>
<textarea id= "post_area_2" rows="1" cols="5"> </textarea>
<button id="post" value="Generate" title="Generate">Post</button>
<div id="generator-result"></div>
While posting a message, i get the following errors from the server
i) 400 error, when i set my variable set_resource = "(whatever)"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 400 Unable to identify the Xtext language.</title>
</head>
<body><h2>HTTP ERROR 400</h2>
<p>Problem accessing /xtext-service/generate. Reason:
<pre> Unable to identify the Xtext language.</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>
</body>
</html>
ii) 500 error, when i set my variable set_resource = "(the resource_id)"
By the way the resource_id is been used from the xtext during update and validation, and changes after the web page is been "refreshed" (F5). The resource id consist of 8 hexadecimals numbers and the edl extension. For example one resource_id should look like this one --> 9a8d7e12.edl
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 500 Server Error</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /xtext-service/generate. Reason:
<pre> Server Error</pre></p><h3>Caused by:</h3><pre>java.lang.NullPointerException
at eu.rawfie.edlWeb.generator.EdlGenerator.doGenerate(EdlGenerator.java:63)
at org.eclipse.xtext.generator.GeneratorDelegate.doGenerate(GeneratorDelegate.java:43)
at org.eclipse.xtext.generator.GeneratorDelegate.generate(GeneratorDelegate.java:34)
at org.eclipse.xtext.web.server.generator.GeneratorService.compute(GeneratorService.java:125)
at org.eclipse.xtext.web.server.generator.GeneratorService.compute(GeneratorService.java:47)
at org.eclipse.xtext.web.server.model.XtextWebDocumentAccess$5.exec(XtextWebDocumentAccess.java:342)
at org.eclipse.xtext.web.server.model.XtextWebDocumentAccess$5.exec(XtextWebDocumentAccess.java:334)
at org.eclipse.xtext.util.concurrent.CancelableUnitOfWork.exec(CancelableUnitOfWork.java:26)
at org.eclipse.xtext.web.server.model.XtextWebDocumentAccess.doAccess(XtextWebDocumentAccess.java:213)
at org.eclipse.xtext.web.server.model.XtextWebDocumentAccess.readOnly(XtextWebDocumentAccess.java:163)
at org.eclipse.xtext.web.server.model.XtextWebDocumentAccess.getCachedServiceResult(XtextWebDocumentAccess.java:346)
at org.eclipse.xtext.web.server.model.AbstractCachedService.getResult(AbstractCachedService.java:27)
at org.eclipse.xtext.web.server.generator.GeneratorService.getArtifact(GeneratorService.java:150)
at org.eclipse.xtext.web.server.XtextServiceDispatcher$16$1.apply(XtextServiceDispatcher.java:885)
at org.eclipse.xtext.web.server.XtextServiceDispatcher$16$1.apply(XtextServiceDispatcher.java:880)
at org.eclipse.xtext.web.servlet.XtextServlet.doService(XtextServlet.java:231)
at org.eclipse.xtext.web.servlet.XtextServlet.doPost(XtextServlet.java:188)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.eclipse.xtext.web.servlet.XtextServlet.service(XtextServlet.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Unknown Source)
</pre>
<hr><i><small>Powered by Jetty://</small></i><hr/>
</body>
</html>
Best Regards
[Updated on: Thu, 20 May 2021 15:04] Report message to a moderator
|
|
|
|
|
Re: Providing text through JavaScript [message #1730124 is a reply to message #1730123] |
Thu, 21 April 2016 14:22 |
|
Hi,
there are still terms used multiple whise
i use
- xtext server for the xtext backend rest api
- load for loading file content from the persistence of the xtext server to the editor in the browser
- save for storing content from the editor in the browser through the persistence of the xtext server.
i do not get what you mean by "send" from the server
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Providing text through JavaScript [message #1730217 is a reply to message #1730124] |
Fri, 22 April 2016 11:59 |
z232 I Messages: 48 Registered: February 2016 |
Member |
|
|
Hi Christian,
i mean that after posting a fullText message (using Httprequest), i am expecting that the Server is responsible to send the fulltext back to the editor. Thought that the server is responsible also for full-filling my edl editor automatically after receiveing the response "200 OK" from the server.
Untill now .
The way that i put text inside the xtext-area has been made with 2 diffrent ways:
i) by typing characters using my keyboard
ii) by inserting programmatically (using jQuery and the clipboard) a code template in the x-text area of my web edl editor.
The second way is made for user convenience, instead of typing a banch off code,
The problem is that i can't paste my code template programmatically inside my editor area, but only by using the key combination cntrl+V.
Any ideas on how to do the "paste" part by using jQuery ?
I am uploading a screenshot, for having a better view of my problem.
Best Regards
[Updated on: Thu, 20 May 2021 15:04] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06206 seconds