You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by tmaus <lo...@yahoo.com> on 2012/07/30 16:09:00 UTC

Link is disabled after Ajax request

Hi there .. 

Setup a panel that covers both, a facebook-login button and a user state
sensitive link. 

The link should be disabled unless we find a user in the session. 

The Ajax FB link looks like:

AjaxLink fbLink = new AjaxLink("fb") {
            public void onClick(AjaxRequestTarget target) {

               
getPage().getRequestCycle().scheduleRequestHandlerAfterCurrent(new
RedirectRequestHandler("http://www.facebook.com/login.php?api_key=" +
pcs.getFbApiKey() + "&v=1.0"));
            }
        };
        add(fbLink).setEnabled(session.getAttribute("user") == null);

It works like a charm. 


The link looks like:
adminPageLink = new Link("adminLink",model) {
            public void onClick() {               
                setResponsePage(new HomeAdminPage());
            }

            protected void onConfigure() {
                LOG.debug("onConfigure");
                setVisible(session.getAttribute("user") != null);
            }
        };
        
        add(adminPageLink);

This link is properly rendered as long as the FB login page has not been
called and returned. 

Once the user is properly logged into FB, the adminLink is not clickable (no  
tag is rendered)

Im still quite new to Wicket and any help your be appreciated. 

Best regards

Thorsten 




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Link-is-disabled-after-Ajax-request-tp4650870.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: Link is disabled after Ajax request

Posted by tmaus <lo...@yahoo.com>.
I see all log statements. 
All methods are properly accessed. 

I tested it both ways: 
1. A static link => complete rerendering of the page
2. AjaxLink => partially rerendering of the page

In both occasions the outcome is the same. 

Initial call renders link properly
Successive call renders link as label 

The funny thing about it is, that my FB button properly switches between the
states:

public class MenuBarPanel extends Panel
...

public MenuBarPanel(String id,Page page, IModel model) {
        super(id);
        this.page = page;

        final Session session = page.getSession();

        setOutputMarkupId(true);


AjaxLink fbLink = new AjaxLink("fb") {
            public void onClick(AjaxRequestTarget target) {
                LOG.debug("button clicked");

               
getPage().getRequestCycle().scheduleRequestHandlerAfterCurrent(new
RedirectRequestHandler("http://www.facebook.com/login.php?api_key=" +
pcs.getFbApiKey() + "&v=1.0"));
            }
        };
        add(fbLink).setEnabled(session.getAttribute("user") == null);

String fbImage = null;
        if(session.getAttribute("user")!=null){
            fbImage = new StringBuilder("https://graph.facebook.com/")
                    .append( ((User)
page.getSession().getAttribute("user")).getFacebookId())
                    .append("/picture")
                    .toString();

        }else{
            fbImage = "http://www.lamptechs.com/svcimg/login.png";
        }
        fbLink.add(new StaticImage("image", new Model(fbImage)));

adminPageLink = new AdminLink("adminLink", model);
        adminPageLink.setOutputMarkupId(true);
        add(adminPageLink);

 private class AdminLink extends AjaxLink<HomeAdminPage>{
        private IModel model;

        public AdminLink(String id, IModel model) {
            super(id, model);
        }

        public void onClick(AjaxRequestTarget target) {
            setResponsePage(new HomeAdminPage());
        }
    }

On initial call, login button is rendered. On the successive call it
properly renders my picture.

The "AdminLink" however is merely "properly" rendered on the initial call. 

Im pretty sure it is a typical beginners bug but I did not find any answer
in any forum so far .. 

thanks for your help






--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Link-is-disabled-after-Ajax-request-tp4650870p4650893.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: Link is disabled after Ajax request

Posted by Martin Grigorov <mg...@apache.org>.
Do you see the log statements logged after successful authentication with FB ?

Do you re-render the whole page after authentication or just some
components (AjaxRequestTarget#add(aComponent)) ?

On Tue, Jul 31, 2012 at 12:01 PM, tmaus <lo...@yahoo.com> wrote:
> Thanks for your response, Martin ...
>
> I have tried to tweak things a bit, replace the Link by an AjaxLink,
> overrode internal methods and did some things things.
>
> The fb login button as well as the link to me admin area belong to a panel.
> The fb login button fires an async call to fb.
>
> The link is always visible on first page rendering.
> The link is always disabled after response from fb.
>
> This must be related to the Panel where both components reside in.
> No matter if the fb button is a simple Link or an AjaxLink, the callback
> from fb somehow disables the link within the panel.
>
> An outside of the Panel located Link is not disabled.
>
> Any hint why this happens or any links to docs that explain this behavior
> are much appreciated ..
>
> Regards
>
> Thorsten
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Link-is-disabled-after-Ajax-request-tp4650870p4650890.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

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


Re: Link is disabled after Ajax request

Posted by tmaus <lo...@yahoo.com>.
Thanks for your response, Martin ...

I have tried to tweak things a bit, replace the Link by an AjaxLink,
overrode internal methods and did some things things. 

The fb login button as well as the link to me admin area belong to a panel. 
The fb login button fires an async call to fb. 

The link is always visible on first page rendering. 
The link is always disabled after response from fb. 

This must be related to the Panel where both components reside in. 
No matter if the fb button is a simple Link or an AjaxLink, the callback
from fb somehow disables the link within the panel. 

An outside of the Panel located Link is not disabled. 

Any hint why this happens or any links to docs that explain this behavior
are much appreciated .. 

Regards

Thorsten 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Link-is-disabled-after-Ajax-request-tp4650870p4650890.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: Link is disabled after Ajax request

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

On Mon, Jul 30, 2012 at 5:09 PM, tmaus <lo...@yahoo.com> wrote:
> Hi there ..
>
> Setup a panel that covers both, a facebook-login button and a user state
> sensitive link.
>
> The link should be disabled unless we find a user in the session.
>
> The Ajax FB link looks like:
>
> AjaxLink fbLink = new AjaxLink("fb") {
>             public void onClick(AjaxRequestTarget target) {
>
>
> getPage().getRequestCycle().scheduleRequestHandlerAfterCurrent(new
> RedirectRequestHandler("http://www.facebook.com/login.php?api_key=" +
> pcs.getFbApiKey() + "&v=1.0"));
>             }
>         };
>         add(fbLink).setEnabled(session.getAttribute("user") == null);
>
> It works like a charm.
>
>
> The link looks like:
> adminPageLink = new Link("adminLink",model) {
>             public void onClick() {
>                 setResponsePage(new HomeAdminPage());
>             }
>
>             protected void onConfigure() {
>                 LOG.debug("onConfigure");

Is this debug statement logged after FB returns ?
Also add the value of session.getAttribute("user") in the log message.

>                 setVisible(session.getAttribute("user") != null);
>             }
>         };
>
>         add(adminPageLink);

When you update an invisible component in an Ajax request you should
also do: invisibleComponent.setOutputMarkupPlaceholder(true)
Check the javadoc of this method for more details.
But I think the second render (after FB returns) the request is not
Ajax anymore, so this shouldn't be necessary.


>
> This link is properly rendered as long as the FB login page has not been
> called and returned.
>
> Once the user is properly logged into FB, the adminLink is not clickable (no
> tag is rendered)
>
> Im still quite new to Wicket and any help your be appreciated.
>
> Best regards
>
> Thorsten
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Link-is-disabled-after-Ajax-request-tp4650870.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

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