Use Duetds Datepicker with Wicket? - datepicker

The Duetds Datepicker (https://github.com/duetds/date-picker) is an accessible Datepicker which i would like to use, however the usage is as follows:
<duet-date-picker identifier="date"></duet-date-picker>
which is incompatible with Wicket Form Components which require input HTML-Tags.
Do you know of a method to use this Datepicker with Wicket or another accessible Datepicker that can be used with Wicket? (Jquery UI Datepicker is not good as is closes on Tab)

You can easily use this JS widget with Wicket!
In your Java code do:
WebComponent datePicker = new WebComponent("datePicker");
parent.add(datePicker);
datePicker.add(new AjaxEventBehavior("duetChange") {
#Override public void onEvent(AjaxRequestTarget target) {
long timestamp = getRequest().getParametersValue("selectedDate").toLong();
// use timestamp here
}
#Override public void updateAjaxRequestAttributes(AjaxRequestAttributes attrs) {
super.updateAjaxRequestAttributes(attrs);
attrs.getDynamicExtraParameters().add("return {\"name\": \"selectedDate\", \"value\": attrs.e.detail.valueAsDate.getTime()}");
}
});
The HTML would be like:
<duet-date-picker wicket:id="datePicker" identifier="date"></duet-date-picker>

Related

Wicket DropDownChoice - OnChangeAjaxBehavior does not react on select of nullSelection

I use Wicket DropDownChoice with a nullSelection string (e.g. "Choose One"). I need react on event. It works fine for all choices except the nullSelection. Any idea?
dropDown.add(new OnChangeAjaxBehavior() {
#Override
protected void onUpdate(AjaxRequestTarget target) {
//some code
}
});
dropDown.setNullValid(true);
I am using Wicket 1.4.12
EDIT
I tried a new project with Wicket 1.4.12 and it works. It seems that it is cause by validators when the dropDown is required.

how to show the locale that the browser is showing in gwt I18N?

i'm doing i18n to my application i did something that is shown in showcase example i'm using the listbox to show different locales, the problem is when i'm swapping from one locale to another locale,locale is changing but the list box is not showing the locale in which i am, it is showing first element of the list every time as it is reloading
here is code:
#Override
public void changeSwap() {
final String queryParam = LocaleInfo.getLocaleQueryParam();
String locale=getView().getLocale().getValue(getView().getLocale().getSelectedIndex());
Log.info("revealed locale is"+locale);
if (queryParam != null) {
UrlBuilder builder = Location.createUrlBuilder().setParameter(
queryParam, locale);
Window.Location.replace(builder.buildString());
} else {
// If we are using only cookies, just reload
Window.Location.reload();
}
}
i didn't find any method in listbox api to do it
thanks
You're using a part of the code from the Showcase (ShowcaseShell.initializeLocaleBox()), but the part that is responsible for selecting the correct value in the ListBox is this:
String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
if (currentLocale.equals("default")) {
currentLocale = "en";
}
String[] localeNames = LocaleInfo.getAvailableLocaleNames();
for (String localeName : localeNames) {
if (!localeName.equals("default")) {
String nativeName = LocaleInfo.getLocaleNativeDisplayName(localeName);
localeBox.addItem(nativeName, localeName);
if (localeName.equals(currentLocale)) {
localeBox.setSelectedIndex(localeBox.getItemCount() - 1);
}
}
}
Make sure to add it to your code before adding the ChangeHandler to the localeBox.
Here's the full setup in the Showcase 2.4.0 example:
Showcase.gwt.xml 21-28 performs the locale setup for the module (especially it defines the available locales as "en", "ar", "fr", "zh")
ShowcaseShell.ui.xml 204-206 creates the ListBox widget.
ShowcaseShell.java 113-114, 190, 322-364 fill the available locales into the ListBox, and adds a ChangeHandler.
I would recommend to create a simple new GWT project (at first without gwtp or anything special) and just add these bits of code. Then you can try to migrate the setup to your full project.

How to hide suggestions in GWT SuggestBox?

I am using GWT 2.4. I have a Suggestbox and I have a requirement to hide the suggestion list under certain cases. The context is as below.
After user selects a suggestion from suggestion list, I am populating two other text box fields, with values corresponding to the selection. For example, suppose the suggestbox contains user-names, and user selects a user-name from suggestions, then other two fields, say user address and email are populated in two other text boxes. These two fields are read only now. Then user clicks on an 'Edit' button. Now the user can edit either user- name ( ie edit in suggestion box), user address and email. It doesn't make sense to show the suggestions again when the user is editing the user-name, since the user has already selected the user and decided to edit it. In a nutshell my SuggesBox should behave as a normal text box. I tried following code, (I know hideSuggestionList() is deprecated) but its not working.
display.getSuggestBox().hideSuggestionList();
Reading the javadoc for hideSuggestionList() it is said that, "Deprecated. use DefaultSuggestionDisplay.hideSuggestions() instead". I don't know how to use DefaultSuggestionDisplay, and I'm using SuggestBox with 'MultiWordSuggestOracle'.
Thanks for helping me out!!
What you can do is simply swap the SuggestionBox with a normal TextBox when the user clicks edit and back when edit is closed. Also because if you would hide the suggestions list, it still queried from the server. By swapping the widget you don't have to care about side effects. SuggestionBox itself uses also a TextBox and thus for the user it's not visible the widget has changed.
If you don't use your own SuggestionDisplay, then this should Just Work™:
((DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay()).hideSuggestions();
Here is the Solution
My Entry Point Class
public class SuggestionEntryPoint implements EntryPoint {
#Override
public void onModuleLoad() {
SuggestBoxWidget suggestBoxWidget = new SuggestBoxWidget();
RootPanel rootPanel = RootPanel.get();
suggestBoxWidget.createOracle();
suggestBoxWidget.createWidgetAndShow(rootPanel);
rootPanel.add(suggestBoxWidget);
DOM.getElementById("loader").removeFromParent();
}
}
And here is my Widget
public class SuggestBoxWidget extends Composite {
private TextBox textSuggestBox = new TextBox();
private SuggestBox suggestBox = null;
DefaultSuggestionDisplay suggestionDisplay = new DefaultSuggestionDisplay();
MultiWordSuggestOracle suggestOracle = new MultiWordSuggestOracle();
private static SuggestBoxWidgetUiBinder uiBinder = GWT
.create(SuggestBoxWidgetUiBinder.class);
interface SuggestBoxWidgetUiBinder extends
UiBinder<Widget, SuggestBoxWidget> {
}
public SuggestBoxWidget() {
initWidget(uiBinder.createAndBindUi(this));
}
public void registerEvents(){
suggestBox.addKeyUpHandler(new KeyUpHandler() {
#Override
public void onKeyUp(KeyUpEvent event) {
if(suggestBox.getText().equalsIgnoreCase("1")){
suggestionDisplay.hideSuggestions();
}
}
});
}
public void createWidgetAndShow(HasWidgets container){
suggestBox = new SuggestBox(suggestOracle,textSuggestBox,suggestionDisplay);
container.clear();
container.add(suggestBox);
registerEvents();
}
public void createOracle(){
for(int i=1;i<=100;i++){
suggestOracle.add(i+"");
}
}
}
Actually you have to create a SuggestBox with 3 Parameters to the Constructor.

hovering HTML help page over a link in GWT

I'm trying to implement a hovering HTML help page over a link or widget in a GWT GUI.
I tried to do something similar to change image on hover using gwt and ui-binder and http://examples.roughian.com/index.htm#Listeners~PopupListener
ui.xml
<layout:cell horizontalAlign="LEFT">
<widget:ButtonLink ui:field="manageApps" text="Applications"/>
</layout:cell>
ui.java
PopupPanel popup = new PopupPanel(true);
HTML html = new HTML("<p>Hello</p>");
//popup.setStyleName("demo-popup");
popup.add(html);
#UiHandler("manageApps")
public void onMouseOver(MouseOverEvent event) {
popup.center();
}
However compilation fails on the #UiHandler with the message: Field manageApps doesn't have 'addHandler' method for com...MouseOverHandler.
Any idea or pointer helps. Thanks.
I have a solution so far that can be improved later:
ui.java
#Override
public void onMouseOver(MouseOverEvent mouseOverEvent) {
//To change body of implemented methods use File | Settings | File Templates.
popup.center();
}
manageApps.addHandler(this, MouseOverEvent.getType());
What is a ButtonLink? If you made it yourself, did you implement HasMouseOverHandlers? Chances are the problem is that the widget doesn't know how to throw a MouseOverEvent, but you're trying to catch them anyway.
I have a solution so far that can be improved later:
ui.java
#Override
public void onMouseOver(MouseOverEvent mouseOverEvent) {
//To change body of implemented methods use File | Settings | File Templates.
popup.center();
}
manageApps.addHandler(this, MouseOverEvent.getType());

setting a default text to a GWT ListBox

I am trying to create a ListBox using GWT. I am using UiBinder to create the field.
I would like to set a default text on the list box and when a user clicks on the box, it should show me the list items. Once again, if user has not selected any option, it should show me the default text again.
Any way to do this either using Uibinder or some ListBox methods?
If I understand correctly you want a value to show but when the user clicks on the list it disappears and shows you the list items?
As far as I know there is no option to that natively.
What you can do is add the first item to hold your default value.
You can do this grammatically by using addItem in code or using:
<g:Listbox>
<g:item value="-1">Default text</g:item>
</g:Listbox>
works with gwt 2.1+
The value can still be selected.
You can choose to ignore it or add an attribute "disabled" with value "disabled" to the option element:
listbox.getElement().getFirstChildElement().setAttribute("disabled" ,"disabled" )
hope it helps a bit :)
You can also use a renderer to control what is shown if 'Null' is selected.
(Inspired by: How do I add items to GWT ListBox in Uibinder .ui.xml template ?)
private class SimpleRenderer implements Renderer<T>{
private String emptyValue = "Select a value";
#Override
public String render(T val) {
if(val == null) {
return emptyValue;
}
return val.toString();
}
#Override
public void render(T val, Appendable appendable) throws IOException {
appendable.append(render(val));
}
public void setEmptyValue(String emptyValue) {
this.emptyValue = emptyValue;
}
}