Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Firing Client-Side events in JavaApplet / Losing shape positions on postback (Read 7027 times)
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Firing Client-Side events in JavaApplet / Losing shape positions on postback
Oct 8th, 2012 at 12:55pm
Print Post  
So far I understand that to use client-side events in JavaApplet mode can be done through using Javascript as shown here.

However can this be done normally through C# server-side code?

I have devised a way to do it but it causes a postback, and upon postback the diagramView loses all the positions of the shapes.

Is there a solution to this?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Firing Client-Side events in JavaApplet / Losing shape positions on postback
Reply #1 - Oct 8th, 2012 at 1:10pm
Print Post  
You could create a web service that implements the required update logic in C# and call it in response to client-side events. This is shown in the OrgBrowser sample project.

How exactly are you posting back the page? The applet and the server control transfer data via a hidden field, whose value is set from an on_submit script registered by the server control. If that on-submit script is not executed, you will get the original positions as they were first saved in the hidden field on the server side instead of the updated positions in the applet. Also check if you are not resetting the node's positions yourself from the page_load handler.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Firing Client-Side events in JavaApplet / Losing shape positions on postback
Reply #2 - Oct 10th, 2012 at 9:44pm
Print Post  
Any idea on how to disable the on_submit script?
  
Back to top
 
IP Logged
 
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Firing Client-Side events in JavaApplet / Losing shape positions on postback
Reply #3 - Oct 11th, 2012 at 12:09am
Print Post  
What I'm trying to do here is very simple, I'll explain.

I want to trigger events, preferably server side (though I couldnt so I resorted to using client side), and then get the response without having the diagram refreshed. BTW I'm using javaApplet mode.

Is there a simple example that does this?
  
Back to top
 
IP Logged
 
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Firing Client-Side events in JavaApplet / Losing shape positions on postback
Reply #4 - Oct 11th, 2012 at 4:30am
Print Post  
Here is what I did to temporarily solve this, but I would appreciate if someone could tell me the proper way to do this:
Code (Javascript)
Select All
<script language="javascript" type="text/javascript">
 function NodeDoubleClicked(diagram, args) {
         __doPostBack('<%= Btn_DoubleClick.UniqueID %>', 'OnClick');
     }

</script>
 



Code
Select All
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
        <ndiag:DiagramView ID="diagramView" runat="server" Style="left: 0px; width: 480px;
            position: absolute; top: 0px; height: 480px"
            ClientSideMode="JavaApplet"
            LinkCreating="onLinkCreating"
            LinkCreatedScript="onLinkCreated"
            NodeCreatingScript="onNodeCreating"
            NodeCreatedScript="onNodeCreated"
            NodeModifyingScript="onNodeModifing"
            NodeModifiedScript="onNodeModified"
            NodeDoubleClickedScript="NodeDoubleClicked" /> 



Code
Select All
 <asp:Button ID="Btn_DoubleClick" runat="server" Style="left: 654px; position: absolute; top: 490px"
            Text="DoubleClick" Width="111px" OnClick="LocationDoubleClicked" /> 




In aspx:

Code
Select All
  protected override void Render(HtmlTextWriter writer)
    {
        ClientScript.RegisterForEventValidation(Btn_DoubleClick.UniqueID, "OnClick");
        base.Render(writer);
    }

    protected void LocationDoubleClicked(object sender, EventArgs e)
    {
        Show("Node Double clicked");
        Diagram diagram = diagramView.Diagram;
        //Show(diagram.FindNode("rectangleLane1").Id.ToString());
        //ShapeNode currShape = e.Node as ShapeNode;



    }
 



By the way for some reason my problem of diagram shapes being refreshed are solved too, for now.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Firing Client-Side events in JavaApplet / Losing shape positions on postback
Reply #5 - Oct 11th, 2012 at 9:49am
Print Post  
If you really want to post back after client events, better use the ClientScript.GetPostBackEventReference method. It returns a piece of JavaScript that posts the page back passing a string parameter, where you can encode the name of the event, the item's id or index, etc. Then implement the IPostBackEventHandler.RaisePostBackEvent method to process the event on the server:

Code
Select All
// on client side
function onNodeCreated(sender, args)
{
	<%= ClientScript.GetPostBackEventReference(this, "NodeCreated") %>;
}

// on server side
public void RaisePostBackEvent(string eventArgument)
{
	if (eventArgument == "NodeCreated")
	{
		// process new node (last element of diagram.Nodes)
	}
} 



Note that the diagam's applet file is 1 MB large and the Java plugin will need some time to reload and initialize it after a post-back (even though the jar file is cached by the browser), so it's really better to call a service from the client event rather than doing a full post-back.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Firing Client-Side events in JavaApplet / Losing shape positions on postback
Reply #6 - Oct 11th, 2012 at 10:05am
Print Post  
Right, so what I gather is, javaApplet by design is meant to be used alongwith client-side events? Correct?

In contrast, if one wants to use server-side events, s/he should use ImageMap mode. Correct?

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Firing Client-Side events in JavaApplet / Losing shape positions on postback
Reply #7 - Oct 11th, 2012 at 12:56pm
Print Post  
Correct. I think this started with validation events - Creating, Modifying, etc., which require some code to run at each mouse move and can't be implemented on the server - and our developers decided it's better to use the same model for all events. Anyway, we'll probably implement an AutoPostBack mode for the next major release to allow handling some events on the server too.
  
Back to top
 
IP Logged
 
saad
Full Member
***
Offline


I Love MindFusion!

Posts: 117
Joined: Oct 8th, 2012
Re: Firing Client-Side events in JavaApplet / Losing shape positions on postback
Reply #8 - Oct 11th, 2012 at 2:44pm
Print Post  
Thanks for the clarification.

By the way the client would run this over the local network. I reckon it shouldnt cause a problem regarding the 1MB applet you mentioned, should it?

Nor should it over the internet if s/he is connected via say VPN, would it?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Firing Client-Side events in JavaApplet / Losing shape positions on postback
Reply #9 - Oct 12th, 2012 at 6:51am
Print Post  
The applet is downloaded only once and stays in the browser cache, so the network does not matter that much. The problem is that after each postback you will have to wait for the Java plugin to load and initialize the applet again, which is not that fast even when the applet is read from the local cache. So showing the Java's coffee animation to the user (displayed while loading applets) each time when they draw or click a node won't be that great user experience. That's why it's better to call a service from the client events instead of posting the page back.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint