You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by iberck <ib...@gmail.com> on 2011/07/13 22:10:10 UTC

T5.2.6 JSONLiteral Bug

Hi forum:

When I send a JSONObject or JSONArray without JSONLiteral, my page shows a
"[OK] Alert", the problem is when I send a JSONLiteral, the test1 function
never is executed, I suppose it's a bug, anyone can help me?
This is my test code:


Test.tml:
<code>
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
    
</html>
</code>

Test.java:
<code>
@Import(library="context:js/Test.js")
public class Test {

    @Inject
    private JavaScriptSupport jsSupport;

    void setupRender() {
        JSONObject jobj = new JSONObject();
        jobj.put("strkey", new JSONLiteral("strvalue"));
        

        jsSupport.addInitializerCall("test1", jobj);
    }
}
</code>

Test.js:
<code>
Tapestry.Initializer.test1 = function(params) {
    alert("ok");
}
</code>


Thanks in advance ;)


--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584187.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5.2.6 JSONLiteral Bug

Posted by iberck <ib...@gmail.com>.
I found the fix passing the arguments like javascript objects, this is my
code Taha :

<code>
@Import(library = {
    "context:js/jqplot/jquery.jqplot.min.js", // jqplot base
    "JQPlotInit.js",
    "context:js/jquery-ui-resizable-1.8.6.min.js",// resize
    "context:js/jqplot/jqplot.canvasTextRenderer.min.js",
    "context:js/jqplot/jqplot.canvasAxisLabelRenderer.min.js",
    "context:js/jqplot/jqplot.canvasAxisTickRenderer.min.js", // Permite
rotar los datos de los ejes
    "context:js/jqplot/jqplot.categoryAxisRenderer.min.js",
    "context:js/jqplot/jqplot.pointLabels.min.js", // pinta los valores
arriba de las barras
    "context:js/jqplot/jqplot.barRenderer.min.js" //Pinta las series como
barras
},
stylesheet = {
    "context:css/jqplot/jquery.jqplot.min.css", // css jqplot
    "context:css/ui-lightness/jquery-ui-1.8.6.resizable.css" // css resize
})
public class PlotVBar {

    // Datos que serán graficados, formato: [['uno',1],['dos',2],['tres',3]]
    @Parameter(required = true)
    private JSONArray _data;
    // Título de la gráfica
    @Parameter(defaultPrefix = "literal")
    private String _titulo;
    // Etiqueta que se mostrará en el eje X
    @Parameter(defaultPrefix = "literal")
    private String _labelX;
    // Etiqueta que se mostrará en el eje Y
    @Parameter(defaultPrefix = "literal")
    private String _labelY;
    // Indica si se desea rotar 30° a la izquierda las etiquetas del eje X,
este parámetro debe
    // ser establecido cuando sean muy largas las etiquetas del eje X, por
ejemplo en una pregunta
    // de opciones
    @Parameter
    private boolean _rotarEtiquetasX;
    // Indica los colores que tendrán las barras. Si sólo se indican 2
colores y hay
    // 6 barras entonces se repitirán esos 2 colores 3 veces
    @Parameter
    private String[] _colores;
    // Opciones de las gráficas
    private JSONObject options;
    @Inject
    private JavaScriptSupport jsSupport;

    void setupRender() {
       
////////////////////////////////////////////////////////////////////////
        // GRÁFICA
       
////////////////////////////////////////////////////////////////////////
        options = new JSONObject();
        options.put("title", _titulo);
        if (_colores != null) {
            options.put("seriesColors", WUtils.toJSONArray(_colores)); //
Array con los colores de las barras
        }

       
////////////////////////////////////////////////////////////////////////
        // DATOS
       
////////////////////////////////////////////////////////////////////////
        JSONArray series = new JSONArray();
        options.put("series", series);

        JSONObject renderer = new JSONObject();
        series.put(renderer);
        renderer.put("renderer", new
JSONLiteral("jQuery.jqplot.BarRenderer")); // Renderiza los datos como
barras
        renderer.put("rendererOptions", new JSONObject().put("varyBarColor",
true)); // Cada barra tiene un color distinto, los colores se definen en
"seriesColors"

       
////////////////////////////////////////////////////////////////////////
        // DEFAULT EN LOS EJES (X,Y)
       
////////////////////////////////////////////////////////////////////////
        JSONObject axesDefaults = new JSONObject();
        options.put("axesDefaults", axesDefaults);
        axesDefaults.put("labelRenderer", new
JSONLiteral("jQuery.jqplot.CanvasAxisLabelRenderer"));

        JSONObject tickOptions = new JSONObject();
        axesDefaults.put("tickOptions", tickOptions);
        tickOptions.put("fontSize", "10pt");
        if (_rotarEtiquetasX) {
            tickOptions.put("angle", "-20"); // Rota las etiquetas 30° a la
izquierda
        }
        tickOptions.put("formatString", "%d"); // Todos los valores que
muestra son enteros

        JSONObject axes = new JSONObject();
        options.put("axes", axes);

       
////////////////////////////////////////////////////////////////////////
        // EJE X
       
////////////////////////////////////////////////////////////////////////
        JSONObject xaxis = new JSONObject();
        axes.put("xaxis", xaxis);
        xaxis.put("renderer", new
JSONLiteral("jQuery.jqplot.CategoryAxisRenderer"));
        xaxis.put("tickRenderer", new
JSONLiteral("jQuery.jqplot.CanvasAxisTickRenderer"));
        xaxis.put("label", _labelX);

       
////////////////////////////////////////////////////////////////////////
        // EJE Y
       
////////////////////////////////////////////////////////////////////////
        JSONObject yaxis = new JSONObject();
        axes.put("yaxis", yaxis);
        yaxis.put("label", _labelY);
        yaxis.put("min", 0); // El eje y empieza en 0
    }

    void beginRender(MarkupWriter writer) {
        // div que contiene la gráfica para hacer resize
        writer.element("div",
                "id", "resizablediv",
                "class", "ui-widget-content",
                "align", "center",
                "style", "width: 400px; height: 300px;margin-top:
2em;margin-bottom: 2em;");
        // div que contiene la gráfica
        writer.element("div",
                "id", "chartdiv",
                "style", "height:96%; width:96%;");

        // [object: array], [object: jsonobject]
        jsSupport.addScript("new JQPlot(%s,%s);", _data.toCompactString(),
options.toCompactString());
    }

    void afterRender(MarkupWriter writer) {
        writer.end(); // </div> id=chartdiv
        writer.end(); // </div> id=resizablediv
    }
}
</code>

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4618258.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5.2.6 JSONLiteral Bug

Posted by Taha Hafeez <ta...@gmail.com>.
Can you share the code ?

regards
Taha

On Thu, Jul 14, 2011 at 5:38 AM, iberck <ib...@gmail.com> wrote:
>
> Taha Hafeez wrote:
>>
>> By using JSONLiteral you are sending the value without quotes. But the
>> problem is how your value is interpreted by javascript. A string
>> literal without quotes will be interpreted as a variable and as that
>> variable is not defined you will get an error.
>>
>> Can you share the actual code ?
>>
>> regards
>> Taha
>>
>> On Thu, Jul 14, 2011 at 4:53 AM, iberck &lt;iberck@gmail.com&gt; wrote:
>>>
>>> I'm using
>>> Taha Hafeez wrote:
>>> >
>>> > Hi
>>> >
>>> > When you specify something as a JSONLiteral, it is displayed as is and
>>> no
>>> > quotes are applied. So the JSON is your case becomes
>>> >
>>> > { strkey: strvalue}
>>> >
>>> > so javascript tries to find the variable strvalue which is not there.
>>> >
>>> > When you don't specify JSONLiteral, JSON is
>>> >
>>> > {strkey : "strvalue"}
>>> >
>>> > which is fine.
>>> >
>>> >  Have you debugged it in firebug or chrome, it may be showing undefined
>>> > variable or something
>>> >
>>> > regards
>>> > Taha
>>> >
>>> > On Thu, Jul 14, 2011 at 1:46 AM, iberck &lt;iberck@gmail.com&gt; wrote:
>>> >
>>> >> When I send the JSONObject: jsSupport.addInitializerCall("test1",
>>> >> jobj.toCompactString()); IT WORKS
>>> >>
>>> >> Thanks in advance ;)
>>> >>
>>> >> --
>>> >> View this message in context:
>>> >>
>>> http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584206.html
>>> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>> >>
>>> >
>>>
>>> Thank you for your response Taha, I need the format {"key": value}
>>> because
>>> I'm using JQPlot library and it requires that json format
>>>
>>> Do you know are there another way to send the value from Tapestry without
>>> quotes ?
>>> I'm fixing the bug sending the json as compacted string and then breaking
>>> it
>>> in javascript :S
>>>
>>> Thank you
>>>
>>>
>>> --
>>> View this message in context:
>>> http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584672.html
>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> Yes I was sending the Strings as JSONLiteral but when I do it, Tapestry
> doesn't executes the javascript function...
> I'm frustrated because much of my code uses JSON. My actual code basically
> sends JSONLiteral's inside a JSONObject like the above example but it
> doesn't work by a Tapestry bug, I'm trying a version downgrade :(
> I've trying disabling SymbolConstants.COMPACT_JSON but it doesn't work
>
> Thank you for your responses
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584751.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5.2.6 JSONLiteral Bug

Posted by iberck <ib...@gmail.com>.
Taha Hafeez wrote:
> 
> By using JSONLiteral you are sending the value without quotes. But the
> problem is how your value is interpreted by javascript. A string
> literal without quotes will be interpreted as a variable and as that
> variable is not defined you will get an error.
> 
> Can you share the actual code ?
> 
> regards
> Taha
> 
> On Thu, Jul 14, 2011 at 4:53 AM, iberck &lt;iberck@gmail.com&gt; wrote:
>>
>> I'm using
>> Taha Hafeez wrote:
>> >
>> > Hi
>> >
>> > When you specify something as a JSONLiteral, it is displayed as is and
>> no
>> > quotes are applied. So the JSON is your case becomes
>> >
>> > { strkey: strvalue}
>> >
>> > so javascript tries to find the variable strvalue which is not there.
>> >
>> > When you don't specify JSONLiteral, JSON is
>> >
>> > {strkey : "strvalue"}
>> >
>> > which is fine.
>> >
>> >  Have you debugged it in firebug or chrome, it may be showing undefined
>> > variable or something
>> >
>> > regards
>> > Taha
>> >
>> > On Thu, Jul 14, 2011 at 1:46 AM, iberck &lt;iberck@gmail.com&gt; wrote:
>> >
>> >> When I send the JSONObject: jsSupport.addInitializerCall("test1",
>> >> jobj.toCompactString()); IT WORKS
>> >>
>> >> Thanks in advance ;)
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584206.html
>> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> >>
>> >
>>
>> Thank you for your response Taha, I need the format {"key": value}
>> because
>> I'm using JQPlot library and it requires that json format
>>
>> Do you know are there another way to send the value from Tapestry without
>> quotes ?
>> I'm fixing the bug sending the json as compacted string and then breaking
>> it
>> in javascript :S
>>
>> Thank you
>>
>>
>> --
>> View this message in context:
>> http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584672.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


Yes I was sending the Strings as JSONLiteral but when I do it, Tapestry
doesn't executes the javascript function...
I'm frustrated because much of my code uses JSON. My actual code basically
sends JSONLiteral's inside a JSONObject like the above example but it
doesn't work by a Tapestry bug, I'm trying a version downgrade :(
I've trying disabling SymbolConstants.COMPACT_JSON but it doesn't work

Thank you for your responses


--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584751.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5.2.6 JSONLiteral Bug

Posted by Howard Lewis Ship <hl...@gmail.com>.
JSONLiteral is a hack ... in fact, it transforms what is being sent
into something that is no longer JSON.  This is necessary for certain
components that initialize themselves using JavaScript object notation
(not JSON, which is a specific subset).  The JSONLiteral often is a
symbol (to reference a function or constant defined elsewhere) or an
inline annonymous function.

Use with care.  Better yet, don't use at all.

On Wed, Jul 13, 2011 at 4:48 PM, Taha Hafeez <ta...@gmail.com> wrote:
> By using JSONLiteral you are sending the value without quotes. But the
> problem is how your value is interpreted by javascript. A string
> literal without quotes will be interpreted as a variable and as that
> variable is not defined you will get an error.
>
> Can you share the actual code ?
>
> regards
> Taha
>
> On Thu, Jul 14, 2011 at 4:53 AM, iberck <ib...@gmail.com> wrote:
>>
>> I'm using
>> Taha Hafeez wrote:
>> >
>> > Hi
>> >
>> > When you specify something as a JSONLiteral, it is displayed as is and no
>> > quotes are applied. So the JSON is your case becomes
>> >
>> > { strkey: strvalue}
>> >
>> > so javascript tries to find the variable strvalue which is not there.
>> >
>> > When you don't specify JSONLiteral, JSON is
>> >
>> > {strkey : "strvalue"}
>> >
>> > which is fine.
>> >
>> >  Have you debugged it in firebug or chrome, it may be showing undefined
>> > variable or something
>> >
>> > regards
>> > Taha
>> >
>> > On Thu, Jul 14, 2011 at 1:46 AM, iberck &lt;iberck@gmail.com&gt; wrote:
>> >
>> >> When I send the JSONObject: jsSupport.addInitializerCall("test1",
>> >> jobj.toCompactString()); IT WORKS
>> >>
>> >> Thanks in advance ;)
>> >>
>> >> --
>> >> View this message in context:
>> >> http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584206.html
>> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> >>
>> >
>>
>> Thank you for your response Taha, I need the format {"key": value} because
>> I'm using JQPlot library and it requires that json format
>>
>> Do you know are there another way to send the value from Tapestry without
>> quotes ?
>> I'm fixing the bug sending the json as compacted string and then breaking it
>> in javascript :S
>>
>> Thank you
>>
>>
>> --
>> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584672.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5.2.6 JSONLiteral Bug

Posted by Taha Hafeez <ta...@gmail.com>.
By using JSONLiteral you are sending the value without quotes. But the
problem is how your value is interpreted by javascript. A string
literal without quotes will be interpreted as a variable and as that
variable is not defined you will get an error.

Can you share the actual code ?

regards
Taha

On Thu, Jul 14, 2011 at 4:53 AM, iberck <ib...@gmail.com> wrote:
>
> I'm using
> Taha Hafeez wrote:
> >
> > Hi
> >
> > When you specify something as a JSONLiteral, it is displayed as is and no
> > quotes are applied. So the JSON is your case becomes
> >
> > { strkey: strvalue}
> >
> > so javascript tries to find the variable strvalue which is not there.
> >
> > When you don't specify JSONLiteral, JSON is
> >
> > {strkey : "strvalue"}
> >
> > which is fine.
> >
> >  Have you debugged it in firebug or chrome, it may be showing undefined
> > variable or something
> >
> > regards
> > Taha
> >
> > On Thu, Jul 14, 2011 at 1:46 AM, iberck &lt;iberck@gmail.com&gt; wrote:
> >
> >> When I send the JSONObject: jsSupport.addInitializerCall("test1",
> >> jobj.toCompactString()); IT WORKS
> >>
> >> Thanks in advance ;)
> >>
> >> --
> >> View this message in context:
> >> http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584206.html
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >
>
> Thank you for your response Taha, I need the format {"key": value} because
> I'm using JQPlot library and it requires that json format
>
> Do you know are there another way to send the value from Tapestry without
> quotes ?
> I'm fixing the bug sending the json as compacted string and then breaking it
> in javascript :S
>
> Thank you
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584672.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5.2.6 JSONLiteral Bug

Posted by iberck <ib...@gmail.com>.
I'm using 
Taha Hafeez wrote:
> 
> Hi
> 
> When you specify something as a JSONLiteral, it is displayed as is and no
> quotes are applied. So the JSON is your case becomes
> 
> { strkey: strvalue}
> 
> so javascript tries to find the variable strvalue which is not there.
> 
> When you don't specify JSONLiteral, JSON is
> 
> {strkey : "strvalue"}
> 
> which is fine.
> 
>  Have you debugged it in firebug or chrome, it may be showing undefined
> variable or something
> 
> regards
> Taha
> 
> On Thu, Jul 14, 2011 at 1:46 AM, iberck &lt;iberck@gmail.com&gt; wrote:
> 
>> When I send the JSONObject: jsSupport.addInitializerCall("test1",
>> jobj.toCompactString()); IT WORKS
>>
>> Thanks in advance ;)
>>
>> --
>> View this message in context:
>> http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584206.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
> 

Thank you for your response Taha, I need the format {"key": value} because
I'm using JQPlot library and it requires that json format

Do you know are there another way to send the value from Tapestry without
quotes ?
I'm fixing the bug sending the json as compacted string and then breaking it
in javascript :S

Thank you


--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584672.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5.2.6 JSONLiteral Bug

Posted by Taha Hafeez <ta...@gmail.com>.
Hi

When you specify something as a JSONLiteral, it is displayed as is and no
quotes are applied. So the JSON is your case becomes

{ strkey: strvalue}

so javascript tries to find the variable strvalue which is not there.

When you don't specify JSONLiteral, JSON is

{strkey : "strvalue"}

which is fine.

 Have you debugged it in firebug or chrome, it may be showing undefined
variable or something

regards
Taha

On Thu, Jul 14, 2011 at 1:46 AM, iberck <ib...@gmail.com> wrote:

> When I send the JSONObject: jsSupport.addInitializerCall("test1",
> jobj.toCompactString()); IT WORKS
>
> Thanks in advance ;)
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584206.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>

Re: T5.2.6 JSONLiteral Bug

Posted by iberck <ib...@gmail.com>.
When I send the JSONObject: jsSupport.addInitializerCall("test1",
jobj.toCompactString()); IT WORKS

Thanks in advance ;)

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-2-6-JSONLiteral-Bug-tp4584187p4584206.html
Sent from the Tapestry - User mailing list archive at Nabble.com.