module jsp fails to point to an external javascript file

am trying to point to an external javascript file like

in my module but it sims the module doesnt recognise file wen it runs

It helps to show both the code and exact error

1 Like

this is the code am using.

  <openmrs:htmlInclude file="/moduleResources/facelist/js/jquery.js"/>
   
	<openmrs:htmlInclude file="/moduleResources/facelist/js/bootstrap.min.js"/>
	
	
	<openmrs:htmlInclude file="/moduleResources/facelist/js/jquery.dataTables.js"/>
	
	<openmrs:htmlInclude file="/moduleResources/facelist/js/dataTables.bootstrap.js"/>
	
	<openmrs:htmlInclude file="/moduleResources/facelist/js/bootbox.min.js"/>

and those files are inthe directory src/main/webapp/js

but they are not recognised

ive soled it. thx sir

Hi @mozzy !
It looks like your depending on the Legacy UI. Its always recommended to use OWA or at worst the UI Framework for new UI developments(Modules).

2 Likes

thx @samuel34. your Right. but u know since am new to openmrs , am first studying and learning the sysytem archtecture. so am first undesrtanding the old concepts them i move to the new concepts.

the small challenge istil have is …

it can now read the external pre-coded javascript-frameworks files…

<openmrs:htmlInclude file="/moduleResources/facelist/js/bootstrap.min.js"/>
	
	
	<openmrs:htmlInclude file="/moduleResources/facelist/js/jquery.dataTables.js"/>
	
	<openmrs:htmlInclude file="/moduleResources/facelist/js/dataTables.bootstrap.js"/>
	
	<openmrs:htmlInclude file="/moduleResources/facelist/js/bootbox.min.js"/>

but it cant read my own writen javascript wen i place it in an external file

<openmrs:htmlInclude file="/moduleResources/facelist/resources/js/myapp.js"/>

here is my jquery code

$(document).ready(function() {
	
	var patients = [
		
		           [ '1' , '2'],
		           [ '1' , '2'],
		           [ '1' , '2']
		        
	               ];
	
	   var $table= $('#pats');
	   
	   // EXECUTE THAT COE ONLY WHERE WE HAVE THE TABLE
	   if ( $table.length) {
		   
		   $table.DataTable ( {
			
				
				data:patients
				   
			});
		   
		   
	   }
	   
	   
	  
	
	
	
});

yet wen i just place that code inside my jsp, it works pretty fine

@samuel34 @dkayiwa @tendomart

Are you sure your “myapp.js” compiles fine?

yes wen i place the code inside the jsp, it works very well,

For some reason, I also am experiencing the very same problem, using openmrs in another project(Librehealth). Any assistance on how to fix this would be greatly appreciated.

ok , can u try to detail your problem , coz there are many issues in the talk

I can’t seem to access my na classes in in their intended jsp pages. I am attaching a screenshot of the code I am using. Before this, i tried including it normally as a javascript file using the src attribute inside the tag, I also tried using page context, yet, nothing seemed to work.

This is the error log

now wen u map to your static resources as

<openmrs:htmlInclude file="/moduleResources/facelist/js/dataTables.bootstrap.js"/>

this path " moduleResources/moduleid" implies or points to the src/webbapp/resources folder. hence if u have any other subfolder under src/webbapp/resources , then u add it in the URL but the base folder wea openmrs can locate your static Resources is src/webapp/resources. if u dont have it, create it and place all your resources in their

Hey @mozzy Thanks for your help, I was able to include the external js files into the jsp page. But now I can’t access other js classes from anither js class. For example, take the case below

  recognizer = new Worker('/moduleResources/radiology/recognizer.js');

That line of code throws a 404 resource not found error in my browser console, meaning the recognizer.js class has not been found, mean while it is in the src/webbapp/resources folder. Same as the other js files. I even tried referencing it as

  recognizer = new Worker('recognizer.js');

since the recognizer.js class is in the same folder as the class I want to reference it from, but I still get the same error in my browser console. I’d really appreciate help on this

when u just write a url like “/moduleResources/…etc” , openmrs can see that file coz it can figure out the Base Url , thats y u either start with “openmrsinclude…”

or now like in that case try something like “${pageContext.request.contextPath}/moduleResources/facelist/........

@mozzy Still no success, even while using ${pageContext.request.contextPath}

can u take a pic of your file structure?

and i dont understand y u have to acces external files this way

recognizer = new Worker('/moduleResources/radiology/recognizer.js');

Hey @mozzy thanks alot for your help so far. Here is a picture of my file structure taken from intellij Idea 21

And the reason why I access the external files that way is because I was following the instructions in the ReadMe file of the project I am trying to integrate into openmrs or in this case, librehealth radiology. Here’s the link to the ReadMe GitHub - syl22-00/pocketsphinx.js: Speech recognition in JavaScript and WebAssembly