raks | 22 May 18:46
Picon

[dwr-users] Getting "Object Expected" Javascript error

Hi,

I am creating a simple DWR application for learning.

I am using DWR jar with version 2.0.10.

Below is the JSP which I have created:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
&quot;http://www.w3.org/TR/html4/loose.dtd&quot;>
<html>

	<head>
		
	
		<meta http-equiv="Content-Type"	content="text/html; charset=ISO-8859-1">
		<title>Insert title here</title>
	</head>
	
	<body>
	
	<form id="form1">

		<input type="button" value="click" onclick="add();"><br><br>
		<br>
		<br>
		<div id="test">
		</div>
(Continue reading)

kikivg | 21 May 15:15
Picon

[dwr-users] ScriptSession in non-dwr thread

Hi all,

I use Reverse Ajax for calling some Javascript function which changes html
page. When user clicks on a button in a browser, dwr calls Java method that
creates a new thread. This metod looks like this:

      public void init(String ipAddress) {
	             ScriptSession scriptSession =
WebContextFactory.get().getScriptSession();		             new Thread(new
Telnet(ipAddress, scriptSession)).start();
	}

In Telnet thread I need to call function from Javascript, so I tried this:
                           // example for calling js function
                           ScriptBuffer script = new ScriptBuffer();
                           // printOutput is javascript function
		script.appendCall("printOutput", "test1");
		scriptSession.addScript(script);

ScriptSession object is passed to Telnet thread in constructor. The code
above is not working, html page is not changed. But when I add this test
code in init() method, it works. I tried with ScriptSessions.addFunctionCall
but it's not working because Telnet is non-dwr thread.

Can you help me?

--
View this message in context: http://dwr.2114559.n2.nabble.com/ScriptSession-in-non-dwr-thread-tp7569207.html
Sent from the DWR - Users mailing list archive at Nabble.com.

(Continue reading)

Lance Java | 17 May 12:43
Gravatar

[dwr-users] Can I populate ScriptSession attributes before including engine.js?

As far as I know, if I want to populate script session attributes, I need to
do the following:
1. MVC controller does some processing
2. MVC controller generates HTML which includes script session values
3. Client includes engine.js
4. Client calls engine.setActiveReverseAjax(true);
5. ScriptSession is created on the server
6. scriptSessionId is populated on the client
7. Client calls a remote DWR method passing script session values
8. Server stores script session values in ScriptSession attributes
9. Step 7 and 8 are insecure and can be spoofed by a hacker

I would like to do the following instead:
1. MVC controller does some processing
2. MVC controller creates a ScriptSession
3. MVC controller adds attributes to ScriptSession
4. MVC controller generates HTML which includes scriptSessionId
5. Client includes engine.js
6. Client calls dwr.engine.setScriptSessionId(scriptSessionId);
7. Client calls engine.setActiveReverseAjax(true);
8. Server does not create script session (it already exists)
9. Client does not need a remote DWR call.
10. No opportunity for a hacker to spoof the values

Are steps 2 and 6 possible? Can I tell DWR to use an existing session
instead of creating one?

--
View this message in context: http://dwr.2114559.n2.nabble.com/Can-I-populate-ScriptSession-attributes-before-including-engine-js-tp7563566.html
Sent from the DWR - Users mailing list archive at Nabble.com.
(Continue reading)

Lance Java | 17 May 11:03
Gravatar

[dwr-users] Map ScriptSessions by "topic" attribute

Hi, I'm currently integrating  http://tapestry.apache.org/ Tapestry  and DWR
in the hope that developers can write push components with zero javascript.

I'm writing a PubSubManager abstraction on top of DWR's reverse ajax and it
makes sense for subscribers to subscribe to a topic and for publishers to
publish to topic.

I see that the DefaultScriptSessionManager implementation maintains a couple
of maps:
ConcurrentMap<String, DefaultScriptSession> sessionMap; // mapped by
scriptSessionId
ConcurrentMap<String, Set&lt;DefaultScriptSession>> pageSessionMap; //
mapped by pageName

I'm not interested in looking up script sessions by scriptSessionId or by
pageName but I would like to do a hash lookup of script sessions by topic
[O(1)] instead of iterating all script sessions [O(N)].

I will be storing the topic as a scriptSession attribute and I'm guessing
that I will need to implement my own ScriptSessionManager to maintain a map
of Set<ScriptSession> by topic.

Can someone please give me some guidance on the ScriptSession lifecycle? I
get the feeling that the ScriptSession will be constructed by DWR and at
some later stage I will set a topic in the attributes. Is there a hook I can
use to fire an event when the "topic" is set?. Any advice on how to handle
this would be appreciated.

Thanks,
Lance.
(Continue reading)

Dhaval Patel | 8 May 16:43
Picon

[dwr-users] Web application architecture using DWR

Hello all,


I just wanted to ask users of DWR about their application architecture. I mean if you have to make a new web application using DWR, how would you architect it? Which MVC do you use if you are planning to use one? What would makes a good sense from growth and expansion point of view?

I have used DWR but on very small scale application like 5-6 page. I am thinking about writing a small web application. It may grow bigger but my main concern is about technology I used. I want to make it as light weight as possible. So far this is what I have in my mind:
- Front end: HTML, CSS, JQuery, DWR
- Back end: Spring MVC, DWR

Front end will be as much decoupled as possible so that I can replace backend if I needed to.

Lot of things are missing from this picture like authentication, authorization etc. But I just wanted to reach out to DWR users about their experience in their work and if they have to change something, what would they change to make the application better?

Also I want to ask authors of DWR about their ideal application stack setup. I know that DWR is very flexible but if you have to choose one, what would you choose?

Thank you.

--
Regards,
Dhaval
Garfi61416 | 4 May 01:48
Picon
Favicon

[dwr-users] ScheduledThreadPoolExecutor won't run after intialized

I took the PeopleTable method and built my own runner method.  It works
perfectly fine with a direct call.  However, after seeing that
ScheduledThreadPoolExecutor gets initialized, the
ScheduledThreadPoolExecutor run method is never called.  Can anyone tell me
what I'm doing wrong?

Here is my runnable class:

public class AlertRunner implements Runnable
{
	
	// Create default logging
	static Logger log = Logger.getLogger(AlertRunner.class);
	
	ScheduledThreadPoolExecutor executor = null;
	
