Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Providing text through JavaScript
Providing text through JavaScript [message #1729594] Fri, 15 April 2016 18:04 Go to next message
z232 I is currently offline z232 IFriend
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 #1729595 is a reply to message #1729594] Fri, 15 April 2016 18:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
hi i am not sure if i get you but you can send a post request with parameter fullText

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Providing text through JavaScript [message #1729597 is a reply to message #1729595] Fri, 15 April 2016 18:40 Go to previous messageGo to next message
z232 I is currently offline z232 IFriend
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 #1729598 is a reply to message #1729597] Fri, 15 April 2016 18:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
I did this some Time ago and it Worked Fine.

https://www.eclipse.org/forums/index.php?t=msg&th=781817&goto=1722463&#msg_1722463

I Renommend you to debug the Server side.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Providing text through JavaScript [message #1729826 is a reply to message #1729598] Tue, 19 April 2016 11:53 Go to previous messageGo to next message
z232 I is currently offline z232 IFriend
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 #1729830 is a reply to message #1729826] Tue, 19 April 2016 12:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
set_resource is the "name" of your virtual dsl file e.g "demo.mydsl".

the npe i the generator i cannot comment from the trace i see


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Providing text through JavaScript [message #1730123 is a reply to message #1729830] Thu, 21 April 2016 14:17 Go to previous messageGo to next message
z232 I is currently offline z232 IFriend
Messages: 48
Registered: February 2016
Member
Through this communication, the goal is to add some text in the editor. I should note that the editor already has some input and I try to add more through javascript. The first thought was to post the text back to the server that's why I was asking for this. Right now i can take 200 from the server, however, the text I send is not appeared inside the editor.
Is there any other way to do this?

Re: Providing text through JavaScript [message #1730124 is a reply to message #1730123] Thu, 21 April 2016 14:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
z232 I is currently offline z232 IFriend
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

Re: Providing text through JavaScript [message #1730218 is a reply to message #1730217] Fri, 22 April 2016 12:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Editor.setValue does not work?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Providing text through JavaScript [message #1730234 is a reply to message #1730218] Fri, 22 April 2016 13:19 Go to previous message
z232 I is currently offline z232 IFriend
Messages: 48
Registered: February 2016
Member
Christian,

you are amazing
Thank you for your time and your continuous support.

Best Regards

[Updated on: Thu, 20 May 2021 15:04]

Report message to a moderator

Previous Topic:Qualified Name Provider
Next Topic:Index of element in the whole tree
Goto Forum:
  


Current Time: Thu Mar 28 18:31:24 GMT 2024

Powered by FUDForum. Page generated in 0.02643 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top