You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Serban Balamaci <se...@asf.ro> on 2011/03/11 15:37:55 UTC

Stateless Wicket and Ajax

Hello everybody.
I'm interested in Wicket for a public site. I want to use stateless pages in
order to have nice looking pages indexed by Google(no JSESSIONID in the url)

There is an approach to remove JSESSIONID from the url for search bots but I
do not like it since that would mean that any link to another page contained
in that page would cause a Page Expired error since the session is lost thus
no deep page navigation.

So how would you implement AJAX since having AjaxLinks and even
AjaxEventBehaviour makes a stateless page become statefull? 
There is the jolira tools wicket-stateless which provides
StatelessAjaxFallbackLink, but it seems that there is the link is inside a
repeater "it could be that the component is inside a repeater make your
component return false in getStatelessHint()" which pretty much means that
the page becomes statefull.

I'm even considering using JQuery for AJAX and so looked at WiQuery with
WiQueryAbstractAjaxBehavior but alas it extends AbstractDefaultAjaxBehavior. 

So perhaps using JQuery ajax requesting from with a generic WebPage serving
wicket panels based on page parameters? This seems a poor approach.

In the end, what other framework would you recommend? Preferably JAVA based.
Maybe Play framework(not a fan of the templating sintax)?  

Thank you.

-----
http://balamaci.wordpress.com 
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3348266.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Stateless Wicket and Ajax

Posted by Serban Balamaci <se...@asf.ro>.
Hello everybody.
It is indeed as Robert is saying. And after changing the code, it works
        Component component = page.get(pageRelativeComponentPath);

        // See {@link
        //
BookmarkableListenerInterfaceRequestTarget#processEvents(RequestCycle)}
        // We make have to try to look for the component twice, if we hit
the
        // same condition.
        if (component == null) {
            page.prepareForRender(false);
            component = page.get(pageRelativeComponentPath);
            //Component no longer null
....

Looking at "BookmarkableListenerInterfaceRequestTarget#processEvents" we
find the comment:
"this is quite a hack to get components in repeater work. But it still can
fail if the repeater is a paging one or on every render it will generate new
index for the items..."

I was trying to implement a comment system for articles. The stateless ajax
buttons would be reply buttons for comments that can span multi levels. I
can't feel confident that the comment hierarchy will not change by the time
the user clicks reply. Currently I'm thinking of moving the reply as a
behaviour outside the repeater, and use JQuery to pass the comment id to
that behaviour so I can know to which comment the user is replying.


Thanks everybody.

-----
http://balamaci.wordpress.com 
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3352490.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Stateless Wicket and Ajax

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Sat, Mar 12, 2011 at 10:41 PM, robert.mcguinness <
robert.mcguinness.iii@gmail.com> wrote:

> Martin,
>
> With a custom StatelessRequestMapper and and a the change to
> Behaviors.getBehaviorById(int id) below I was able to get stateless
> components to work in 1.5 using a clone
> https://github.com/martin-g/wicket-stateless.  This is probably not the
> best
> approach but it was a fun exercise.
>
> http://apache-wicket.1842946.n4.nabble.com/file/n3350821/Behaviors.java
> Behaviors.java
>
> http://apache-wicket.1842946.n4.nabble.com/file/n3350821/StatelessRequestMapper.java
> StatelessRequestMapper.java
>
> Thanks! I'll check them.
A change in Behaviors.java is indeed needed. But I never needed custom
request mapper to have the stateless ajax links and behaviors working.
Thanks again for sharing your work!

> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3350821.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Stateless Wicket and Ajax

Posted by "robert.mcguinness" <ro...@gmail.com>.
Martin,

With a custom StatelessRequestMapper and and a the change to
Behaviors.getBehaviorById(int id) below I was able to get stateless
components to work in 1.5 using a clone
https://github.com/martin-g/wicket-stateless.  This is probably not the best
approach but it was a fun exercise.

http://apache-wicket.1842946.n4.nabble.com/file/n3350821/Behaviors.java
Behaviors.java 
http://apache-wicket.1842946.n4.nabble.com/file/n3350821/StatelessRequestMapper.java
StatelessRequestMapper.java 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3350821.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Stateless Wicket and Ajax

Posted by Decebal Suiu <de...@asf.ro>.
Hi

I have the same problem "unable to find component with path... " (a
DropDownChoice with StatelessAjaxFormComponentUpdatingBehavior("onchange")
on each item in a repeater ). It's now a solution without to modify wicket
sources (probably with the wicket 1.5 version)?

Thanks,
decebal

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3783810.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Stateless Wicket and Ajax

Posted by Martin Grigorov <mg...@apache.org>.
On Sat, Mar 12, 2011 at 2:48 PM, Serban Balamaci <se...@asf.ro>wrote:

> Yes I was looking at jolira tools, but I get the exception ""unable to find
> component .... "" and looking at the source:
> final Component component = page.get(pageRelativeComponentPath);
> if (component == null) {
>            throw new WicketRuntimeException("unable to find component with
> path "
>                            + pageRelativeComponentPath
>                            + " on stateless page "
>                            + page
>                             + " it could be that the component is inside a
> repeater make your component return false in getStatelessHint()");
>        }
>
> and yes I'm using it inside a ListView, so this means that
> StatelessAjaxFallbackLink cannot be used inside a repeater(and have a
> stateless page)?
>
> Martin I see that you have not replaced StatelessWebRequestCodingStrategy
> in
> your  https://github.com/martin-g/wicket-stateless

I didn't need it so far. The Ajax stateless links and behaviors work just
fine for now.

>
> https://github.com/martin-g/wicket-stateless . So the problem with the
> ajax
> link in the repeater remains?
>
I'm not sure. I'll need more test cases to see when and why it doesn't work.
Please create a quickstart that fails and attach it to GitHub issue.

>
> I'm trying to understand if there is a known case of not using
> StatelessAjaxFallbackLink inside repeaters. Or is it somehow my fault? My
> repeater model does not change beetween renderings so the
> pageRelativeComponentPath should be the same.
>
> -----
> http://balamaci.wordpress.com
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3350179.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Stateless Wicket and Ajax

Posted by "robert.mcguinness" <ro...@gmail.com>.
Serban,

If you make the change below in StatelessWebRequestCodingStrategy the
component should be found in the page.  It's a copy from
BookmarkableListenerInterfaceRequestTarget#processEvents.  Jolira noted this
might be needed in their comments.


private static Component getComponent(final Page page, final String
componentPath) {
		final String pageRelativeComponentPath =
Strings.afterFirstPathComponent(componentPath, PATH_SEPARATOR);
		 Component component = page.get(pageRelativeComponentPath);

		
		if(component == null) {
			page.prepareForRender(false);
			component = page.get(pageRelativeComponentPath);
			
			// See {@link
			//
BookmarkableListenerInterfaceRequestTarget#processEvents(RequestCycle)}
			// We make have to try to look for the component twice, if we hit the
			// same condition.
			if (component == null) {
				throw new WicketRuntimeException("unable to find component with path " +
pageRelativeComponentPath + " on stateless page " + page
						+ " it could be that the component is inside a repeater make your
component return false in getStatelessHint()");
			}
		}
		

		return component;
}

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3350985.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Stateless Wicket and Ajax

Posted by Serban Balamaci <se...@asf.ro>.
Yes I was looking at jolira tools, but I get the exception ""unable to find
component .... "" and looking at the source:
final Component component = page.get(pageRelativeComponentPath); 
if (component == null) {
            throw new WicketRuntimeException("unable to find component with
path "
                            + pageRelativeComponentPath
                            + " on stateless page "
                            + page
                            + " it could be that the component is inside a
repeater make your component return false in getStatelessHint()");
        }

and yes I'm using it inside a ListView, so this means that
StatelessAjaxFallbackLink cannot be used inside a repeater(and have a
stateless page)?

Martin I see that you have not replaced StatelessWebRequestCodingStrategy in
your  https://github.com/martin-g/wicket-stateless
https://github.com/martin-g/wicket-stateless . So the problem with the ajax
link in the repeater remains?

I'm trying to understand if there is a known case of not using
StatelessAjaxFallbackLink inside repeaters. Or is it somehow my fault? My
repeater model does not change beetween renderings so the
pageRelativeComponentPath should be the same.

-----
http://balamaci.wordpress.com 
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3350179.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Stateless Wicket and Ajax

Posted by Martin Grigorov <mg...@apache.org>.
On Fri, Mar 11, 2011 at 8:28 PM, robert.mcguinness <
robert.mcguinness.iii@gmail.com> wrote:

> I built a stateless site using the
> http://code.google.com/p/jolira-tools/wiki/stateless Jolira Tools  and it
> worked out great, you just have to get used to using PageParameters for
> everything (contructors, pagination, etc).
>
>
>
> During development I had conditional breakpoints in locations that would
> indicate statefulness (the Stateless annotation wasn't working as expected
> at the time)
>
>
>
> Component.isStateless
> Session.isTemporary
> Session.bind
>
>
> I'm trying to convert the stateful components to Wicket 1.5 but I'm not too
> familiar with the new Wicket version yet so it's a slow process.
>
> Here they are: https://github.com/martin-g/wicket-stateless
<https://github.com/martin-g/wicket-stateless>But a tweak in Behaviors.java
is needed to work fine.
I'll try to improve that soon.

>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3348781.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Stateless Wicket and Ajax

Posted by "robert.mcguinness" <ro...@gmail.com>.
I built a stateless site using the 
http://code.google.com/p/jolira-tools/wiki/stateless Jolira Tools  and it
worked out great, you just have to get used to using PageParameters for
everything (contructors, pagination, etc).  



During development I had conditional breakpoints in locations that would
indicate statefulness (the Stateless annotation wasn't working as expected
at the time)



Component.isStateless
Session.isTemporary
Session.bind


I'm trying to convert the stateful components to Wicket 1.5 but I'm not too
familiar with the new Wicket version yet so it's a slow process.


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3348781.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Stateless Wicket and Ajax

Posted by Vojtěch Krása <vo...@gmail.com>.
Hi,
check this
http://apache-wicket.1842946.n4.nabble.com/Removing-the-jsessionid-for-SEO-td1854094.html
no error should occur.

2011/3/11 Serban Balamaci <se...@asf.ro>

> Hello everybody.
> I'm interested in Wicket for a public site. I want to use stateless pages
> in
> order to have nice looking pages indexed by Google(no JSESSIONID in the
> url)
>
> There is an approach to remove JSESSIONID from the url for search bots but
> I
> do not like it since that would mean that any link to another page
> contained
> in that page would cause a Page Expired error since the session is lost
> thus
> no deep page navigation.
>
> So how would you implement AJAX since having AjaxLinks and even
> AjaxEventBehaviour makes a stateless page become statefull?
> There is the jolira tools wicket-stateless which provides
> StatelessAjaxFallbackLink, but it seems that there is the link is inside a
> repeater "it could be that the component is inside a repeater make your
> component return false in getStatelessHint()" which pretty much means that
> the page becomes statefull.
>
> I'm even considering using JQuery for AJAX and so looked at WiQuery with
> WiQueryAbstractAjaxBehavior but alas it extends
> AbstractDefaultAjaxBehavior.
>
> So perhaps using JQuery ajax requesting from with a generic WebPage serving
> wicket panels based on page parameters? This seems a poor approach.
>
> In the end, what other framework would you recommend? Preferably JAVA
> based.
> Maybe Play framework(not a fan of the templating sintax)?
>
> Thank you.
>
> -----
> http://balamaci.wordpress.com
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Stateless-Wicket-and-Ajax-tp3348266p3348266.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>