JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 26th, 2012, 09:28 PM
superprogrammer superprogrammer is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Posts: 850 superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 6 h 16 m 50 sec
Reputation Power: 10
Send a message via AIM to superprogrammer Send a message via MSN to superprogrammer Send a message via Yahoo to superprogrammer
Java Classes to Javascript Object

I have the following class hierarchy

Abstract class
Code:
public abstract class AbstractClass
{
	private long timestamp;
	private String candidateId;
	private String regId;

}

And I have multiple classes extending above abstract class as below in my java project
Code:
public class QuestionClass extends AbstractClass
{
    
    private boolean questionanswered;
   private boolean valid;

    public QuestionClass(boolean questionanswered)
    {
        this.questionanswered = questionanswered;
    }

    public boolean isQuestionanswered()
    {
        return questionanswered;
    }

}


Now, I need to send from the browser the similar javascript objects(as json) to server (and on server I convert json to java object)

For instance:

{"candidateid":"1243","regId":"78","valid":"true","timestamp":"0","questionanswered":"true"}

Is there anyway to dynamically create the javascript objects from java and get all the parent classes fields too
If I can get javascript object from server java, then I can directly convert it to JSON while sending it back to server
Right now, I have to manually code the similar javascript object

Thanks
__________________
Contact info:
Primary email: advanced.programmer@gmail.com
MSN/email: superprg@hotmail.com
AIM: superprg

Reply With Quote
  #2  
Old October 29th, 2012, 09:56 AM
superprogrammer superprogrammer is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Posts: 850 superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 6 h 16 m 50 sec
Reputation Power: 10
Send a message via AIM to superprogrammer Send a message via MSN to superprogrammer Send a message via Yahoo to superprogrammer
Anyone?

Reply With Quote
  #3  
Old October 29th, 2012, 12:17 PM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,874 Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 17 h 30 m 25 sec
Reputation Power: 2569
There are solutions to your question but this seems to be a very peculiar way of going about things. Why are you using this method to deploy Javascript?
__________________
[PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

W3Fools - A W3Schools Intervention.

Reply With Quote
  #4  
Old October 29th, 2012, 04:12 PM
superprogrammer superprogrammer is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Posts: 850 superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 6 h 16 m 50 sec
Reputation Power: 10
Send a message via AIM to superprogrammer Send a message via MSN to superprogrammer Send a message via Yahoo to superprogrammer
The reason is as I mentioned, I am using the same object at javascript end to monitor and get my related data in browser

Reply With Quote
  #5  
Old October 29th, 2012, 06:12 PM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,874 Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 17 h 30 m 25 sec
Reputation Power: 2569
I understand why you are using the same Javascript as Java. I am asking why you are deploying it via a JSON object. To put it another way, why are you not simply printing the Javascript into the document?

Reply With Quote
  #6  
Old November 12th, 2012, 06:55 AM
superprogrammer superprogrammer is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Posts: 850 superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level)superprogrammer User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 6 h 16 m 50 sec
Reputation Power: 10
Send a message via AIM to superprogrammer Send a message via MSN to superprogrammer Send a message via Yahoo to superprogrammer
Sorry for the late response because of Sandy and other things..
Let me explain more
I do have the javascript objects in the client code(which I created by manually making it similar to the java classes)
Json is coming in picture only while sending the data from browser to server(I can send in xml or json format and I preferred json since at server it was easy to convert it to java object)
My question is, given 80 such java classes, is there any way to convert these classes to javascript objects?(More importantly, it would be good if this is possible at runtime too)

Reply With Quote
  #7  
Old November 15th, 2012, 06:47 AM
Winters Winters is offline
Super Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jul 2003
Posts: 3,874 Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level)Winters User rank is General 24th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 17 h 30 m 25 sec
Reputation Power: 2569
Ok, I'll start off by saying that yes you can execute data as code by using the eval function. It is however extremely dangerous to allow that level of functionality on a client-side application.

Another option is to create a file with the generated Javascript in and then insert the file into the document, as an active Javascript source.

I'm still not clear on this. Is the code dynamic and therefore requires generation? Or is it only the data that is dynamic? If it is only the data then there is no need to send over the code also, at least not after the document has loaded.

Can you explain the flow of this application and the requirement for transferring functionality after document load?

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Java Classes to Javascript Object

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap