You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alec Swan <al...@gmail.com> on 2012/08/27 16:33:47 UTC

Best practices for passing configurations, such as Facebook app_id, to JavaScript

Hello,

We deploy our web app on different domains which means that JavaScript
Facebook integration needs to use different app_id values. I am
planning to store these values in a configuration file and wonder how
to expose them to JavaScript. I would also like to write a unit test
that verifies that settings were passed correctly.

I could use a HeaderContributor to inject raw JavaScript, but this
doesn't seem to be very unit-testable. I could create a <div> which
attributes/elements contain the settings, which seems to be more
unit-testable.

Thoughts?

Thanks,

Alec

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


Re: Best practices for passing configurations, such as Facebook app_id, to JavaScript

Posted by Alec Swan <al...@gmail.com>.
I implemented the solution proposed by Fergal, but I think I will redo
it with Pointbreak's approach which seems to be cleaner.

Thanks!

Alec

On Wed, Aug 29, 2012 at 7:20 AM, Pointbreak
<po...@ml1.net> wrote:
> I would use PackageTextTemplate to render the javascript, e.g. put your
> javascript in MyPage.js along with the other templates, and use
> ${facebookId} for the id, then add this to your class:
>
> @Override public void renderHead(IHeaderResponse response) {
>     super.renderHead(response);
>     PackageTextTemplate javascript = new
>     PackageTextTemplate(MyPage.class, MyPage.class.getSimpleName() +
>     ".js");
>     Map<String, String> vars = new HashMap<String, String>();
>     vars.put("facebookId", facebookId);
>     response.renderOnDomReadyJavaScript(javascript.asString(vars));
> }
>
> On Wed, Aug 29, 2012, at 15:09, Fergal Keating wrote:
>> *HTML*
>> *
>> *
>>
>> <script type="text/javascript" wicket:id=" Facebookjs">/* script will be
>> rendered here */</script>
>>
>> *JAVA*
>>
>> String FacbookJS = " var facebookID = \"" +
>> this.getfacebookID(CurrentDomain) + "\"); ";
>> Label FacebookLabel = new Label("Facebookjs", FacbookJS );
>>
>> addOrReplace( FacebookLabel.setEscapeModelStrings(false));
>>
>> On 27 August 2012 15:33, Alec Swan <al...@gmail.com> wrote:
>>
>> > Hello,
>> >
>> > We deploy our web app on different domains which means that JavaScript
>> > Facebook integration needs to use different app_id values. I am
>> > planning to store these values in a configuration file and wonder how
>> > to expose them to JavaScript. I would also like to write a unit test
>> > that verifies that settings were passed correctly.
>> >
>> > I could use a HeaderContributor to inject raw JavaScript, but this
>> > doesn't seem to be very unit-testable. I could create a <div> which
>> > attributes/elements contain the settings, which seems to be more
>> > unit-testable.
>> >
>> > Thoughts?
>> >
>> > Thanks,
>> >
>> > Alec
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>>
>>
>> --
>> Fergal Keating
>> IT Senior Engineer
>> -----------------------------------------------
>> e. fergal.keating@directski.com
>> p. NA
>> w. www.directski.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

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


Re: Best practices for passing configurations, such as Facebook app_id, to JavaScript

Posted by Pointbreak <po...@ml1.net>.
I would use PackageTextTemplate to render the javascript, e.g. put your
javascript in MyPage.js along with the other templates, and use
${facebookId} for the id, then add this to your class:

@Override public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    PackageTextTemplate javascript = new
    PackageTextTemplate(MyPage.class, MyPage.class.getSimpleName() +
    ".js");
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("facebookId", facebookId);
    response.renderOnDomReadyJavaScript(javascript.asString(vars));
}

On Wed, Aug 29, 2012, at 15:09, Fergal Keating wrote:
> *HTML*
> *
> *
> 
> <script type="text/javascript" wicket:id=" Facebookjs">/* script will be
> rendered here */</script>
> 
> *JAVA*
> 
> String FacbookJS = " var facebookID = \"" +
> this.getfacebookID(CurrentDomain) + "\"); ";
> Label FacebookLabel = new Label("Facebookjs", FacbookJS );
> 
> addOrReplace( FacebookLabel.setEscapeModelStrings(false));
> 
> On 27 August 2012 15:33, Alec Swan <al...@gmail.com> wrote:
> 
> > Hello,
> >
> > We deploy our web app on different domains which means that JavaScript
> > Facebook integration needs to use different app_id values. I am
> > planning to store these values in a configuration file and wonder how
> > to expose them to JavaScript. I would also like to write a unit test
> > that verifies that settings were passed correctly.
> >
> > I could use a HeaderContributor to inject raw JavaScript, but this
> > doesn't seem to be very unit-testable. I could create a <div> which
> > attributes/elements contain the settings, which seems to be more
> > unit-testable.
> >
> > Thoughts?
> >
> > Thanks,
> >
> > Alec
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> 
> 
> -- 
> Fergal Keating
> IT Senior Engineer
> -----------------------------------------------
> e. fergal.keating@directski.com
> p. NA
> w. www.directski.com

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


Re: Best practices for passing configurations, such as Facebook app_id, to JavaScript

Posted by Fergal Keating <fe...@directski.com>.
*HTML*
*
*

<script type="text/javascript" wicket:id=" Facebookjs">/* script will be
rendered here */</script>

*JAVA*

String FacbookJS = " var facebookID = \"" +
this.getfacebookID(CurrentDomain) + "\"); ";
Label FacebookLabel = new Label("Facebookjs", FacbookJS );

addOrReplace( FacebookLabel.setEscapeModelStrings(false));

On 27 August 2012 15:33, Alec Swan <al...@gmail.com> wrote:

> Hello,
>
> We deploy our web app on different domains which means that JavaScript
> Facebook integration needs to use different app_id values. I am
> planning to store these values in a configuration file and wonder how
> to expose them to JavaScript. I would also like to write a unit test
> that verifies that settings were passed correctly.
>
> I could use a HeaderContributor to inject raw JavaScript, but this
> doesn't seem to be very unit-testable. I could create a <div> which
> attributes/elements contain the settings, which seems to be more
> unit-testable.
>
> Thoughts?
>
> Thanks,
>
> Alec
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Fergal Keating
IT Senior Engineer
-----------------------------------------------
e. fergal.keating@directski.com
p. NA
w. www.directski.com