Re: Variable numbers of rows

2007-02-20 Thread Justin Walsh
Ok still confused:  I've got

Names = {
  elements: {},
  GUID: 0;
  update: function(id, value) {
var realId = parseInt(id.split("_")[1], 10);
Names.elements[realId] = value;
  },
  add: function() {
Names.GUID++;
Names.elements[Names.GUID] = null;
  },
  generateJSON: function() {
return (Names.elements).toJSONString();
  }
}

Obviously
return (Names.elements).toJSONString();
is going to break because I don't implement this method

So - how do I return a JSON string representation of my element object
so I can populate the hidden field?

Justin


Jesse Kuhnert wrote:
> You don't need a json javascript library, that's the whole point of
> the protocol. You just eval ' it and you're on your way.
> 
> If you want to get the response back correctly eval'd for you and such
> you can implement the function:
> 
> tapestry.loadJson=function(type, data, http, kwArgs){ }
> 
> "data" will be your json object structure. Ie if you returned
> something like {this:value,means:nothing} you'd be able to do:
> 
> 
> tapestry.loadJson=function(type, data, http, kwArgs){
>   alert("Hey what does it mean?: " + data["means"]);
> }
> 

-- 
Justin Walsh
http://www.ewage.co.za

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Variable numbers of rows

2007-02-20 Thread Justin Walsh
Justin Walsh wrote:


D'oh

Just realised that eval is for converting text to object.  Sorry.

-- 
Justin Walsh

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Variable numbers of rows

2007-02-20 Thread Justin Walsh
Ok - I'm stumbling at the first hurdle here then.  I know that this is
JSON question but its in the context of this example.

I'm looking at: http://www.json.org/js.html
and trying to follow their example:

So I have

var myJSONObject = {"bindings": [
{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
{"ircEvent": "PRIVMSG", "method": "deleteURI", "regex":
"^delete.*"},
{"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
]
};

But when I call:

var myObject = eval('(' + myJSONObject + ')');

I get
missing ] after element list
http://localhost:8080/prototypes/FirstJSON.html#
Line 79

What am I doing wrong?


Jesse Kuhnert wrote:
> You don't need a json javascript library, that's the whole point of
> the protocol. You just eval ' it and you're on your way.
> 
> If you want to get the response back correctly eval'd for you and such
> you can implement the function:
> 
> tapestry.loadJson=function(type, data, http, kwArgs){ }
> 
> "data" will be your json object structure. Ie if you returned
> something like {this:value,means:nothing} you'd be able to do:
> 
> 
> tapestry.loadJson=function(type, data, http, kwArgs){
>   alert("Hey what does it mean?: " + data["means"]);
> }
> 

-- 
Justin Walsh
http://www.ewage.co.za

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Variable numbers of rows

2007-02-20 Thread Jesse Kuhnert

You don't need a json javascript library, that's the whole point of
the protocol. You just eval ' it and you're on your way.

If you want to get the response back correctly eval'd for you and such
you can implement the function:

tapestry.loadJson=function(type, data, http, kwArgs){ }

"data" will be your json object structure. Ie if you returned
something like {this:value,means:nothing} you'd be able to do:


tapestry.loadJson=function(type, data, http, kwArgs){
  alert("Hey what does it mean?: " + data["means"]);
}

On 2/21/07, Justin Walsh <[EMAIL PROTECTED]> wrote:

Hi,

Very interested in this topic.

Just a typo:

elements: [],

Also changed:

return (Names.elements).toJSONString();
to
return JSONstring.make(Names.elements);

Not sure if this last change is correct - still having problems with the
JSON js library:

Stupid question - how do you include the JSON javascript library.  I was
under the impression it was included automatically - but I'm getting:

JSONstring is not defined
http://localhost:8080/prototypes/FirstJSON.html#
Line 76

I'm using tapestry 4.1.1 and have the following in my html:



...
...

Thanks



Jesse Kuhnert wrote:
> Well, I just assumed ~everyone~ must be using 4.1 by now. =p
>
> On 2/20/07, Matt Brock <[EMAIL PROTECTED]> wrote:
>>

--
Justin Walsh

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Variable numbers of rows

2007-02-20 Thread Justin Walsh
Hi,

Very interested in this topic.

Just a typo:

elements: [],

Also changed:

return (Names.elements).toJSONString();
to
return JSONstring.make(Names.elements);

Not sure if this last change is correct - still having problems with the
JSON js library:

Stupid question - how do you include the JSON javascript library.  I was
under the impression it was included automatically - but I'm getting:

JSONstring is not defined
http://localhost:8080/prototypes/FirstJSON.html#
Line 76

I'm using tapestry 4.1.1 and have the following in my html:



...
...

Thanks



Jesse Kuhnert wrote:
> Well, I just assumed ~everyone~ must be using 4.1 by now. =p
> 
> On 2/20/07, Matt Brock <[EMAIL PROTECTED]> wrote:
>>

-- 
Justin Walsh

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [WARNING] Variable numbers of rows

2007-02-20 Thread Jesse Kuhnert

Well, I just assumed ~everyone~ must be using 4.1 by now. =p

On 2/20/07, Matt Brock <[EMAIL PROTECTED]> wrote:



Jessek wrote:
>
> Don't forget that json is also included ~in~
> 
tapestry...http://tapestry.apache.org/tapestry4.1/apidocs/org/apache/tapestry/json/package-summary.html
>

Ahem... 4.1

The OP said he was using Tap 4.  :)
--
View this message in context: 
http://www.nabble.com/Variable-numbers-of-rows-tf3255330.html#a9075300
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [WARNING] Variable numbers of rows

