• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic