Ok! Final, clean example:
*) spring.xml:
<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor"
/>
<bean id="jsPage" class="net.sf.apr.spring.JavaScriptFactory"
scope="prototype">
<constructor-arg index="0" value="classpath:JsPage.js" /><!-- your
page code -->
<constructor-arg index="1"><null /></constructor-arg>
<constructor-arg index="2" value="classpath:ClickJsUtils.js"
/><!-- constant click utils -->
</bean>
*) New JsPage.js and ClickJsUtils.js are attached.
JsPage.js contains only business logic and is very clean.
On Fri, Feb 5, 2010 at 21:56, Andrey P.Rybin <[email protected]> wrote:
> I have made new JsPage.js version with autobinding ;-)
>
> It looks fresh and nice.
> "Spring powered declarative javascript Click programming" (c) ;-)
>
> Attached file is actually JsPage.js.
>
> On Fri, Feb 5, 2010 at 16:28, Andrey P.Rybin <[email protected]> wrote:
>> Bob Schellink wrote:
>> does it mean you write your Click page in a dynamic language?
>>
>>
>> Yes! Exactly! But nothing special for Click ;-/
>>
>> I found bug, that prevents using this feature.
>> https://issues.apache.org/jira/browse/CLK-622
>>
>> But I did example with workaround.
>>
>> Example: How to write Spring-powered Click Pages in javascript?
>> ===============================================
>> (if you don't need Spring you can use javascript more "directly")
>>
>> 1) download JavaScriptFactory sources and build them (or just put in
>> your project sources)
>>
>> 2) make page htm template as usual (JsPage.htm in this example)
>>
>> 3) put in your spring.xml:
>> <!-- enable script beans -->
>> <bean
>> class="org.springframework.scripting.support.ScriptFactoryPostProcessor"
>> />
>>
>> <!-- id = your page name converted to bean name (1st letter in
>> lowercase), net.sf.apr.spring.JavaScriptFactory - my class, you can
>> put it in your package or in org.springframework.scripting.rhino
>> package -->
>> <bean id="jsPage" class="net.sf.apr.spring.JavaScriptFactory"
>> scope="prototype">
>> <constructor-arg index="0" value="classpath:JsPage.js" /><!-- use
>> this script in WEB-INF/classes/JsPage.js -->
>> <constructor-arg index="1"><null /></constructor-arg>
>> </bean>
>>
>> 4) Click hack/workaround:
>> put empty
>> public class JsPage extends Page {}
>> in package from click.xml pages.package
>>
>> 5) write your javascript ;-)
>> Example script is attached.
>>
>> I found two problems:
>> 1) autocomplete doesn't work (IDE doesn't know this kind of DOM model ;-)
>> 2) autobinding doesn't work - hmm... may be put it to JIRA?
>> Click could support not only fields, but getters [public type getField()]
>> too.
>> Because Rhino can generate methods, but can't fields (it is obvious).
>>
>>
>>
>>
>> On Thu, Feb 4, 2010 at 18:03, Andrey P.Rybin <[email protected]> wrote:
>>> After some investigation - It isn't off-topic!
>>>
>>> It is cool feature.
>>>
>>> I will make example in near time:
>>>
>>> How to make Click application without javac (and .java files at all)!
>>>
>>> Rails and Grails will be dead.
>>>
>>> Dynamic Click is coming ;-)
>>>
>>>
>>>
>>> On Wed, Feb 3, 2010 at 21:37, Andrey P.Rybin <[email protected]> wrote:
>>>> Sorry for off-topic, but I think it can help somebody.
>>>> And I need testers ;-\
>>>>
>>>> I have made bug fixed, improved, multi-thread safe, spring 3.0
>>>> compatible JavaScriptFactory "on steroids".
>>>>
>>>> * https://jira.springsource.org/browse/SPR-1933
>>>> * Direct download:
>>>> https://jira.springsource.org/secure/attachment/16139/org.springframework.scripting.rhino.zip
>>>> * Examples:
>>>> https://jira.springsource.org/browse/SPR-1933?focusedCommentId=50770&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_50770
>>>>
>>>>
>>>> It is Rhino javascript support for Spring framework (core, not mvc).
>>>> Spring supports out-of-box BeanShell, JRuby and Groovy.
>>>> With JavaScriptFactory you can write your Spring beans in Javascript.
>>>>
>>>>
>>>> Russian announce (with many examples):
>>>> http://community.livejournal.com/ru_java/901310.html
>>>>
>>>
>>
>
ClickJsUtils.js
Description: JavaScript source
JsPage.js
Description: JavaScript source
