File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Chris Stewart
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Josh Juneau
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic