You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by MattyDE <uf...@gmail.com> on 2010/02/16 11:29:04 UTC
Re: Delegate a Modelchange to the child components. Or using a
ModalWindow for displaying different Models of a specific Type.
Ohkay.. i've found a solution.. but i thinks not simple.. or "wicket"-like i
think... but its the only way to pass the new model to the "known"
propertyModel =/
now iam doing this in UserEdit.java
@Override
protected void onModelChanged() {
final IModel<User> _model = (IModel<User>) this.getDefaultModel();
visitChildren(new IVisitor<Component>() {
@Override
public Object component(Component component) {
PropertyModel<User> cpm =
((PropertyModel<User>)component.getDefaultModel());
PropertyModel<User> newCpm = new PropertyModel<User>(_model.getObject(),
cpm.getPropertyExpression());
//cpm.setObject(_model.getObject());
component.setDefaultModel(newCpm);
component.modelChanging();
return component;
}
});
}
its to dirty i think.. or isn't it?
Thanks for any Help in Advance!
Martin U wrote:
>
> Its not easy to find the right topic, but i will try to explain my problem
> as best as i can.
>
> I want to display an user-detail View (User is an BusinessObject in my
> Application) inside a specific Modal window.
>
>
> So at the rendering of the Site i place an "empty" or dummy UserObject
> inside my UserEdit-Panel and later if the user choose one specific user
> from
> a Table i want to replace this dummy-Model with the clicked-User-Model.
>
> public class UserEdit extends Panel {
>
> /**
> * @param id
> * @param model
> */
>
> private IModel<User> model;
> CompoundPropertyModel<User> cpm;
>
> public UserEdit(String id, IModel<User> _model) {
> super(id, _model);
>
> this.model = _model;
>
> init();
> }
>
> private void init(){
>
> cpm = new
> CompoundPropertyModel<User>(this.getDefaultModelObject());
>
> this.add(new TextField("lastname", cpm.bind("lastName")) );
> }
> }
>
> I dont know if its the right choice to use a cpm ... but i think its the
> proper way right?
>
> The UserEdit is the "content" of my ModalWindow implementation so i bore
> up
> the "show" method with a new Model-Parameter to delegate them to the
> Inside
> Content...
>
> (inside ModelOverlay.class)
>
> public void show(final AjaxRequestTarget target, IModel<T> model)
> {
> if (shown == false)
> {
> getContent().setVisible(true);
> getContent().setDefaultModel(model); // <- my new Line ;o)
> target.addComponent(this);
> target.appendJavascript(getWindowOpenJavascript());
> shown = true;
> }
> }
>
> The Model inside "UserEdit" is changed. But how can i archieve that the
> lastname-Textfield now displays the Value of getLastName() from the new,
> submitted Model?
> In my opinion i tried everything... tried to override the
> "onModelChange"-Event and tryed to set the new Model with an Visitor of
> every childfield... but than i
> lost my "expression" from the CPM and only
> pages.AdminUserPage$User@17eea10is shown inside the Textfield.
>
> Thanks for any help. Am i totally lost.. or am i on the right way and few
> steps before the solution?
>
> I hope you understand my problem... if not so tell me and i will try to
> explain it in another way or even better...
>
>
> Apologise my english, its not my mothers tongue!
>
> - Martin
>
>
--
View this message in context: http://old.nabble.com/Delegate-a-Modelchange-to-the-child-components.-Or-using-a--ModalWindow-for-displaying-different-Models-of-a-specific-Type.-tp27604201p27606240.html
Sent from the Wicket - User 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: Delegate a Modelchange to the child components. Or using a
ModalWindow for displaying different Models of a specific Type.
Posted by MattyDE <uf...@gmail.com>.
Oh my God.. its so easy ... >_<
public class UserEdit extends Panel {
/**
* @param id
* @param model
*/
public UserEdit(String id, CompoundPropertyModel<User> _model) {
super(id, _model);
this.add(new TextField("lastname", _model.bind("lastName")));
this.add(new TextField("firstname", _model.bind("firstName")) );
this.add(new TextField("department", _model.bind("department")) );
}
}
and in ModalWindow.show
public void show(final AjaxRequestTarget target, IModel<T> model)
{
if (shown == false)
{
getContent().setVisible(true);
getContent().setDefaultModelObject(model.getObject()); //<- magic line
target.addComponent(this);
target.appendJavascript(getWindowOpenJavascript());
shown = true;
}
}
Damn!
MattyDE wrote:
>
> Ohkay.. i've found a solution.. but i thinks not simple.. or "wicket"-like
> i think... but its the only way to pass the new model to the "known"
> propertyModel =/
>
> now iam doing this in UserEdit.java
>
> @Override
> protected void onModelChanged() {
> final IModel<User> _model = (IModel<User>) this.getDefaultModel();
>
> visitChildren(new IVisitor<Component>() {
>
> @Override
> public Object component(Component component) {
> PropertyModel<User> cpm =
> ((PropertyModel<User>)component.getDefaultModel());
> PropertyModel<User> newCpm = new
> PropertyModel<User>(_model.getObject(), cpm.getPropertyExpression());
> //cpm.setObject(_model.getObject());
> component.setDefaultModel(newCpm);
>
>
> component.modelChanging();
>
> return component;
> }
> });
>
> }
>
> its to dirty i think.. or isn't it?
>
>
> Thanks for any Help in Advance!
>
>
>
>
> Martin U wrote:
>>
>> Its not easy to find the right topic, but i will try to explain my
>> problem
>> as best as i can.
>>
>> I want to display an user-detail View (User is an BusinessObject in my
>> Application) inside a specific Modal window.
>>
>>
>> So at the rendering of the Site i place an "empty" or dummy UserObject
>> inside my UserEdit-Panel and later if the user choose one specific user
>> from
>> a Table i want to replace this dummy-Model with the clicked-User-Model.
>>
>> public class UserEdit extends Panel {
>>
>> /**
>> * @param id
>> * @param model
>> */
>>
>> private IModel<User> model;
>> CompoundPropertyModel<User> cpm;
>>
>> public UserEdit(String id, IModel<User> _model) {
>> super(id, _model);
>>
>> this.model = _model;
>>
>> init();
>> }
>>
>> private void init(){
>>
>> cpm = new
>> CompoundPropertyModel<User>(this.getDefaultModelObject());
>>
>> this.add(new TextField("lastname", cpm.bind("lastName")) );
>> }
>> }
>>
>> I dont know if its the right choice to use a cpm ... but i think its the
>> proper way right?
>>
>> The UserEdit is the "content" of my ModalWindow implementation so i bore
>> up
>> the "show" method with a new Model-Parameter to delegate them to the
>> Inside
>> Content...
>>
>> (inside ModelOverlay.class)
>>
>> public void show(final AjaxRequestTarget target, IModel<T> model)
>> {
>> if (shown == false)
>> {
>> getContent().setVisible(true);
>> getContent().setDefaultModel(model); // <- my new Line ;o)
>> target.addComponent(this);
>> target.appendJavascript(getWindowOpenJavascript());
>> shown = true;
>> }
>> }
>>
>> The Model inside "UserEdit" is changed. But how can i archieve that the
>> lastname-Textfield now displays the Value of getLastName() from the new,
>> submitted Model?
>> In my opinion i tried everything... tried to override the
>> "onModelChange"-Event and tryed to set the new Model with an Visitor of
>> every childfield... but than i
>> lost my "expression" from the CPM and only
>> pages.AdminUserPage$User@17eea10is shown inside the Textfield.
>>
>> Thanks for any help. Am i totally lost.. or am i on the right way and few
>> steps before the solution?
>>
>> I hope you understand my problem... if not so tell me and i will try to
>> explain it in another way or even better...
>>
>>
>> Apologise my english, its not my mothers tongue!
>>
>> - Martin
>>
>>
>
>
--
View this message in context: http://old.nabble.com/Delegate-a-Modelchange-to-the-child-components.-Or-using-a--ModalWindow-for-displaying-different-Models-of-a-specific-Type.-tp27604201p27607064.html
Sent from the Wicket - User 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