reinit beans

1 view
Skip to first unread message

jbuda

unread,
Nov 11, 2008, 7:37:22 AM11/11/08
to Mach-II for CFML
i have bean that inherits from another one. However, when im trying to
reinit this bean in my xml, like so:

<event-bean name="vacancy" type="focus-
cms.com.focus.beans.extends.Vacancy" reinit="true" />

It is only reinitialising the parent bean properties, and so my values
are not cleared?

Basically, i have a form that when posted, and is successful it
returns to the same page with the form, but with the fields empty.
Below is the example i have in the view

<cfset vacancy = event.getArg('vacancy') />

<input type="text" name="title" id="title" maxlength="100" size="25"
value="#vacancy.getTitle()#" />

Im not sure, whey the propeties are not getting cleared.

Thanks

Peter J. Farrell

unread,
Nov 11, 2008, 2:06:36 PM11/11/08
to mach-ii-for...@googlegroups.com
Are you using redirect with persist? It's probably reiniting for you,
but because of the redirect with persist -- all the original event-args
are there so it's getting repopulated. Also, event-bean only populates
one level -- nested or child beans of a bean are ignored.

It's a little vague what exactly is happening, it would help if you
could share the pertinent event-handlers from the XML.

.pjf

jbuda said the following on 11/11/2008 6:37 AM:

George Murphy

unread,
Nov 12, 2008, 11:56:51 AM11/12/08
to mach-ii-for...@googlegroups.com
I ran into this same problem.  I was only passing 'message' into the persist attribute of the redirect.  Once I passed persist="message,username" I was able to read #event.getUsername()#
Peter, is it okay to pass a comma delimited sting into the persist attribute?
 
Thanks,
 
GM

Peter J. Farrell

unread,
Nov 12, 2008, 1:42:16 PM11/12/08
to mach-ii-for...@googlegroups.com
The "persist" attribute takes a boolean and indicates if a persist should occur.  I think you are referring to the "persistArgs" attribute which indicates which args to persist (and will persist the whole Event if you do not define this attribute).  And yes you are correct if I infer, "persistArgs" takes a comma list.  If you use "persistArgs" (because you want specific event args and not the whole thing), you must also use "persist".  So "persistArgs" is just a modifier on how what data "persist" should well .... persist ;-)

Complete reference here for future reference:
http://greatbiztoolsllc-trac.cvsdude.com/mach-ii/wiki/ConfigFileExplained#redirect

Best,
.Peter


George Murphy said the following on 11/12/2008 10:56 AM:

jbuda

unread,
Nov 16, 2008, 12:12:44 PM11/16/08
to Mach-II for CFML
Hi

Im not trying to redirect or persist arguments...

This is the xml that i have :

<event-handler event="vacancies" access="public">
<notify listener="VacanciesListener" method="getVacancies" />
<event-bean name="vacancy" type="focus-
cms.com.focus.beans.contactExtends.vacancy" reinit="true"/>
<view-page name="vacancies.list" contentArg="layout.content"/>
<view-page name="vacancies.table" contentArg="layout.content"
append="true"/>
<announce event="vacancies.template" copyEventArgs="true"/>
</event-handler>

<event-handler event="process-vacancy" access="public">
<event-bean name="vacancy" type="focus-
cms.com.focus.beans.contactExtends.vacancy"
fields="event_id,title,reference,contact_name,category,location,start_date,information"/
>
<notify listener="VacanciesListener" method="createVacancy"/>
<announce event="vacancies"/>
</event-handler>

The vacancies event display a form that needs to be completed.
When the form is submitted it goes to the 'process-vacancy' event with
the event-bean of vacancy.

The listener processes the bean and then the 'vacancies' event is
announced.

Now, i am assuming that because the vacancy bean is in the event.....
the event bean is reinitialised in the 'vacancies' event, if the bean
already exists... it is overwritten?

Im not sure what im doing wrong so that the bean is emptied/cleared.


On Nov 12, 6:42 pm, "Peter J. Farrell" <pe...@mach-ii.com> wrote:
> The "persist" attribute takes a boolean and indicates if a persist
> should occur. I think you are referring to the "persistArgs" attribute
> which indicates which args to persist (and will persist the whole Event
> if you do not define this attribute). And yes you are correct if I
> infer, "persistArgs" takes a comma list. If you use "persistArgs"
> (because you want specific event args and not the whole thing), you must
> also use "persist". So "persistArgs" is just a modifier on how what
> data "persist" should well .... persist ;-)
>
> Complete reference here for future reference:http://greatbiztoolsllc-trac.cvsdude.com/mach-ii/wiki/ConfigFileExpla...

Peter J. Farrell

unread,
Nov 16, 2008, 1:52:05 PM11/16/08
to mach-ii-for...@googlegroups.com
Jbuda,

Mach-II is reiniting the bean except because the original event args are also in the event still, it is getting repopulate with data. Annouce by default in Xml copies the current event arg into the new event. You also use copyEventArgs="false" but then no args will be in the next event or you could use an event-mapping and announce the event at the end of your listener method and put int the args you want.

The best thing you could do is to redirect at the end of your process event. This is also a good thing because right now the url in the browser will be your process event. Redirecting will also update thr url since a cflocation is occuring.
-----Original Message-----
From: jbuda <Janus...@gmail.com>

Date: Sun, 16 Nov 2008 09:12:44
To: Mach-II for CFML<mach-ii-for...@googlegroups.com>
Subject: [Mach-II] Re: reinit beans

jbuda

unread,
Nov 16, 2008, 3:10:41 PM11/16/08
to Mach-II for CFML
Hi Peter

Correct me if im wrong, surely the reinit=true should be overwriting
the bean with 'vacancy' already inside the event?

Should it not matter if im doing an announce or redirect?

Thanks

Peter J. Farrell

unread,
Nov 16, 2008, 3:18:14 PM11/16/08
to mach-ii-for...@googlegroups.com
jbuda said the following on 11/16/2008 2:10 PM:

> Hi Peter
>
> Correct me if im wrong, surely the reinit=true should be overwriting
> the bean with 'vacancy' already inside the event?
>
Yes, it is reiniting the bean, however remember what event-bean
does...it populates the event-bean for you. Here's the sequence of event.

1. process-vacancy event is announced
2. event-bean is run and populates your vacancy bean with data from the
event (like firstName, lastName, etc.).
3. Notify runs.
4. Announce vacancy (remember Mach-II copies all the current event args
into the new event -- this includes the original event args used to
populate your event-bean)
5. vacancy is announced.
6. event-bean command is run and reinits the bean, but doing what it is
supposed to do -- it tries to populate the bean which it can because the
original event-args are in the event after being copied.

That is why I suggested using <announce event='vacancy'
copyEventArgs="false" /> or redirecting so the browser url is update (my
preference).

.Peter

jbuda

unread,
Nov 16, 2008, 3:30:43 PM11/16/08
to Mach-II for CFML
Makes abit more sense now... so although the bean is being
reinitialised, values still exist in the event so that it attempts a
repopulation?

So, the best thing to do is as you have stated is to do a redirect as
opposed to an announce?

In this instance then, i cannot see how a reinit is going to be useful
if it tried to repopulate the bean if it is already in the event.

Thanks for your help and clearing some problems up

Peter J. Farrell

unread,
Nov 16, 2008, 8:23:11 PM11/16/08
to mach-ii-for...@googlegroups.com
jbuda said the following on 11/16/2008 2:30 PM:

> Makes abit more sense now... so although the bean is being
> reinitialised, values still exist in the event so that it attempts a
> repopulation?
>
Yes, that is exactly what I was saying.

> So, the best thing to do is as you have stated is to do a redirect as
> opposed to an announce?
>
Usually, you need to worry about refreshes from the browser. In your
case, the form post to" process-vacancy" and even though you are
announcing a new event, it does *not* update the URL is the browser.
This is not a probably specific to Mach-II, but how the HTTP works and
by using a redirect -- you are essentially doing a PRG
(post-redirect-get) routine which helps make sure somebody doesn't do a
refresh and then accidentally do a double post. This is also important
so people don't bookmark the "process" event by accident, because in
your case once they do the first post of the form -- the url will be
something like index.cfm?event=process-vacancy.

.pjf

jbuda

unread,
Nov 17, 2008, 4:45:48 AM11/17/08
to Mach-II for CFML
Brilliant.... thanks for your help.
Reply all
Reply to author
Forward
0 new messages