This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you want to use something like this:

<h:commandLink action="#{tie to action}"> <h:outputText 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic