You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Martin Ahrer <ma...@gmx.at> on 2007/10/19 20:11:23 UTC
[trinidad] what is the proper lifecycle phase for populating a
I'm trying to implement a simple query by example view (qbe.jsp) containing
* a form with the query criteria,
* a table with query results
* a form for editing a selected table row
<tr:panelFormLayout rendered="#{formController.entity==null}">
...the query form
<tr:inputText value="#{qbeController.example.criteria}"/>
</tr:panelFormLayout>
<tr:table value="#{qbeController.model}" var="object"
rows="5" width="200" rendered="#{formController.entity==null}">
...the query result
...
<tr:column sortable="true" headerText="criteria">
<tr:commandLink action="#{qbeController.select}">
<tr:outputText value="#{object.type}" />
</tr:commandLink>
</tr:column>
</tr:table>
<tr:panelFormLayout rendered="#{formController.entity!=null}">
<tr:subform>
...the editor form
...
</tr:subform>
</tr:panelFormLayout>
In the most simple implementation the table is populated by a getModel()
method (#{qbeController.model}).
protected DataModel model = new ListDataModel(Collections.EMPTY_LIST);
@Override
public DataModel getModel() {
model.setWrappedData(service.queryByExample(example));
return model;
}
As the page is going through the JSF lifecycle the getModel() method is
called multiple times resulting in multiple database hits. The database hits
are unnecessary, it should be sufficient to query the database once.
The query should be performed after the UPDATE_MODEL_VALUES phase (i.e after
the values from the query form have been applied to the backing bean ->
#{qbeController.example.criteria} ). This is the earlies t phase where it
makes sense to perform the query!
So I was trying to do some optimization to avoid this. Using the JSF 1.2
<f:view> afterPhase/beforePhase method bindings I tried to perform the
actual database query...
public void beforePhase(PhaseEvent event) {
if (event.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES)) {
System.out.println();
}
System.out.println("before " + event.getPhaseId());
if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
if (model.getWrappedData() == Collections.EMPTY_LIST) {
model.setWrappedData(service.queryByExample(example));
}
}
}
public void afterPhase(PhaseEvent event) {
System.out.println("after " + event.getPhaseId());
if (event.getPhaseId().equals(PhaseId.UPDATE_MODEL_VALUES)) {
if (model.getWrappedData() == Collections.EMPTY_LIST) {
model.setWrappedData(service.queryByExample(example));
}
}
}
protected DataModel model = new ListDataModel(Collections.EMPTY_LIST);
@Override
public DataModel getModel() {
// model.setWrappedData(getCrudService().findByExample(example));
return model;
}
The query result is correct! But the table dows not allow to click a row and
call the row editor! Seems that the table is missing something if no rows
are available during the APPLY_REQUEST_VALUES phase
Ok next, I try to do the query before the APPLY_REQUEST_VALUES phase ->
selecting a table row works but the query result is not correct as the query
criteria has not yet been applied to the backing bean
(#{qbeController.example.criteria}).
Hmmm, interested in your ideas about this... thx
--
View this message in context: http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13300085
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [trinidad] what is the proper lifecycle phase for populating a
Posted by Martin Ahrer <ma...@gmx.at>.
Ok seems this is justabout how JSF works. I found another interessing
discusssion and thought it would fit in here just in case others experience
similar problems:
http://forum.java.sun.com/thread.jspa?threadID=5116147
--Martin
Andrew Robinson-5 wrote:
>
> It *should* hit the database twice, unless you use a
> conversation-scoped bean (see sandbox, or seam for this type of
> scope).
>
> The components have to access their model data during decode so they
> can properly iterate over the data and decode any actions from the
> client. For data tables, they are iterated over for every lifecycle
> phase. If the table never did this, you would never have any actions
> or updates to components inside tables, iterators, trees, etc.
>
> If you need the data to stick around, and is serializable, use the
> t:saveState component. This way the data is not reloaded for your
> decode/validate/update phases. You would then reload the data after
> your action changes something
>
> -Andrew
>
> On 10/22/07, Martin Ahrer <ma...@gmx.at> wrote:
>>
>> The seam factory annotation still won't do it - it only takes care that
>> data
>> is prepared only once when it is requested first time (See also
>> http://www.ibm.com/developerworks/web/library/j-seam1/index.html Factory
>> components).
>>
>> In the case that I have described, JSF would request data for the table
>> the
>> first time in the APPLY_REQUEST_VALUES phase - BUT it (here it would be
>> your
>> createModel() method) can't retrieve the right data as the query criteria
>> form values have not yet been transferred to the backing bean it is bound
>> to!
>> Next JSF would request data during the RENDER_REPONSE phase. NOW the
>> right
>> data can be retrieved using the criteria properties that have been
>> applied
>> in the UPDATE_MODEL_VALUES phase.
>>
>> So JSF forced me to hit the database twice, BUT skipping the first
>> database
>> by only allowing database access during the RENDER_RESPONSE phase causes
>> the
>> table component not to work properly (can't click a row ... I have tried
>> this with the dataTable tag from JSF core as well)
>>
>> --Thanks Martin
>>
>>
>>
>> Andrew Robinson-5 wrote:
>> >
>> > Seam's injection with factory support would work for you I would
>> believe.
>> >
>> > <tr:dataTable value="#{mymodel}" ...>
>> >
>> > @Name("doesntMatter")
>> > public class Whatever {
>> >
>> > @In(required=false) @Out(required=false)
>> > private DataModel mymodel;
>> >
>> > @Factory("mymodel")
>> > public DataModel createModel() {
>> > ... load the model here
>> > }
>> > // for programmatic access:
>> > public DataModel getDataModel() {
>> > if (mymodel == null) {
>> > mymodel = createModel();
>> > }
>> > return mymodel;
>> > }
>> > }
>> >
>> > This would force #{mymodel} to be lazy loaded as needed and backing
>> > beans could use "getDataModel"
>> >
>> > You could then also have a on-load function to load this data too if
>> you
>> > want.
>> >
>> > -Andrew
>> >
>> >
>> > On 10/20/07, Martin Ahrer <ma...@gmx.at> wrote:
>> >>
>> >> I'm already using request scope to keep the managed bean qbeController
>> >> (this
>> >> is the one providing the DataModel) so that data is refreshed every
>> time
>> >> the
>> >> page is refreshed.
>> >>
>> >> With using the JSF 1.2 <f:view> beforePhase and afterPhase method
>> >> bindings
>> >> I already try to load data at a very specific phase. I know about
>> >> jsf-comp,
>> >> shale (does not work with JSF 1.2) and seam, this is almost the same
>> >> solution just different tags or annotations to control the phase and
>> when
>> >> to
>> >> invoke a specific method. I don't think they would do the trick here!
>> >> Correct me if I should be wrong!
>> >>
>> >> May be I did not state it clearly enough, the problems that I'm
>> fighting
>> >> are
>> >> a result from restricting data loading to a specific phase. Especially
>> >> delaying data loading to before RENDER_RESPONSE causes the Trinidad
>> table
>> >> not to allow me to click a row and perform a selection method. It
>> simply
>> >> would not create a request! I don't know if this is a Trinidad problem
>> or
>> >> if
>> >> this is a general issue that results from the JSF life-cycle. As I
>> move
>> >> data
>> >> loading to the earlier APPLY_REQUEST_VALUES phase the Trinidad table
>> >> works
>> >> BUT data loading can't be performed properly because the backing bean
>> has
>> >> not yet been refreshed with the query criteria form input :(
>> >>
>> >>
>> >>
>> >> Andrew Robinson-5 wrote:
>> >> >
>> >> > Typically, what I have seen is to store the data in a request scoped
>> >> > member variable. This is used with "if not loaded, load, otherwise
>> use
>> >> > current instance" paradigm.
>> >> >
>> >> > There are 3 libraries that I am aware of that also provide on-load
>> >> > functionality, so that you can load the data before rendering (thus
>> >> > making error handling easier):
>> >> >
>> >> > * jsf-comp on-load
>> >> > * Seam
>> >> > * Shale
>> >> >
>> >> > The simplest way is to store you model directly on the request
>> context
>> >> > from the external request.
>> >> >
>> >> > -Andrew
>> >> >
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13308254
>> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13339401
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13370588
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [trinidad] what is the proper lifecycle phase for populating a
Posted by Andrew Robinson <an...@gmail.com>.
It *should* hit the database twice, unless you use a
conversation-scoped bean (see sandbox, or seam for this type of
scope).
The components have to access their model data during decode so they
can properly iterate over the data and decode any actions from the
client. For data tables, they are iterated over for every lifecycle
phase. If the table never did this, you would never have any actions
or updates to components inside tables, iterators, trees, etc.
If you need the data to stick around, and is serializable, use the
t:saveState component. This way the data is not reloaded for your
decode/validate/update phases. You would then reload the data after
your action changes something
-Andrew
On 10/22/07, Martin Ahrer <ma...@gmx.at> wrote:
>
> The seam factory annotation still won't do it - it only takes care that data
> is prepared only once when it is requested first time (See also
> http://www.ibm.com/developerworks/web/library/j-seam1/index.html Factory
> components).
>
> In the case that I have described, JSF would request data for the table the
> first time in the APPLY_REQUEST_VALUES phase - BUT it (here it would be your
> createModel() method) can't retrieve the right data as the query criteria
> form values have not yet been transferred to the backing bean it is bound
> to!
> Next JSF would request data during the RENDER_REPONSE phase. NOW the right
> data can be retrieved using the criteria properties that have been applied
> in the UPDATE_MODEL_VALUES phase.
>
> So JSF forced me to hit the database twice, BUT skipping the first database
> by only allowing database access during the RENDER_RESPONSE phase causes the
> table component not to work properly (can't click a row ... I have tried
> this with the dataTable tag from JSF core as well)
>
> --Thanks Martin
>
>
>
> Andrew Robinson-5 wrote:
> >
> > Seam's injection with factory support would work for you I would believe.
> >
> > <tr:dataTable value="#{mymodel}" ...>
> >
> > @Name("doesntMatter")
> > public class Whatever {
> >
> > @In(required=false) @Out(required=false)
> > private DataModel mymodel;
> >
> > @Factory("mymodel")
> > public DataModel createModel() {
> > ... load the model here
> > }
> > // for programmatic access:
> > public DataModel getDataModel() {
> > if (mymodel == null) {
> > mymodel = createModel();
> > }
> > return mymodel;
> > }
> > }
> >
> > This would force #{mymodel} to be lazy loaded as needed and backing
> > beans could use "getDataModel"
> >
> > You could then also have a on-load function to load this data too if you
> > want.
> >
> > -Andrew
> >
> >
> > On 10/20/07, Martin Ahrer <ma...@gmx.at> wrote:
> >>
> >> I'm already using request scope to keep the managed bean qbeController
> >> (this
> >> is the one providing the DataModel) so that data is refreshed every time
> >> the
> >> page is refreshed.
> >>
> >> With using the JSF 1.2 <f:view> beforePhase and afterPhase method
> >> bindings
> >> I already try to load data at a very specific phase. I know about
> >> jsf-comp,
> >> shale (does not work with JSF 1.2) and seam, this is almost the same
> >> solution just different tags or annotations to control the phase and when
> >> to
> >> invoke a specific method. I don't think they would do the trick here!
> >> Correct me if I should be wrong!
> >>
> >> May be I did not state it clearly enough, the problems that I'm fighting
> >> are
> >> a result from restricting data loading to a specific phase. Especially
> >> delaying data loading to before RENDER_RESPONSE causes the Trinidad table
> >> not to allow me to click a row and perform a selection method. It simply
> >> would not create a request! I don't know if this is a Trinidad problem or
> >> if
> >> this is a general issue that results from the JSF life-cycle. As I move
> >> data
> >> loading to the earlier APPLY_REQUEST_VALUES phase the Trinidad table
> >> works
> >> BUT data loading can't be performed properly because the backing bean has
> >> not yet been refreshed with the query criteria form input :(
> >>
> >>
> >>
> >> Andrew Robinson-5 wrote:
> >> >
> >> > Typically, what I have seen is to store the data in a request scoped
> >> > member variable. This is used with "if not loaded, load, otherwise use
> >> > current instance" paradigm.
> >> >
> >> > There are 3 libraries that I am aware of that also provide on-load
> >> > functionality, so that you can load the data before rendering (thus
> >> > making error handling easier):
> >> >
> >> > * jsf-comp on-load
> >> > * Seam
> >> > * Shale
> >> >
> >> > The simplest way is to store you model directly on the request context
> >> > from the external request.
> >> >
> >> > -Andrew
> >> >
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13308254
> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context: http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13339401
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
Re: [trinidad] what is the proper lifecycle phase for populating a
Posted by Martin Ahrer <ma...@gmx.at>.
The seam factory annotation still won't do it - it only takes care that data
is prepared only once when it is requested first time (See also
http://www.ibm.com/developerworks/web/library/j-seam1/index.html Factory
components).
In the case that I have described, JSF would request data for the table the
first time in the APPLY_REQUEST_VALUES phase - BUT it (here it would be your
createModel() method) can't retrieve the right data as the query criteria
form values have not yet been transferred to the backing bean it is bound
to!
Next JSF would request data during the RENDER_REPONSE phase. NOW the right
data can be retrieved using the criteria properties that have been applied
in the UPDATE_MODEL_VALUES phase.
So JSF forced me to hit the database twice, BUT skipping the first database
by only allowing database access during the RENDER_RESPONSE phase causes the
table component not to work properly (can't click a row ... I have tried
this with the dataTable tag from JSF core as well)
--Thanks Martin
Andrew Robinson-5 wrote:
>
> Seam's injection with factory support would work for you I would believe.
>
> <tr:dataTable value="#{mymodel}" ...>
>
> @Name("doesntMatter")
> public class Whatever {
>
> @In(required=false) @Out(required=false)
> private DataModel mymodel;
>
> @Factory("mymodel")
> public DataModel createModel() {
> ... load the model here
> }
> // for programmatic access:
> public DataModel getDataModel() {
> if (mymodel == null) {
> mymodel = createModel();
> }
> return mymodel;
> }
> }
>
> This would force #{mymodel} to be lazy loaded as needed and backing
> beans could use "getDataModel"
>
> You could then also have a on-load function to load this data too if you
> want.
>
> -Andrew
>
>
> On 10/20/07, Martin Ahrer <ma...@gmx.at> wrote:
>>
>> I'm already using request scope to keep the managed bean qbeController
>> (this
>> is the one providing the DataModel) so that data is refreshed every time
>> the
>> page is refreshed.
>>
>> With using the JSF 1.2 <f:view> beforePhase and afterPhase method
>> bindings
>> I already try to load data at a very specific phase. I know about
>> jsf-comp,
>> shale (does not work with JSF 1.2) and seam, this is almost the same
>> solution just different tags or annotations to control the phase and when
>> to
>> invoke a specific method. I don't think they would do the trick here!
>> Correct me if I should be wrong!
>>
>> May be I did not state it clearly enough, the problems that I'm fighting
>> are
>> a result from restricting data loading to a specific phase. Especially
>> delaying data loading to before RENDER_RESPONSE causes the Trinidad table
>> not to allow me to click a row and perform a selection method. It simply
>> would not create a request! I don't know if this is a Trinidad problem or
>> if
>> this is a general issue that results from the JSF life-cycle. As I move
>> data
>> loading to the earlier APPLY_REQUEST_VALUES phase the Trinidad table
>> works
>> BUT data loading can't be performed properly because the backing bean has
>> not yet been refreshed with the query criteria form input :(
>>
>>
>>
>> Andrew Robinson-5 wrote:
>> >
>> > Typically, what I have seen is to store the data in a request scoped
>> > member variable. This is used with "if not loaded, load, otherwise use
>> > current instance" paradigm.
>> >
>> > There are 3 libraries that I am aware of that also provide on-load
>> > functionality, so that you can load the data before rendering (thus
>> > making error handling easier):
>> >
>> > * jsf-comp on-load
>> > * Seam
>> > * Shale
>> >
>> > The simplest way is to store you model directly on the request context
>> > from the external request.
>> >
>> > -Andrew
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13308254
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13339401
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [trinidad] what is the proper lifecycle phase for populating a
Posted by Andrew Robinson <an...@gmail.com>.
Seam's injection with factory support would work for you I would believe.
<tr:dataTable value="#{mymodel}" ...>
@Name("doesntMatter")
public class Whatever {
@In(required=false) @Out(required=false)
private DataModel mymodel;
@Factory("mymodel")
public DataModel createModel() {
... load the model here
}
// for programmatic access:
public DataModel getDataModel() {
if (mymodel == null) {
mymodel = createModel();
}
return mymodel;
}
}
This would force #{mymodel} to be lazy loaded as needed and backing
beans could use "getDataModel"
You could then also have a on-load function to load this data too if you want.
-Andrew
On 10/20/07, Martin Ahrer <ma...@gmx.at> wrote:
>
> I'm already using request scope to keep the managed bean qbeController (this
> is the one providing the DataModel) so that data is refreshed every time the
> page is refreshed.
>
> With using the JSF 1.2 <f:view> beforePhase and afterPhase method bindings
> I already try to load data at a very specific phase. I know about jsf-comp,
> shale (does not work with JSF 1.2) and seam, this is almost the same
> solution just different tags or annotations to control the phase and when to
> invoke a specific method. I don't think they would do the trick here!
> Correct me if I should be wrong!
>
> May be I did not state it clearly enough, the problems that I'm fighting are
> a result from restricting data loading to a specific phase. Especially
> delaying data loading to before RENDER_RESPONSE causes the Trinidad table
> not to allow me to click a row and perform a selection method. It simply
> would not create a request! I don't know if this is a Trinidad problem or if
> this is a general issue that results from the JSF life-cycle. As I move data
> loading to the earlier APPLY_REQUEST_VALUES phase the Trinidad table works
> BUT data loading can't be performed properly because the backing bean has
> not yet been refreshed with the query criteria form input :(
>
>
>
> Andrew Robinson-5 wrote:
> >
> > Typically, what I have seen is to store the data in a request scoped
> > member variable. This is used with "if not loaded, load, otherwise use
> > current instance" paradigm.
> >
> > There are 3 libraries that I am aware of that also provide on-load
> > functionality, so that you can load the data before rendering (thus
> > making error handling easier):
> >
> > * jsf-comp on-load
> > * Seam
> > * Shale
> >
> > The simplest way is to store you model directly on the request context
> > from the external request.
> >
> > -Andrew
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13308254
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
Re: [trinidad] what is the proper lifecycle phase for populating a
Posted by Martin Ahrer <ma...@gmx.at>.
I'm already using request scope to keep the managed bean qbeController (this
is the one providing the DataModel) so that data is refreshed every time the
page is refreshed.
With using the JSF 1.2 <f:view> beforePhase and afterPhase method bindings
I already try to load data at a very specific phase. I know about jsf-comp,
shale (does not work with JSF 1.2) and seam, this is almost the same
solution just different tags or annotations to control the phase and when to
invoke a specific method. I don't think they would do the trick here!
Correct me if I should be wrong!
May be I did not state it clearly enough, the problems that I'm fighting are
a result from restricting data loading to a specific phase. Especially
delaying data loading to before RENDER_RESPONSE causes the Trinidad table
not to allow me to click a row and perform a selection method. It simply
would not create a request! I don't know if this is a Trinidad problem or if
this is a general issue that results from the JSF life-cycle. As I move data
loading to the earlier APPLY_REQUEST_VALUES phase the Trinidad table works
BUT data loading can't be performed properly because the backing bean has
not yet been refreshed with the query criteria form input :(
Andrew Robinson-5 wrote:
>
> Typically, what I have seen is to store the data in a request scoped
> member variable. This is used with "if not loaded, load, otherwise use
> current instance" paradigm.
>
> There are 3 libraries that I am aware of that also provide on-load
> functionality, so that you can load the data before rendering (thus
> making error handling easier):
>
> * jsf-comp on-load
> * Seam
> * Shale
>
> The simplest way is to store you model directly on the request context
> from the external request.
>
> -Andrew
>
>
>
--
View this message in context: http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13308254
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [trinidad] what is the proper lifecycle phase for populating a
Posted by Andrew Robinson <an...@gmail.com>.
Typically, what I have seen is to store the data in a request scoped
member variable. This is used with "if not loaded, load, otherwise use
current instance" paradigm.
There are 3 libraries that I am aware of that also provide on-load
functionality, so that you can load the data before rendering (thus
making error handling easier):
* jsf-comp on-load
* Seam
* Shale
The simplest way is to store you model directly on the request context
from the external request.
-Andrew
On 10/19/07, Martin Ahrer <ma...@gmx.at> wrote:
>
> I'm trying to implement a simple query by example view (qbe.jsp) containing
> * a form with the query criteria,
> * a table with query results
> * a form for editing a selected table row
>
> <tr:panelFormLayout rendered="#{formController.entity==null}">
> ...the query form
> <tr:inputText value="#{qbeController.example.criteria}"/>
> </tr:panelFormLayout>
>
> <tr:table value="#{qbeController.model}" var="object"
> rows="5" width="200" rendered="#{formController.entity==null}">
> ...the query result
> ...
>
> <tr:column sortable="true" headerText="criteria">
> <tr:commandLink action="#{qbeController.select}">
> <tr:outputText value="#{object.type}" />
> </tr:commandLink>
> </tr:column>
>
> </tr:table>
>
> <tr:panelFormLayout rendered="#{formController.entity!=null}">
> <tr:subform>
> ...the editor form
> ...
> </tr:subform>
> </tr:panelFormLayout>
>
> In the most simple implementation the table is populated by a getModel()
> method (#{qbeController.model}).
>
> protected DataModel model = new ListDataModel(Collections.EMPTY_LIST);
> @Override
> public DataModel getModel() {
> model.setWrappedData(service.queryByExample(example));
> return model;
> }
>
> As the page is going through the JSF lifecycle the getModel() method is
> called multiple times resulting in multiple database hits. The database hits
> are unnecessary, it should be sufficient to query the database once.
> The query should be performed after the UPDATE_MODEL_VALUES phase (i.e after
> the values from the query form have been applied to the backing bean ->
> #{qbeController.example.criteria} ). This is the earlies t phase where it
> makes sense to perform the query!
>
> So I was trying to do some optimization to avoid this. Using the JSF 1.2
> <f:view> afterPhase/beforePhase method bindings I tried to perform the
> actual database query...
>
>
> public void beforePhase(PhaseEvent event) {
> if (event.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES)) {
> System.out.println();
> }
> System.out.println("before " + event.getPhaseId());
> if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
> if (model.getWrappedData() == Collections.EMPTY_LIST) {
> model.setWrappedData(service.queryByExample(example));
> }
> }
> }
>
> public void afterPhase(PhaseEvent event) {
> System.out.println("after " + event.getPhaseId());
> if (event.getPhaseId().equals(PhaseId.UPDATE_MODEL_VALUES)) {
> if (model.getWrappedData() == Collections.EMPTY_LIST) {
> model.setWrappedData(service.queryByExample(example));
> }
> }
> }
>
> protected DataModel model = new ListDataModel(Collections.EMPTY_LIST);
>
> @Override
> public DataModel getModel() {
> // model.setWrappedData(getCrudService().findByExample(example));
> return model;
> }
>
>
> The query result is correct! But the table dows not allow to click a row and
> call the row editor! Seems that the table is missing something if no rows
> are available during the APPLY_REQUEST_VALUES phase
>
> Ok next, I try to do the query before the APPLY_REQUEST_VALUES phase ->
> selecting a table row works but the query result is not correct as the query
> criteria has not yet been applied to the backing bean
> (#{qbeController.example.criteria}).
>
> Hmmm, interested in your ideas about this... thx
> --
> View this message in context: http://www.nabble.com/-trinidad--what-is-the-proper-lifecycle-phase-for-populating-a-%3Ctr%3Atable%3E-tf4654950.html#a13300085
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>