2007-02-20 Thread Matt Brock


Jessek wrote:
> 
> Don't forget that json is also included ~in~
> tapestry...http://tapestry.apache.org/tapestry4.1/apidocs/org/apache/tapestry/json/package-summary.html
> 

Ahem... 4.1

The OP said he was using Tap 4.  :)
-- 
View this message in context: 
http://www.nabble.com/Variable-numbers-of-rows-tf3255330.html#a9075300
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [WARNING] Variable numbers of rows

2007-02-20 Thread Jesse Kuhnert

Don't forget that json is also included ~in~
tapestry...http://tapestry.apache.org/tapestry4.1/apidocs/org/apache/tapestry/json/package-summary.html

On 2/20/07, Matt Brock <[EMAIL PROTECTED]> wrote:


Er, that "Add another name" got link-ified!  It should read:

< a href ="#" onclick="newName();">Add another name.< / a>

--
View this message in context: 
http://www.nabble.com/Variable-numbers-of-rows-tf3255330.html#a9075237
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [WARNING] Variable numbers of rows

2007-02-20 Thread Matt Brock

Er, that "Add another name" got link-ified!  It should read:

< a href ="#" onclick="newName();">Add another name.< / a>

-- 
View this message in context: 
http://www.nabble.com/Variable-numbers-of-rows-tf3255330.html#a9075237
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [WARNING] Variable numbers of rows

2007-02-20 Thread Matt Brock


Michael Prescott-2 wrote:
> 
> We've got a couple of forms where users can edit a list of items, and
> also add new items to the bottom.  We're currently doing this by sending
> preset number of hidden rows, revealed as necessary by Javascript -
> although this is a little lame.

This is one of those things that used to bug me with Tap4, but it's actually
very, very easy to work around the whole "can't instantiate components on
the fly" problem.  The way to do it is to create a JavaScript object on the
client side that's updated to the state of your fields, which you can create
dynamically.  Then onSubmit, you convert your JS Object into a JSON
transport string and populate a hidden form field with the results, which
are then submitted.  You then just have to re-instantiate the Object into a
Java HashMap.  Read up on  http://www.json.org/java/index.html JSON .

Here's an egregiously simple example that should get you started...

In your .page:
  

  

  

  

  

  

In your .java:
  public abstract String getTheName();
  public abstract void setTheName(String theName);

  public abstract String getNamesList();
  public abstract void setTheNamesList(String theNamesList);

  public IPage doSubmit(IRequestCycle cycle) {
JSONObject namesList;
HashMap allNamesMap = new HashMap();
try {
  namesList = new JSONObject(getNamesList());
  for (Iterator aName = namesList.keys(); aName.hasNext();) {
String keyStr = (String) aName.next();
Integer key = Integer.parseInt(keyStr);
allNamesMap.put(key, namesList.get(keyStr).toString());
  }
} catch (JSONException e) {
  log.info("Failed: ", e.getMessage());
  return null;
}
// Now iterate through your allNamesMap and save them however you see
fit.
return this;
  }

In your .html:
  




 # Add another name. 

