# JavaBeans and Js command

**URL:** <https://discourse.dojo.io/t/javabeans-and-js-command/328>\
**Category:** DWR users\
**Created:** [November 20, 2018, 8:19am UTC](https://discourse.dojo.io/t/javabeans-and-js-command/328 "2018-11-20T08:19:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wilnzi](https://avatars.discourse-cdn.com/v4/letter/w/41988e/32.png) [@wilnzi](https://discourse.dojo.io/u/wilnzi)\
**Post date:** [November 20, 2018, 8:19am UTC](https://discourse.dojo.io/t/javabeans-and-js-command/328/1 "2018-11-20T08:19:14Z")

</div>

hello,  
I’m new on dwr and i want to know if it is possible to add the js commands from the Java Code ?

I want to use dwr like xajax on PHP.  
Please help me.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [November 20, 2018, 10:50am UTC](https://discourse.dojo.io/t/javabeans-and-js-command/328/2 "2018-11-20T10:50:37Z")

</div>

I’m not at all familiar with Xajax but if you describe the way you want to do things then I can hopefully tell you if you can use DWR in a similar way.

In the docs you can see how you invoke your Java code from Javascript:  
[http://directwebremoting.org/dwr/introduction/scripting-dwr.html](http://directwebremoting.org/dwr/introduction/scripting-dwr.html)

---

<div class="post-metadata">

**Author:** ![wilnzi](https://avatars.discourse-cdn.com/v4/letter/w/41988e/32.png) [@wilnzi](https://discourse.dojo.io/u/wilnzi)\
**Post date:** [November 21, 2018, 9:08pm UTC](https://discourse.dojo.io/t/javabeans-and-js-command/328/3 "2018-11-21T21:08:39Z")

</div>

Hello,  
Thanks.

I want to make the treatment in java and add js command directly in java code.

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [November 22, 2018, 1:05pm UTC](https://discourse.dojo.io/t/javabeans-and-js-command/328/4 "2018-11-22T13:05:53Z")

</div>

I took a quick look at an `Xajax` example at [https://github.com/Xajax/Xajax/blob/master/examples/multiply/multiply.php](https://github.com/Xajax/Xajax/blob/master/examples/multiply/multiply.php)  
and it shows that Xajax does _not_ offer you to write your Javascript code as PHP code. Rather, it shows that the Xajax solution requires you to write your code as a mix of HTML, Javascript and PHP but allows you to mix all these in the same file (as is common for PHP).  
So, make a distinction whether you are talking about a _file_ or _actual code_ in a certain language.

In DWR the normal usage is to separate the HTML and JS code from the Java code and keep these in separate files. I would estimate that the amount of HTML and Javascript _code_ you need to write is about the same as for Xajax as you delegate much of the work to the Java code.

Before asking any more questions you should run through DWR’s demo examples by installing:  
`dwrdemo.war` from [http://directwebremoting.org/dwr/downloads/index.html](http://directwebremoting.org/dwr/downloads/index.html)  
in a Java application server of your choice. The examples have documentation you can read as well and you will learn how DWR performs its functions.

If you actually want to mix all languages in the same file (which I do not recommend) then you should look at one of the Java templating languages, where JSP is the official one, but you can find a lot of other ones here:

> **[Comparison of web template engines](https://en.wikipedia.org/wiki/Comparison_of_web_template_engines)**
>
> The following table lists the various Web Template Engines used in Web template systems and a brief rundown of their features.
