You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by myrz <my...@gmail.com> on 2012/04/13 19:23:10 UTC
Manipulate a List into a Panel
Hi !
I want to know what was the best practice with Wicket when I want to
manipulate a Panel which need a List of object.
Today i can do what i'm supposed to do but I think it's so easy to be lost
and apply anti-patterns with Wicket.
A concrete example:
http://apache-wicket.1842946.n4.nabble.com/file/n4555471/OngletAdressePanel.java
OngletAdressePanel.java
and this is how I create my Panel
IModel<List<Adresse>> lesAdressesDeLaCommandeModel = new
AbstractReadOnlyModel<List<Adresse>>() {
private static final long serialVersionUID = 1L;
@Override
public List<Adresse> getObject() {
return adresseService.getLesAdressesDeLaCommande();
}
};
final boolean tabAdresseVisible =
!lesAdressesDeLaCommandeModel.getObject().isEmpty();
Panel ongletAdressePanel = new
OngletAdressePanel("panelAdresse",lesAdressesDeLaCommandeModel,
TYPE_VISION.CONSEILLER);
ongletAdressePanel.setVisible(tabAdresseVisible);
blocClientAdresse.add(ongletAdressePanel);
blocClientAdresse.add(new
WebMarkupContainer("tabAdresseClient").setVisible(tabAdresseVisible));
This code works, but I know it's pretty uggly. Do you have any ideas how
could I improve my code.
And another question do you know what should I do to manipulate the list
into my Panel. Doing something like get the size of the list and decide to
set visible or not a component ?
I ask this question because we can't cast a List :
List<Adress> adresses = (List<Adress>) getDefaultModelObject();
Is there a special model to use to manipulate a list into a Component
different than a Repeater?
Thank you for your help
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Manipulate-a-List-into-a-Panel-tp4555471p4555471.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: Manipulate a List into a Panel
Posted by myrz <my...@gmail.com>.
Thanks for your reply.
I have a better understanding about what i should do to set visibility.
But adresseService is not a "real service" or a database access. Because my
data access layer is a call to a web service. So i call one time a web
service and so I have a cluster object with wich I have to manipulate to
retrieve the rights informations.
Should I still use a AROM or LDM?
Because everytime I call getObject() I will invoke
adresseService.getLesAdressesDeLaCommande().
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Manipulate-a-List-into-a-Panel-tp4555471p4556950.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: Manipulate a List into a Panel
Posted by Sven Meier <sv...@meiers.net>.
For service or database calls you should use a LDM:
final IModel<List<Adresse>> lesAdressesDeLaCommandeModel = new
LoadableDetachableModel<List<Adresse>>() {
@Override
public List<Adresse> load() {
return adresseService.getLesAdressesDeLaCommande();
}
};
#onConfigure() is now the recommended location to alter component
visibility:
Panel ongletAdressePanel = new OngletAdressePanel("panelAdresse",
lesAdressesDeLaCommandeModel, TYPE_VISION.CONSEILLER) {
onConfigure() {
setVisible(!lesAdressesDeLaCommandeModel.getObject().isEmpty());
}
};
blocClientAdresse.add(ongletAdressePanel);
blocClientAdresse.add(new WebMarkupContainer("tabAdresseClient") {
onConfigure() {
setVisible(!lesAdressesDeLaCommandeModel.getObject().isEmpty());
}
});
This has the advantage that the visibility is always up-to-date when the
panel is re-rendered.
Sven
On 04/13/2012 07:23 PM, myrz wrote:
> Hi !
>
> I want to know what was the best practice with Wicket when I want to
> manipulate a Panel which need a List of object.
> Today i can do what i'm supposed to do but I think it's so easy to be lost
> and apply anti-patterns with Wicket.
>
> A concrete example:
> http://apache-wicket.1842946.n4.nabble.com/file/n4555471/OngletAdressePanel.java
> OngletAdressePanel.java
>
> and this is how I create my Panel
>
>
> IModel<List<Adresse>> lesAdressesDeLaCommandeModel = new
> AbstractReadOnlyModel<List<Adresse>>() {
> private static final long serialVersionUID = 1L;
>
> @Override
> public List<Adresse> getObject() {
> return adresseService.getLesAdressesDeLaCommande();
> }
> };
>
> final boolean tabAdresseVisible =
> !lesAdressesDeLaCommandeModel.getObject().isEmpty();
>
> Panel ongletAdressePanel = new
> OngletAdressePanel("panelAdresse",lesAdressesDeLaCommandeModel,
> TYPE_VISION.CONSEILLER);
> ongletAdressePanel.setVisible(tabAdresseVisible);
>
> blocClientAdresse.add(ongletAdressePanel);
> blocClientAdresse.add(new
> WebMarkupContainer("tabAdresseClient").setVisible(tabAdresseVisible));
>
>
> This code works, but I know it's pretty uggly. Do you have any ideas how
> could I improve my code.
>
> And another question do you know what should I do to manipulate the list
> into my Panel. Doing something like get the size of the list and decide to
> set visible or not a component ?
> I ask this question because we can't cast a List :
> List<Adress> adresses = (List<Adress>) getDefaultModelObject();
> Is there a special model to use to manipulate a list into a Component
> different than a Repeater?
>
>
> Thank you for your help
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Manipulate-a-List-into-a-Panel-tp4555471p4555471.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