users@javaserverfaces.java.net

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?

From: Jason Lee <jason_at_steeplesoft.com>
Date: Thu, 5 Jul 2007 12:58:12 -0500

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_at_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