This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSF and the fly likes How to load a bean for an Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to load a bean for an "edit.jsf" page?" Watch "How to load a bean for an "edit.jsf" page?" New topic
Author

How to load a bean for an "edit.jsf" page?

Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
I'm attempting to create an edit.jsf page where I pass an ID and have it pre-populate a bean. Can anyone help me in this process? The hyperlink from the main page looks like "edit.jsf?id=12". How can I load my data in order to populate the form fields?
Josh Juneau
Ranch Hand

Joined: Jun 16, 2004
Posts: 86
You should tie an action to the invoking link by using h:commandLInk. Once the link is selected, the action will populate the bean accordingly. You can use the FacesContext from within the backing bean action method in order to obtain the parameter.

I would like to add that this is also a good reason to use a solution like Seam or Spring. In Seam you can set up actions which are invoked when pages are accessed. This can be done within an XML file with no code at all. However, it seems like a commandLInk or commandButton should work fine in your case (from what I know about your issue).


Database Administrator/Application Developer
Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
How can I add a value to the request parameter map that way? I see I can set a value for the command link but that's the value that displays. How can I set a value that doesn't display that I can pull from within that action?
Josh Juneau
Ranch Hand

Joined: Jun 16, 2004
Posts: 86
I think you want to use something like this:

<h:commandLink action="#{tie to action}"> <hutputText value="Click This Link"/> <f:param name="editParameter" value="parameterValue"/> </h:commandLink>

In your bean action you would use something like this:

FacesContext fc = FacesContext.getCurrentInstance();
String value = (String) fc.getExternalContext().getRequestParameterMap().get("editParameter");

I think this would do the trick...however I cannot test it out at this time.

Hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to load a bean for an "edit.jsf" page?
 
Similar Threads
PLEASE HELP????? jsf + form population
How to identify the controls of a online html page
dropdown from database
Repopulating form in struts2
How to prepopulate combo boxes on page startup