CRUD, ManyToOne, Sorting

99 views
Skip to first unread message

Илья Скорик

unread,
Oct 19, 2011, 5:43:36 AM10/19/11
to play-framework
I have this code in Article Model:

@ManyToOne(fetch = FetchType.EAGER)
public Category category;

In one Article can be only one Category. And when editing Article
properties in CRUD, I see a list of possible Categories. But this list
is not sorted alphabetically! How I can sort it?

Mikael

unread,
Oct 19, 2011, 7:08:09 AM10/19/11
to play-fr...@googlegroups.com
Have you tried something like this in your Article:

@OrderBy("categoryName DESC") 
List<Category> categories

Илья Скорик

unread,
Oct 19, 2011, 8:01:12 AM10/19/11
to play-fr...@googlegroups.com
I can't do that. Category is a single object, not list.

2011/10/19 Mikael <mikael...@gmail.com>:


> Have you tried something like this in your Article:
> @OrderBy("categoryName DESC")
> List<Category> categories
>

> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/BC0uinvpBtAJ.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.
>

--
С уважением, Илья Скорик
Yours faithfully, Ilya Skorik

Илья Скорик

unread,
Oct 19, 2011, 10:53:37 AM10/19/11
to play-fr...@googlegroups.com
Solution:

In relationField tag add:

%{
sortedArray = _field.choices
try {
Collections.sort(sortedArray);
} catch (Exception ex) {
}
%}

And change:

%{ _field.choices.each() { }%

to

%{ sortedArray.each() { }%

Than add Comparable interface to Model

19 октября 2011 г. 16:01 пользователь Илья Скорик <il...@skorik.me> написал:

Aishwarya Singhal

unread,
Oct 19, 2011, 12:30:57 PM10/19/11
to play-framework
i think i would prefer "order by" on the database query vis-a-vis
sorting in application code. can you perhaps do a HQL ?

On Oct 19, 7:53 pm, Илья Скорик <i...@skorik.me> wrote:
> Solution:
>
> In relationField tag add:
>
> %{
>         sortedArray = _field.choices
>         try {
>             Collections.sort(sortedArray);
>         } catch (Exception ex) {
>         }
> %}
>
> And change:
>
> %{ _field.choices.each() { }%
>
> to
>
> %{ sortedArray.each() { }%
>
> Than add Comparable interface to Model
>
> 19 ÏËÔÑÂÒÑ 2011šÇ. 16:01 ÐÏÌØÚÏ×ÁÔÅÌØ éÌØÑ óËÏÒÉË <i...@skorik.me> ÎÁÐÉÓÁÌ:
>
>
>
>
>
>
>
>
>
> > I can't do that. Category is a single object, not list.
>
> > 2011/10/19 Mikael <mikael.bel...@gmail.com>:
> >> Have you tried something like this in your Article:
> >> @OrderBy("categoryName DESC")
> >> List<Category> categories
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "play-framework" group.
> >> To view this discussion on the web visit
> >>https://groups.google.com/d/msg/play-framework/-/BC0uinvpBtAJ.
> >> To post to this group, send email to play-fr...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> play-framewor...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/play-framework?hl=en.
>
> > --
> > ó Õ×ÁÖÅÎÉÅÍ, éÌØÑ óËÏÒÉË
> > Yours faithfully, Ilya Skorik
>
> --
> ó Õ×ÁÖÅÎÉÅÍ, éÌØÑ óËÏÒÉË
> Yours faithfully, Ilya Skorik

Илья Скорик

unread,
Oct 19, 2011, 5:20:51 PM10/19/11
to play-fr...@googlegroups.com
This is CRUD module, where possible values for fields selected
dynamically. In this case by Choises interface:

public List<Object> getChoices() {
return property.choices.list();
}

I found no way to pass parameters to this method without significant
modifications to the CRUD and Play code.

2011/10/19 Aishwarya Singhal <asing...@gmail.com>:

--

Reply all
Reply to author
Forward
0 new messages