function newName() {
  Names.add();
  var newInput = "";
  var targetDiv = document.getElementById("namesDiv");
  targetDiv.innerHTML = targetDiv.innerHTML + newInput;
  document.getElementById("name_" + Names.GUID).onchange = function() {
Names.update(this.id, this.value);
  }
}

Names = {
  elements: {},
  GUID: 0;
  update: function(id, value) {
var realId = parseInt(id.split("_")[1], 10);
Names.elements[realId] = value;
  },
  add: function() {
Names.GUID++;
Names.elements[Names.GUID] = null;
  },
  generateJSON: function() {
return (Names.elements).toJSONString();
  }
}
  

There might be some typos in there, but that's the basic form.  You can make
your JS objects as complicated or simple as you like (this one, for
instance, is just one level deep, but it's perfectly cromulant to make
nested objects... it just takes more code to go back to a POJO when you
submit).  The JSON code is (I believe) straight from the link I gave above. 
The JavaScript JSON methods are very, very simple (naturally) and can be
downloaded  http://www.json.org/json.js here .
-- 
View this message in context: 
http://www.nabble.com/Variable-numbers-of-rows-tf3255330.html#a9075214
Sent from the Tapestry - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Variable numbers of rows

2007-02-20 Thread James Carman

Yes, tapestry will also use hidden fields to manage the state, but you
don't have to worry about it.

On 2/20/07, Jesse Kuhnert <[EMAIL PROTECTED]> wrote:

I think T4.1 does this sort of mundane state mgmt kind of stuff for you.

On 2/19/07, Michael Prescott <[EMAIL PROTECTED]> wrote:
> Sorry, Tapestry 4.0.
>
> -Original Message-
> From: Mark Stang [mailto:[EMAIL PROTECTED]
> Sent: February 19, 2007 4:46 PM
> To: Tapestry users; tapestry-user@jakarta.apache.org
> Subject: RE: Variable numbers of rows
>
> Which version of Tapestry are you using?
>
> Mark J. Stang
> Senior Engineer/Architect
> office: +1 303.468.2900
> mobile: +1 303.507.2833
> Ping Identity
>
>
>
> -Original Message-
> From: Michael Prescott [mailto:[EMAIL PROTECTED]
> Sent: Mon 2/19/2007 2:29 PM
> To: tapestry-user@jakarta.apache.org
> Subject: Variable numbers of rows
>
> We've got a couple of forms where users can edit a list of items, and
> also add new items to the bottom.  We're currently doing this by sending
> preset number of hidden rows, revealed as necessary by Javascript -
> although this is a little lame.
>
> It seems that components like @For are designed to handle changes in the
> backing data set that originate on the server, but not on the client.
> There are hidden fields that need maintenance, for one thing.
>
> Is there a common approach for this sort of scenario?  Off the top of my
> head, it looks like I might need to implement something like @For, but
> which has a well-known (or at least published) contract in terms of the
> hidden field maintenance that would be required.
>
> Any clues or pointers would be much appreciated.
>
> Michael
>
>
> Michael Prescott
> direct: 416.646.7062
>
> main: 416.646.7000
> fax: 416.646.7050
>
> Exchange Solutions Inc.
> 250 Yonge Street, 18th Floor
> Toronto, ON M5B 2L7
> www.exchangesolutions.com
>
>
>
>
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


--
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Variable numbers of rows

2007-02-19 Thread Jesse Kuhnert

I think T4.1 does this sort of mundane state mgmt kind of stuff for you.

On 2/19/07, Michael Prescott <[EMAIL PROTECTED]> wrote:

Sorry, Tapestry 4.0.

-Original Message-
From: Mark Stang [mailto:[EMAIL PROTECTED]
Sent: February 19, 2007 4:46 PM
To: Tapestry users; tapestry-user@jakarta.apache.org
Subject: RE: Variable numbers of rows

Which version of Tapestry are you using?

Mark J. Stang
Senior Engineer/Architect
office: +1 303.468.2900
mobile: +1 303.507.2833
Ping Identity



-Original Message-
From: Michael Prescott [mailto:[EMAIL PROTECTED]
Sent: Mon 2/19/2007 2:29 PM
To: tapestry-user@jakarta.apache.org
Subject: Variable numbers of rows

We've got a couple of forms where users can edit a list of items, and
also add new items to the bottom.  We're currently doing this by sending
preset number of hidden rows, revealed as necessary by Javascript -
although this is a little lame.

It seems that components like @For are designed to handle changes in the
backing data set that originate on the server, but not on the client.
There are hidden fields that need maintenance, for one thing.

Is there a common approach for this sort of scenario?  Off the top of my
head, it looks like I might need to implement something like @For, but
which has a well-known (or at least published) contract in terms of the
hidden field maintenance that would be required.

Any clues or pointers would be much appreciated.

Michael


Michael Prescott
direct: 416.646.7062

main: 416.646.7000
fax: 416.646.7050

Exchange Solutions Inc.
250 Yonge Street, 18th Floor
Toronto, ON M5B 2L7
www.exchangesolutions.com






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Variable numbers of rows

2007-02-19 Thread Michael Prescott
Sorry, Tapestry 4.0.

-Original Message-
From: Mark Stang [mailto:[EMAIL PROTECTED] 
Sent: February 19, 2007 4:46 PM
To: Tapestry users; tapestry-user@jakarta.apache.org
Subject: RE: Variable numbers of rows

Which version of Tapestry are you using?

Mark J. Stang
Senior Engineer/Architect
office: +1 303.468.2900
mobile: +1 303.507.2833
Ping Identity



-Original Message-
From: Michael Prescott [mailto:[EMAIL PROTECTED]
Sent: Mon 2/19/2007 2:29 PM
To: tapestry-user@jakarta.apache.org
Subject: Variable numbers of rows
 
We've got a couple of forms where users can edit a list of items, and
also add new items to the bottom.  We're currently doing this by sending
preset number of hidden rows, revealed as necessary by Javascript -
although this is a little lame.
 
It seems that components like @For are designed to handle changes in the
backing data set that originate on the server, but not on the client.
There are hidden fields that need maintenance, for one thing.
 
Is there a common approach for this sort of scenario?  Off the top of my
head, it looks like I might need to implement something like @For, but
which has a well-known (or at least published) contract in terms of the
hidden field maintenance that would be required.
 
Any clues or pointers would be much appreciated.
 
Michael
 

Michael Prescott
direct: 416.646.7062

main: 416.646.7000
fax: 416.646.7050 

Exchange Solutions Inc.
250 Yonge Street, 18th Floor
Toronto, ON M5B 2L7
www.exchangesolutions.com

 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Variable numbers of rows

2007-02-19 Thread Mark Stang
Which version of Tapestry are you using?

Mark J. Stang
Senior Engineer/Architect
office: +1 303.468.2900
mobile: +1 303.507.2833
Ping Identity



-Original Message-
From: Michael Prescott [mailto:[EMAIL PROTECTED]
Sent: Mon 2/19/2007 2:29 PM
To: tapestry-user@jakarta.apache.org
Subject: Variable numbers of rows
 
We've got a couple of forms where users can edit a list of items, and
also add new items to the bottom.  We're currently doing this by sending
preset number of hidden rows, revealed as necessary by Javascript -
although this is a little lame.
 
It seems that components like @For are designed to handle changes in the
backing data set that originate on the server, but not on the client.
There are hidden fields that need maintenance, for one thing.
 
Is there a common approach for this sort of scenario?  Off the top of my
head, it looks like I might need to implement something like @For, but
which has a well-known (or at least published) contract in terms of the
hidden field maintenance that would be required.
 
Any clues or pointers would be much appreciated.
 
Michael
 

Michael Prescott
direct: 416.646.7062

main: 416.646.7000 
fax: 416.646.7050 

Exchange Solutions Inc.
250 Yonge Street, 18th Floor
Toronto, ON M5B 2L7
www.exchangesolutions.com

 



Variable numbers of rows

2007-02-19 Thread Michael Prescott
We've got a couple of forms where users can edit a list of items, and
also add new items to the bottom.  We're currently doing this by sending
preset number of hidden rows, revealed as necessary by Javascript -
although this is a little lame.
 
It seems that components like @For are designed to handle changes in the
backing data set that originate on the server, but not on the client.
There are hidden fields that need maintenance, for one thing.
 
Is there a common approach for this sort of scenario?  Off the top of my
head, it looks like I might need to implement something like @For, but
which has a well-known (or at least published) contract in terms of the
hidden field maintenance that would be required.
 
Any clues or pointers would be much appreciated.
 
Michael
 

Michael Prescott
direct: 416.646.7062

main: 416.646.7000 
fax: 416.646.7050 

Exchange Solutions Inc.
250 Yonge Street, 18th Floor
Toronto, ON M5B 2L7
www.exchangesolutions.com