Jason:
I'm using a PL because I have view logic that depends on the data that
is loaded.
So, Unless I really don't know what I'm talking about - I thought the
method with the PostConstruct annotation in a managed bean was ran only
after all Phase Listeners had past?
In the mean time, I think I found a solution - I wrapped my database
logic that populated the managed bean fields with a condition:
if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
....
}
So, now my log output is:
APPLY_REQUEST_VALUES 2
|#]
PROCESS_VALIDATIONS 3
|#]
UPDATE_MODEL_VALUES 4
|#]
INVOKE_APPLICATION 5
|#]
Test Comment Update <-- user's entered value
|#]
RENDER_RESPONSE 6
|#]
Test Comment Update <-- database value
|#]
As I test this page, it seems to be working, but this probably isn't the
best approach, eh?
--Todd
________________________________
From: Jason Lee [mailto:jason@steeplesoft.com]
Sent: Thursday, July 05, 2007 12:58 PM
To: users@javaserverfaces.dev.java.net
Subject: Re: JSF 1.2_04: How do create a page that loads values from a
database, the user edits the values and saves the values back to the
database, then redisplay the same page with the new values?
Why are you using a PL for that? That sounds like simple page<->managed
bean operation.
public class Foo {
@PostConstruct
public void init() {
// do stuff
}
public String getOneOfManyFormValues() {
// for example
}
public String saveData() {
// update model/persist data
return null; // or ""
}
}
Something like that (coded entirely in my webmail client, so be careful
;)?
On 7/5/07, Todd Patrick <Todd.Patrick@dtn.com> wrote:
JSF 1.2_04
How do create a page that loads values from a database, the user
edits the values and saves the values back to the database, then
redisplay the same page with the new values?
What I am using currently is a f:view beforePhase attribute.
In my managed bean, public void beforePhase(PhaseEvent event)
contains the logic to load the data into the page by setting the managed
beans fields.
Everything seems to work fine, expect the log output is:
APPLY_REQUEST_VALUES 2
|#]
PROCESS_VALIDATIONS 3
|#]
Test Comment <-- database value
|#]
UPDATE_MODEL_VALUES 4
|#]
Test Comment <-- database value
|#]
INVOKE_APPLICATION 5
|#]
Test Comment Update <-- user's entered value
|#]
RENDER_RESPONSE 6
|#]
Test Comment <-- database value again???
|#]
What is happening is my beforePhase method is resetting my
managed bean field back to the previous database value.
I don't understand this. I thought my database column value
would be updated in the INVOKE_APPLICATION phase and the RENDER_RESPONSE
phase would display the new value?
"Why in the heck is it so hard to develop a simple page that
loads values from a database and redisplays the *updated* values in the
same page after the user updates the values through an Action or
ActionListener?"
Thanks,
--Todd
NOTICE: This email message is for the sole use of the intended
recipient(s) and may contain confidential and privileged information.
Any unauthorized use, disclosure or distribution is prohibited. If you
are not the intended recipient, please contact the sender by reply email
and destroy all copies of the original message.
--
Jason Lee, SCJP
Software Architect -- Objectstream, Inc.
JSF RI Dev Team
http://blogs.steeplesoft.com
-----------------------------------------
NOTICE: This email message is for the sole use of the intended
recipient(s) and may contain confidential and privileged
information. Any unauthorized use, disclosure or distribution is
prohibited. If you are not the intended recipient, please contact
the sender by reply email and destroy all copies of the original
message.