You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sandor Feher <sf...@bluesystem.hu> on 2012/09/04 16:27:36 UTC

select2 localization questions

Hi,

I successfuly created a Select2Choice item in my form. I fill it up from a
model and everything works fine but the listed choices' display in wrong
codepage. I use utf8 everywhere and have no problems with cp.
The second one is how to localize select2 messages from select2.js ?
E.g. formatNoMatches,  formatSearching and so one.

thnx., Sandor



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/select2-localization-questions-tp4651732.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: select2 localization questions

Posted by Sandor Feher <sf...@bluesystem.hu>.
Hi,


Igor Vaynberg-2 wrote
> 
> you should declare your Select2Choice as Select2Choice<Short> since
> that is its model type. once you do this the compiler will tell you
> that your TextChoiceProvider should be TextChoiceProvider<Short>
> instead of <HrpBbhepar5>
> 
> -igor
> 

In this case I can't search for description hence only the values are
displayed. Only I want to search for some text and get back it's id into a
Short field.

 private class Hepar5Provider extends TextChoiceProvider<Short> {

        @Override
        protected String getDisplayText(Short choice) {
            return choice.toString();
        }

        @Override
        protected Object getId(Short choice) {
           return choice;
        }

        @Override
        public void query(String term, int page, Response<Short> response) {
            response.addAll(queryMatches(term, page, 10));
	    response.setHasMore(response.size() == 10);
        }
        
        @Override
        public Collection<Short> toChoices(Collection<String> ids) {
            ArrayList<Short> hepar5idlist = new ArrayList<Short>();

            Iterator it = hepar5list.iterator();
            while (it.hasNext()) {
                HrpBbhepar5 h = (HrpBbhepar5) it.next();
                hepar5idlist.add(h.getHrpBbhepar5PK().getDertek());
            }
            return hepar5idlist;
        }
     }




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/select2-localization-questions-tp4651732p4651765.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: select2 localization questions

Posted by Igor Vaynberg <ig...@gmail.com>.
you should declare your Select2Choice as Select2Choice<Short> since
that is its model type. once you do this the compiler will tell you
that your TextChoiceProvider should be TextChoiceProvider<Short>
instead of <HrpBbhepar5>

-igor

On Tue, Sep 4, 2012 at 1:42 PM, Sandor Feher <sf...@bluesystem.hu> wrote:
> Okay. Just one more question.
>
> I have a domain model (HrpBbheerk) which contains a Short column. I would
> like to fill this via Select2Choice.
> I read the select2-examples but not able to get rid it.
>
> So the steps I took.
>
> 1. Fill my hepar5list list from my domain model (HrpBbhepar5). This contains
> couple of columns but I only need for two. One for value and one for
> description. If possible I don't want to create another wrapper class just
> for this case.
> 2. Create a form, added a model (HrpBbheerk)
> 3. Added a new Select2Choice to the form with that Short column mentioned
> above.
>
> Snippets:
>
> ...
>         fillHepar5(); // step 1
>         HrpBbheertk heertk = fillHeertk();
>         IModel model=new CompoundPropertyModel(heertk);
>         sform.setModel(model);  // step 2
>         Select2Choice dimelemert = new Select2Choice("dimelemert",new
> PropertyModel(sform.getModel(),"dimelemert"),new Hepar5Provider());  // step
> 3
>
> ......
>
>   private static List<HrpBbhepar5> queryMatches(String term, int page, int
> pageSize) {
>
>         List<HrpBbhepar5> result = new ArrayList<HrpBbhepar5>();
>         term = term.toUpperCase();
>
>         final int offset = page * pageSize;
>
>         int matched = 0;
>
>         for (HrpBbhepar5 hepar5 : hepar5list) {
>             if (result.size() == pageSize) {
>                 break;
>             }
>
>             if (hepar5.getDertekmegnev().toUpperCase().startsWith(term)) {
>                 matched++;
>                 if (matched > offset) {
>                     result.add(hepar5);
>                 }
>             }
>         }
>         return result;
>     }
>
>
>     public class Hepar5Provider extends TextChoiceProvider<HrpBbhepar5> {
>
>         @Override
>         protected String getDisplayText(HrpBbhepar5 choice) {
>             return choice.getDertekmegnev();
>         }
>
>         @Override
>         protected Object getId(HrpBbhepar5 choice) {
>            return choice;
>         }
>
>         @Override
>         public void query(String term, int page, Response<HrpBbhepar5>
> response) {
>             response.addAll(queryMatches(term, page, 10));
>             response.setHasMore(response.size() == 10);
>         }
>
>         @Override
>         public Collection<HrpBbhepar5> toChoices(Collection<String> ids) {
>             ArrayList<HrpBbhepar5> hepar5idlist = new
> ArrayList<HrpBbhepar5>();
>
>             Iterator it = hepar5list.iterator();
>             while (it.hasNext()) {
>                 HrpBbhepar5 h = (HrpBbhepar5) it.next();
>                 hepar5idlist.add(h);
>             }
>             return hepar5idlist;
>         }
>     }
>
> .....
>
> It complains that java.lang.Short cannot be cast to
> hu.xxx.model.HrpBbhepar5.
> Please let me know what  should I do.
>
> thnx., Sandor
>
>
>
>
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/select2-localization-questions-tp4651732p4651753.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
>

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


Re: select2 localization questions

Posted by Sandor Feher <sf...@bluesystem.hu>.
Okay. Just one more question.

I have a domain model (HrpBbheerk) which contains a Short column. I would
like to fill this via Select2Choice.
I read the select2-examples but not able to get rid it.

So the steps I took.

1. Fill my hepar5list list from my domain model (HrpBbhepar5). This contains
couple of columns but I only need for two. One for value and one for
description. If possible I don't want to create another wrapper class just
for this case.
2. Create a form, added a model (HrpBbheerk)
3. Added a new Select2Choice to the form with that Short column mentioned
above.

Snippets:

...
        fillHepar5(); // step 1
        HrpBbheertk heertk = fillHeertk();      
        IModel model=new CompoundPropertyModel(heertk);
        sform.setModel(model);  // step 2
        Select2Choice dimelemert = new Select2Choice("dimelemert",new
PropertyModel(sform.getModel(),"dimelemert"),new Hepar5Provider());  // step
3

......

  private static List<HrpBbhepar5> queryMatches(String term, int page, int
pageSize) {

	List<HrpBbhepar5> result = new ArrayList<HrpBbhepar5>();
	term = term.toUpperCase();

	final int offset = page * pageSize;

	int matched = 0;
        
	for (HrpBbhepar5 hepar5 : hepar5list) {
	    if (result.size() == pageSize) {
		break;
	    }

	    if (hepar5.getDertekmegnev().toUpperCase().startsWith(term)) {
		matched++;
		if (matched > offset) {
		    result.add(hepar5);
		}
	    }
	}
	return result;
    }
    
    
    public class Hepar5Provider extends TextChoiceProvider<HrpBbhepar5> {

        @Override
        protected String getDisplayText(HrpBbhepar5 choice) {
            return choice.getDertekmegnev();
        }

        @Override
        protected Object getId(HrpBbhepar5 choice) {
           return choice;
        }

        @Override
        public void query(String term, int page, Response<HrpBbhepar5>
response) {
            response.addAll(queryMatches(term, page, 10));
	    response.setHasMore(response.size() == 10);
        }
        
        @Override
        public Collection<HrpBbhepar5> toChoices(Collection<String> ids) {
            ArrayList<HrpBbhepar5> hepar5idlist = new
ArrayList<HrpBbhepar5>();

            Iterator it = hepar5list.iterator();
            while (it.hasNext()) {
                HrpBbhepar5 h = (HrpBbhepar5) it.next();
                hepar5idlist.add(h);
            }
            return hepar5idlist;
        }
    }

.....

It complains that java.lang.Short cannot be cast to
hu.xxx.model.HrpBbhepar5.
Please let me know what  should I do.

thnx., Sandor








--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/select2-localization-questions-tp4651732p4651753.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: select2 localization questions

Posted by Igor Vaynberg <ig...@gmail.com>.
On Tue, Sep 4, 2012 at 10:14 AM, Sandor Feher <sf...@bluesystem.hu> wrote:
>
> Igor Vaynberg-2 wrote
>>
>> On Tue, Sep 4, 2012 at 7:27 AM, Sandor Feher &lt;sfeher@&gt; wrote:
>>> Hi,
>>>
>>> I successfuly created a Select2Choice item in my form. I fill it up from
>>> a
>>> model and everything works fine but the listed choices' display in wrong
>>> codepage. I use utf8 everywhere and have no problems with cp.
>>
>> i believe this was fixed recently in master.
>>
> I use 1.0 from maven repo. Is it possible that 1.0 does not contain that ?

i know for sure that one does not.

-igor


>
>
> Igor Vaynberg-2 wrote
>>
>>> The second one is how to localize select2 messages from select2.js ?
>>> E.g. formatNoMatches,  formatSearching and so one.
>>
>> select2 is localized by you providing those functions with the correct
>> strings. in wicket you can do the same by specifying them in the
>> config object.
>>
>> -igor
>>
>>
> Stupid I was. Figured out meanwhile.. Sorry.
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/select2-localization-questions-tp4651732p4651741.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
>

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


Re: select2 localization questions

Posted by Sandor Feher <sf...@bluesystem.hu>.
Igor Vaynberg-2 wrote
> 
> On Tue, Sep 4, 2012 at 7:27 AM, Sandor Feher &lt;sfeher@&gt; wrote:
>> Hi,
>>
>> I successfuly created a Select2Choice item in my form. I fill it up from
>> a
>> model and everything works fine but the listed choices' display in wrong
>> codepage. I use utf8 everywhere and have no problems with cp.
> 
> i believe this was fixed recently in master.
> 
I use 1.0 from maven repo. Is it possible that 1.0 does not contain that ?


Igor Vaynberg-2 wrote
> 
>> The second one is how to localize select2 messages from select2.js ?
>> E.g. formatNoMatches,  formatSearching and so one.
> 
> select2 is localized by you providing those functions with the correct
> strings. in wicket you can do the same by specifying them in the
> config object.
> 
> -igor
> 
> 
Stupid I was. Figured out meanwhile.. Sorry.




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/select2-localization-questions-tp4651732p4651741.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: select2 localization questions

Posted by Igor Vaynberg <ig...@gmail.com>.
On Tue, Sep 4, 2012 at 7:27 AM, Sandor Feher <sf...@bluesystem.hu> wrote:
> Hi,
>
> I successfuly created a Select2Choice item in my form. I fill it up from a
> model and everything works fine but the listed choices' display in wrong
> codepage. I use utf8 everywhere and have no problems with cp.

i believe this was fixed recently in master.

> The second one is how to localize select2 messages from select2.js ?
> E.g. formatNoMatches,  formatSearching and so one.

select2 is localized by you providing those functions with the correct
strings. in wicket you can do the same by specifying them in the
config object.

-igor

>
> thnx., Sandor
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/select2-localization-questions-tp4651732.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
>

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