2

I have 2 pages.

  1. Add Page for add a new item Add Page
  2. List Page for show all items List Page

When I click on Edit icon on List Page, I want to show selected data on Add Page for editing and update its data if I click on save button. How to do this?

punny
  • 403
  • 5
  • 16

1 Answers1

5

Pass the row identifier as a parameter to the button. For example, assuming that #{item} is the currently iterated item and has some Long id property which uniquely identifies the item.

<p:button icon="ui-icon-pencil" outcome="edit.xhtml">
    <f:param name="id" value="#{item.id}" />
</p:button>

In the target page, edit.xhtml, you can use <f:viewParam> to convert, validate and set it as a bean property.

<f:metadata>
    <f:viewParam name="id" value="#{bean.item}" required="true" converter="itemConverter" />
</f:metadata>

...

<p:inputText value="#{bean.item.name}" />
<p:inputText value="#{bean.item.shortName}" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • BalusC, please suggest me. I should handle add and update event in one page (Add Page) or separate into 2 page add event in Add Page and update event in Edit Page – punny Jun 05 '12 at 04:03