	/**
	 * Constructor - Creates a thread pool that runs every minute.
	 */
	public AlertRunner()
	{
		System.out.println("Initialize ScheduledThreadPoolExecutor");
		executor = new
		ScheduledThreadPoolExecutor(1, new DaemonThreadFactory());
		executor.scheduleAtFixedRate(this, 1, 10, TimeUnit.SECONDS);
		
		int queued = executor.getQueue().size(); 
		int active = executor.getActiveCount(); 
		int notCompleted = queued + active; // approximate
		System.out.println(String.format("\nBeginning Executor Statistics:\nqueued
%1$d\nactive %2$d\nnotCompleted %3$d", queued, active, notCompleted));

	}

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run()
	{
		updateTableDisplay();
	}
	
	public void stop() 
	{
		log.info("stopping executor...");
		executor.shutdownNow();
	}

	public void updateTableDisplay()
	{
		int queued = executor.getQueue().size(); 
		int active = executor.getActiveCount(); 
		int notCompleted = queued + active; // approximate
		System.out.println(String.format("\nBeginning Executor Statistics:\nqueued
%1$d\nactive %2$d\nnotCompleted %3$d", queued, active, notCompleted));
		
		// Get the current page.
		String page = ServerContextFactory.get().getContextPath() +
"/html/LandingPage.jsp";
		ScriptSessionFilter attributeFilter = new
		AttributeScriptSessionFilter(SCRIPT_SESSION_ATTR);
		log.info("Check for page filter...");
		ScriptSession session = WebContextFactory.get().getScriptSession();
		String customSessionAttr =
(String)session.getAttribute(SCRIPT_SESSION_ATTR);
		log.info("<Before Page> SCRIPT_SESSION_ATTR: " + customSessionAttr);
		
		Browser.withPageFiltered(page, attributeFilter, new Runnable(){
			@Override
			public void run() {

				try {
					Util.setValue("errorDiv1", "");
					log.info("updating table....");
					ScriptSession session = WebContextFactory.get().getScriptSession();
					if (session.isInvalidated()) {
						return;
					}
					
					String jfsEndpoint = (String) session.getAttribute("jfsEndpoint");
					Object jfsinfoObj = session.getAttribute("jfsinfo");
					JFSInfo jfsinfo = (JFSInfo)jfsinfoObj;
					if (jfsEndpoint == null || jfsinfo == null) {
						Util.setValue("errorDiv1", "Error: missing session information");
						return;
					}
					
					String alertXML = JFSWSClient.getAlertHistory(jfsEndpoint, jfsinfo);
					Util.setValue("alertXML", alertXML);
					ScriptSessions.addFunctionCall("eg.ahpkg.loadForm");
					log.info("table updated.");

				} catch (AxisFault e) {
					Util.setValue("errorDiv1", "Error: " + e.getMessage());
				}

			}
		});
		
	}

	/**
	 * Called from the client to add an attribute on the ScriptSession.  This
	 * attribute will be used so that only pages (ScriptSessions) that have 
	 * set this attribute will be updated.
	 */
	public void addAttributeToScriptSession(String val) {
		log.info("Setting filter of " + val + " to " + SCRIPT_SESSION_ATTR);
		ScriptSession scriptSession =
			WebContextFactory.get().getScriptSession();
		scriptSession.setAttribute(SCRIPT_SESSION_ATTR, val);
	}

	/**
	 * Called from the client to remove an attribute from the ScriptSession.  
	 * When called from a client that client will no longer receive updates
(unless addAttributeToScriptSession)
	 * is called again.
	 */
	public void removeAttributeToScriptSession(String val) {
		ScriptSession scriptSession =
			WebContextFactory.get().getScriptSession();
		scriptSession.removeAttribute(SCRIPT_SESSION_ATTR);

	}

	/**
	 * This is the ScriptSessionFilter that will be used to filter out
allScriptSessions
	 * unless the SCRIPT_SESSION_ATTR attribute exists and is the same as the
user's username. 
	 */
	protected class AttributeScriptSessionFilter implements
	ScriptSessionFilter
	{
		
		public AttributeScriptSessionFilter(String attributeName)
		{
			this.attributeName = attributeName;
		}

		/* (non-Javadoc)
		 * @see
org.directwebremoting.ScriptSessionFilter#match(org.directwebremoting.ScriptSession)
		 */
		@Override
		public boolean match(ScriptSession session)
		{
			Object jfsinfoObj = session.getAttribute("jfsinfo");
			if (jfsinfoObj == null)
				return false;
			JFSInfo jfsinfo = (JFSInfo)jfsinfoObj;
			
			String userName = (String)session.getAttribute(attributeName);
			if (userName == null || "".equals(userName))
				return false;

			return (userName.equals(jfsinfo.getUserName()));
		}

		private final String attributeName;
	}

	private final static String SCRIPT_SESSION_ATTR = "SCRIPT_SESSION_ATTR";
}

And just in case you need it, 

my dwr.xml:

<!DOCTYPE dwr PUBLIC 
	&quot;-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN&quot; 
	&quot;http://getahead.org/dwr//dwr30.dtd&quot;>

<dwr>
  <allow>
    <create creator="new" scope="application">

    </create>

    <create creator="new" scope="application">

    </create>
    <convert converter="bean" match="com.jfs.util.JFSInfo" />

    <create creator="new" scope="application">

    </create>

    <convert match="java.lang.Exception" converter="exception">
  		
    </convert>      
  </allow>
</dwr>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID">
 <display-name>JFSSETSInteractive</display-name>

    <servlet>
	  <servlet-name>dwr-invoker</servlet-name>
	  <display-name>DWR Servlet</display-name>
	  <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
	  <load-on-startup>1</load-on-startup>
	  <init-param>
	     <param-name>debug</param-name>
	     <param-value>false</param-value>
	  </init-param>
      <init-param>
	      <param-name>activeReverseAjaxEnabled</param-name>
	      <param-value>true</param-value>
	  </init-param>
	</servlet>
	 <servlet>
	  <servlet-name>LoginHelper</servlet-name>
	  <servlet-class>com.jfs.servlets.LoginHelper</servlet-class>
	  <load-on-startup>2</load-on-startup>
	</servlet>
	<servlet>
	  <servlet-name>DataEntryHelper</servlet-name>
	  <servlet-class>com.jfs.servlets.DataEntryHelper</servlet-class>
	  <load-on-startup>2</load-on-startup>
	</servlet>
	<servlet>
	  <servlet-name>DataSubmitter</servlet-name>
	  <servlet-class>com.jfs.servlets.DataSubmitter</servlet-class>
	  <load-on-startup>2</load-on-startup>
	</servlet>
	<servlet>
	  <servlet-name>DocumentHelper</servlet-name>
	  <servlet-class>com.jfs.servlets.DocumentHelper</servlet-class>
	  <load-on-startup>2</load-on-startup>
	</servlet>
	
	<servlet-mapping>
	  <servlet-name>dwr-invoker</servlet-name>
	  <url-pattern>/dwr/*</url-pattern>
	</servlet-mapping>
     <servlet-mapping>
          <servlet-name>LoginHelper</servlet-name>
          <url-pattern>/html/LoginHelper</url-pattern>
     </servlet-mapping>
	 <servlet-mapping>
          <servlet-name>DataEntryHelper</servlet-name>
          <url-pattern>/html/DataEntryHelper</url-pattern>
     </servlet-mapping>
	 <servlet-mapping>
          <servlet-name>DataSubmitter</servlet-name>
          <url-pattern>/html/DataSubmitter</url-pattern>
     </servlet-mapping>
	 <servlet-mapping>
          <servlet-name>DocumentHelper</servlet-name>
          <url-pattern>/html/DocumentHelper</url-pattern>
     </servlet-mapping>

     <welcome-file-list id="WelcomeFileList_1">
          <welcome-file>index.html</welcome-file>
     </welcome-file-list>
</web-app>

The relevent javascript code:

this is the load function:

    ahpkg.tableLoaded = function() {
    	AlertRunner.addAttributeToScriptSession(dwr.util.getValue("userName"),
function() {dwr.engine.setActiveReverseAjax(true);});
	AlertRunner.updateTableDisplay();
    }

And some global javascript:

dwr.engine.setErrorHandler(errh);
dwr.engine.setNotifyServerOnPageUnload(true);

Thanks.

--
View this message in context: http://dwr.2114559.n2.nabble.com/ScheduledThreadPoolExecutor-won-t-run-after-intialized-tp7525522.html
Sent from the DWR - Users mailing list archive at Nabble.com.

stigmund | 27 Apr 17:37

[dwr-users] dwr creator, non static and non new?

Hi, 

just kind of testing out the features of DWR and something i seem to be
stuck at is trying to call a function on my server from a class that has
already been instanciated (not new).

The idea is that this function updates the browser of its own accord (but as
far as i can tell you need an inicial "send" from the browser (hence the
DWR.xml ?))

If its created new, it just does nothing (the class' constructor is set to
recive parameters for connections etc... so if its created new for DRW then
nothing will happen.

i can set it to "static" and call a static function, or set to new and call
a class specificly created to send a simple line of text.

its use is to update the browsers progress bar based on the servers
computing progress (e.g. deleting database records etc...).

P.s. i did read the docs, and have searched for this (very non helpful reply
from some guy relating to this exact situation, basicly telling the OP to
read the docs -.-).

So is it possible or have i totaly miss-intermprated the docs?

Thanks.
Stig.

--
View this message in context: http://dwr.2114559.n2.nabble.com/dwr-creator-non-static-and-non-new-tp7506547.html
Sent from the DWR - Users mailing list archive at Nabble.com.

Mike Wilson | 16 Apr 10:59
Picon
Favicon

[dwr-users] Re: how to detect that Reverse Ajax is broken

Are you using the breakpoint to simulate a communication error? Normally DWR should retry and resume automatically. Could you try to pull the network cable instead as maybe the breakpoint is interfering with the retry mechanism?
 
If you are on DWR 3, then you can use
    dwr.engine.setPollStatusHandler(function() {...});
to be informed about your connection status. If you look at
you can see that it is used to update the Server Status.
 
You should not have to call setActiveReverseAjax() again.
 
Best regards
Mike
 
Jeff Ma wrote:

Take chat for example, in JS, call dwr.engine.setActiveReverseAjax(true). Both parties (A and B) can receive messages from each other. Now put a break point in forward-ajax handling function in server code , and resume after 1 minute. Now when A sends messages, B won’t receive until B types. So ’server-push’ is not working. Now if in B’s browser, call dwr.engine.setActiveReverseAjax(true) again, it works again (B can receive A’s message right after A sends).

 

The question is what’s the best way for B to check if ReverseAjax (‘server-push’) is not working? Will calling dwr.engine.setActiveReverseAjax(true) unnecessarily create any problems?

 

Thanks.

- Jeff

 

From: Mike Wilson [mailto:mikewse-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org]
Sent: Thursday, April 12, 2012 7:18 PM
To: users-QN3ROSRnxATk1uMJSBkQmQ@public.gmane.org
Subject: [dwr-users] Re: how to detect that Reverse Ajax is broken

 

Ji Jeff,

 

Can you please define what you mean with "broken" and "side-effects"? :-)

 

Best regards

Mike Wilson

 

Jeff Ma wrote:

Hi all,

 

What’s the best way (using JS) to detect that reverse ajax is broken so that we can call dwr.engine.setActiveReverseAjax(true) without any side effects?

 

Thanks.

- Jeff

 

 

Mike Wilson | 12 Apr 13:18
Picon
Favicon

[dwr-users] Re: how to detect that Reverse Ajax is broken

Ji Jeff,
 
Can you please define what you mean with "broken" and "side-effects"? :-)
 
Best regards
Mike Wilson
 
Jeff Ma wrote:

Hi all,

 

What’s the best way (using JS) to detect that reverse ajax is broken so that we can call dwr.engine.setActiveReverseAjax(true) without any side effects?

 

Thanks.

- Jeff

 

 

Jeff Ma | 12 Apr 10:10

[dwr-users] how to detect that Reverse Ajax is broken

Hi all,

 

What’s the best way (using JS) to detect that reverse ajax is broken so that we can call dwr.engine.setActiveReverseAjax(true) without any side effects?

 

Thanks.

- Jeff

 

 

LeoKringer | 11 Apr 01:19
Picon
Favicon

[dwr-users] Invoking method not working...

Good night,

I'm working in a application using DWR to invoke java servlets but it's not
working! When I call the method, the java servlet simply isn't called! There
are *2* javascript calls that isn't working... Follow below my code...

HEAD
<code>

</code>

dwr.xml
<code>
<dwr>
    <allow>
        <create creator="new" javascript="CarregaEstados">

        </create>
    </allow>

    <allow>
        <create creator="new" javascript="VerificaNick">

        </create>
    </allow>

</dwr>
</code>

web.xml
<code>
<servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>true</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>
</code>

cadastro.jsp
<code>
<p class="cadastroPa">:: Pa&iacute;s
      <select name="pais" id="paises" onchange="carregaEstado(this.value,
estados);">
        	<option value="0">Selecione...</option>
	<c:forEach var="pais" items="${listaPais}">
		<option value=&quot;&lt;c:out value='${pais.id}'/>"><c:out
value="${pais.nome}" /></option>
	</c:forEach>
      </select>
</p>

<p class="cadastroEs">:: Estado
      <select name="estados" id="estados">
	<option value="0">Selecione...</option>
	<c:forEach var="estado" items="${listaEstados}">
		<option value=&quot;&lt;c:out value='${estado.id}'/>"><c:out
value="${estado.nome}" /></option>
	</c:forEach>
       </select>
</p>

<p class="cadastroNi">:: Nick <input name="nick" type="text" id="nick"
class="ni" value="Nick maior que 2 letras" style="color: gray;" onfocus="if
(this.style.color === 'gray') {this.value = ''; this.style.color = 'gray';}"
onblur="if (this.value.length === 0) {this.value = 'Nick maior que 2
letras'; this.style.color = 'gray';}"/>

<input name="botaoNick" type="button" value="verificar..."
onclick="verificaNick(res);"/><label class="res"></label>

</code>

ajax.js
<code>
function carregaEstado(id, combo){
    DWRUtil.removeAllOptions(combo);
    CarregaEstados.listarEstados(id, function(mapa)
    {
        DWRUtil.addOptions(combo, mapa);
     });
}

function verificaNick(lab){
    var valorNick = document.getElementByID("nick").value;
    VerificaNick.verificar(valorNick, function(bol){
    	if (bol == "Indisponivel")
    	{
    		dwr.util.setValue(id,"");
    	}
    	dwr.util.setValue(lab, bol);
    });
}
</code>

CarregaEstados.java
<code>
public class CarregaEstados
{
	
	public List<Estado> listarEstados(int id)
	{
		System.out.println("ENTROU EM CARREGAR ESTADOS.JAVA!!!");
		BancoDados db = new BancoDados();
		List<Estado> listaEstados = db.getEstados(id);
		return listaEstados;
	}
}

</code>

VerificaNick.java
<code>
public class VerificaNick
{
	public String verificar(String nick)
	{
		System.out.println("ENTROU EM CARREGAR CHECAR NICK.JAVA!!!");
		BancoDados db = new BancoDados();
		Manager manager = db.verificaNick(nick);
		
		if (manager == null)
		{
			return "Disponivel";
		}
		else
		{
			return "Indisponivel";
		}
		
	}
}
</code>

PLEASE, help me.. I don't have any idea where is the mistake!!

Regards,
Leo

--
View this message in context: http://dwr.2114559.n2.nabble.com/Invoking-method-not-working-tp7454655p7454655.html
Sent from the DWR - Users mailing list archive at Nabble.com.


Gmane