Re: quick page model question

2011-01-04 Thread Jeremy Thomerson
On Tue, Jan 4, 2011 at 2:10 PM, gnugrf  wrote:

>
> Thanks a million man!
>
> I wasn't calling super(model) and after figuring out how to attach sources
> (which I hadn't known about), I was able to see that the page model was
> being detached and refreshed.


Great!


> The labels on the page aren't updating, but
> I'm assuming I need to provide each component with dynamic models e.g
> propertymodels referencing the page model.
>

Yes.


> You saved me weeks of searching and I can't tell you how much I appreciate
> the time you took helping me.
>

No worries.   Glad it worked out.

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*


Re: quick page model question

2011-01-04 Thread gnugrf

Thanks a million man!

I wasn't calling super(model) and after figuring out how to attach sources
(which I hadn't known about), I was able to see that the page model was
being detached and refreshed. The labels on the page aren't updating, but
I'm assuming I need to provide each component with dynamic models e.g
propertymodels referencing the page model. 

You saved me weeks of searching and I can't tell you how much I appreciate
the time you took helping me. 
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/quick-page-model-question-tp3172678p3174289.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: quick page model question

2011-01-04 Thread Jeremy Thomerson
On Tue, Jan 4, 2011 at 10:28 AM, gnugrf  wrote:

>
> Jeremy thanks for your patience, I have a couple of questions about your
> replies.
>
> 1. If my constructors for the page are
> public ManageClientPage(long id){this(new ClientLDM(id));}
>public ManageClientPage(IModel client) { ///code here}
>
> and the page is being called using ... ManageclientPage(clientId) isn't the
> second constructor setting the page model? Previously I was making an
> explicit call to setDefaultModel(), but it seemed to have the same
> functionality, and I thought setting the model through the constructor
> seemed cleaner.
>

Only if you are calling super(model) within that constructor.

2. How do I set a breakpoint on a method inherited from an abstract class? I
> would assume setting it on the detach method in the abstract class. Isnt
> this going to make execution stop every time ANY ldm detaches?
>

If you open the Wicket source (hopefully you have it attached to your IDE),
you can set the breakpoint in LDM's detach.  As you mention, this will make
it stop for EVERY LDM.  But, if you only have a couple on the page, no big
deal.  If you have a lot, override onDetach in your custom model and put the
breakpoint there.


-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*


Re: quick page model question

2011-01-04 Thread gnugrf

Jeremy thanks for your patience, I have a couple of questions about your
replies. 

1. If my constructors for the page are 
public ManageClientPage(long id){this(new ClientLDM(id));}
public ManageClientPage(IModel client) { ///code here} 

and the page is being called using ... ManageclientPage(clientId) isn't the
second constructor setting the page model? Previously I was making an
explicit call to setDefaultModel(), but it seemed to have the same
functionality, and I thought setting the model through the constructor
seemed cleaner.

2. How do I set a breakpoint on a method inherited from an abstract class? I
would assume setting it on the detach method in the abstract class. Isnt
this going to make execution stop every time ANY ldm detaches?




-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/quick-page-model-question-tp3172678p3173857.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: quick page model question

2011-01-04 Thread Jeremy Thomerson
On Tue, Jan 4, 2011 at 9:18 AM, gnugrf  wrote:
>
> I set a breakpoint within the load() and when the page first gets constructed
> I am able to watch the code get executed. When I refresh, the listview on
> the page (which uses a different LDM) does get called again, however this
> LDM (the model for the page) does not.
>
> I think I probably copied most of this from the examples I've found. I read
> detach happens automatically and that I didn't need to override it, is that
> true?

Detach happens automatically if your model is used as the default
model in any component in your page hierarchy.  So, if this is your
page model, it should be detached automatically.  Put a breakpoint in
LDM detach to verify.

> public class ClientLDM extends LoadableDetachableModel
> {
>   �...@springbean
>    ClientService clientService;
>
>    private final long id;
>
>    public ClientLDM(Client c){this(c.getId());}
>
>    public ClientLDM(long id){
>
>        InjectorHolder.getInjector().inject(this);
>        if (id == 0)
>        {
>            throw new IllegalArgumentException();

I know this isn't related to your question, but you should always
throw useful exceptions - with a useful (to the developer) message.

>        }
>        this.id = id;
>    }
>
>   �...@override
>    public int hashCode()
>    {
>        return Long.valueOf(id).hashCode();
>    }
>
>   �...@override
>    public boolean equals(final Object obj)
>    {
>        if (obj == this)
>        {
>            return true;
>        }
>        else if (obj == null)
>        {
>            return false;
>        }
>        else if (obj instanceof ClientLDM)
>        {
>            ClientLDM other = (ClientLDM)obj;
>            return other.id == id;
>        }
>        return false;
>    }
>
>   �...@override
>    protected Client load()
>    {
>
>        Client client = new Client();
>        try {
>          client = clientService.loadClient("web", id);
>        } catch (InvalidClientException e) {
>        e.printStackTrace();
>        }
>        return client;
>    }
>
>
> }

See what the breakpoint in detach tells you.  Make sure you're using
the model as the default model in some component.  Then send us the
entire code for your page if you can't figure it out.

-- 
Jeremy Thomerson
http://wickettraining.com
Need a CMS for Wicket?  Use Brix! http://brixcms.org

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



Re: quick page model question

2011-01-04 Thread gnugrf

I set a breakpoint within the load() and when the page first gets constructed
I am able to watch the code get executed. When I refresh, the listview on
the page (which uses a different LDM) does get called again, however this
LDM (the model for the page) does not.

I think I probably copied most of this from the examples I've found. I read
detach happens automatically and that I didn't need to override it, is that
true?

public class ClientLDM extends LoadableDetachableModel
{
@SpringBean
ClientService clientService;

private final long id;

public ClientLDM(Client c){this(c.getId());}

public ClientLDM(long id){

InjectorHolder.getInjector().inject(this);
if (id == 0)
{
throw new IllegalArgumentException();
}
this.id = id;
}

@Override
public int hashCode()
{
return Long.valueOf(id).hashCode();
}

@Override
public boolean equals(final Object obj)
{
if (obj == this)
{
return true;
}
else if (obj == null)
{
return false;
}
else if (obj instanceof ClientLDM)
{
ClientLDM other = (ClientLDM)obj;
return other.id == id;
}
return false;
}

@Override
protected Client load()
{

Client client = new Client();
try {
  client = clientService.loadClient("web", id);
} catch (InvalidClientException e) {
e.printStackTrace();
}
return client;
}


}
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/quick-page-model-question-tp3172678p3173721.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: quick page model question

2011-01-03 Thread Jeremy Thomerson
On Mon, Jan 3, 2011 at 5:00 PM, gnugrf  wrote:
>
> I'm pretty much a noob, even though I've been slowly working on a project for
> about a year so bear with me. I've read "understanding models" a couple
> dozen times already and lifecycle, requestcycle, etc. and did a fair amount
> of slogging through the mailing list for old posts about "page resfresh"
> "page model", etc. and didnt find anything to help me, so forgive my
> stupidity..
>
> How would i refresh it in the loadabledetachable model (how would the model
> know when the page has been refreshed)

In a LDM, load() will be called every time that getObject is called
*and* the object has not already been loaded.  There is a transient
instance field in LDM that holds the object once it is loaded.  At the
end of every request, detach() is called, which nulls out that
transient object reference.  This means that on the next page view
(new request), getObject will presumably be called by something that
is using your page model, and in turn, load() will be called again.
You don't have to do anything to "refresh" your model.

If that is not happening, please show the LDM code you have.

-- 
Jeremy Thomerson
http://wickettraining.com
Need a CMS for Wicket?  Use Brix! http://brixcms.org

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



Re: quick page model question

2011-01-03 Thread gnugrf

I'm pretty much a noob, even though I've been slowly working on a project for
about a year so bear with me. I've read "understanding models" a couple
dozen times already and lifecycle, requestcycle, etc. and did a fair amount
of slogging through the mailing list for old posts about "page resfresh"
"page model", etc. and didnt find anything to help me, so forgive my
stupidity..

How would i refresh it in the loadabledetachable model (how would the model
know when the page has been refreshed)

onbeforerender makes sense to me since its an event, i suppose you are
saying to override that method and i could force the page to reload the
model there. i saw in the javadocs it warned to call super.onbeforerender at
the end.

is there any advantage to either direction?

also as a sanity check my constructors are -->

public ManageClientPage(long id){this(new ClientLDM(id));}
public ManageClientPage(IModel client) { ///code here}

and its being called using id.
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/quick-page-model-question-tp3172678p3172797.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: quick page model question

2011-01-03 Thread Martin Makundi
You can refresh it in your loadabledetachable model or
onbeforerender.. there are some alternatives.

**
Martin

2011/1/3 gnugrf :
>
> how do you get the page model to refresh when a user presses "reload" or F5?
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/quick-page-model-question-tp3172678p3172678.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

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



quick page model question

2011-01-03 Thread gnugrf

how do you get the page model to refresh when a user presses "reload" or F5?
-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/quick-page-model-question-tp3172678p3172678.html
Sent from the Users forum mailing list archive at Nabble.com.

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