Friday, December 31, 2010

Wicket : Unable to hide/show the components through Ajax

Hi,

Just came across a problem, where I was not able to hide a text field on a DropDown Change event.

On the onChange event of the dropdown i was doing the following :

myDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
myTxtField.clearInput();
myTxtField.setModelObject("");
myTxtField.setEnabled(false);
myTxtField.setVisible(false);
target.addComponent(myTxtField);
}
});

Solution:
I added the following line in the onUpdate method and it worked:

myTxtField.setOutputMarkupPlaceholderTag(true);

The SetOutputMarkupPlaceholder() method helps to re-render the wicket components.

Thanks,
Sanjay Ingole

Sunday, December 19, 2010

Wicket : Unable to re-submit the form after the form errors

I was working on a login form where two fields were used as usual i.e. login id and password.

I used a form with an AjaxSubmitLink and overrode its onSubmit and onError methods.
I did not use the FeedbackPanel on the form as I used custom labels with some style to show the errors.

in the onError overridden method I did the following :


      protected void onError(final AjaxRequestTarget target, final Form form) {

        if(userEmail.getFeedbackMessage() != null) {
          invalidEmailLabel.setDefaultModelObject(
                          userEmail.getFeedbackMessage().getMessage().toString());
          invalidEmailLabel.setOutputMarkupPlaceholderTag(true);
        }
        if(userPassword.getFeedbackMessage() != null) {                    
           userPassword.getFeedbackMessage().getMessage().toString());

        passwordError.setDefaultModelObject(
                   userPassword.getFeedbackMessage().getMessage().toString()); 
          loginErrorMessage.setVisible(false);
        }


        userPassword.clearInput();
        userPassword.setModelObject("");
        form.add(userPassword);
        target.addComponent(form);
        
      }
    };

This code looks fine. But I faced one issue - After the page is loaded for the first time, If I enter correct data it works fine but as soon as I input the invalid values, the form validation fails and form error occurs. Which is an expected behavior but then again if I give the correct values and try to submit the form, it doest pass me through. I played with ajax a lot but coud not find the solution.

Then I found the cleanupFeedbackMessages() method by doing some search, but in my custom session I had an empty implementation of cleanupFeedbackMessages(), as my custom session extended org.apache.wicket.Session. 
I changed my session's parent class to org.apache.wicket.protocol.http.WebSession; which does not require to override the cleanupFeedbackMessages() method.

Then in my onError method I called the following which solved my problem.


getSession().cleanupFeedbackMessages();

This method saved my life,My ajax implementation worked fine as expected. I was almost going to implement it on page load event. But could not compromise with what I desired.

Finally somebody has said it correctly : "Where is the will , there is the way."

Let me know if this info helped you.

Thanks,
Sanjay :)

Friday, December 17, 2010

Unable to broadcast webcam with yahoo messanger on my macbook

Hi

 I had a problem using my built-in webcam on macbook while using yahoo messenger, whereas it was working fine with gtalk. I did following to fix the problem and it worked.

Open Yahoo messenger-> Open Preferences -> WebCam -> Video

There is a drop-down called - Video Source with values :

-Google Camera Adapter 0
-Google Camera Adapter 1
-Built-In iSight

In my case Google Camera Adapter 0 was set by default. I changed it to - Built-In iSight.

Then closed the camera and reopened. It solved my problem :)

Just thought it be helpful for somebody who is facing the same problem.

Regards,
Sanjay