Avoid The Jsf Prerenderview On Crud Edit Mode

Long fourth dimension agone I learned that the usual approach inwards CRUD is list, add, edit, delete. And correct right away I'm implementing the same affair inwards JavaEE6, Glassfish, JSF 2.1, Primefaces. So what I did was:

1.) Create a unmarried backing edible bean that volition handgrip all the operations.

2.) Create a listing page, where add, edit in addition to delete activity is defined. Delete create non require a page but a backing edible bean activity that volition delete the selected object in addition to refresh the page.

3.) Create an edit page that volition live homecoming when the edit activity is clicked on the listing page. Now this edit page must submit the id of the object. And the id must live converted to object. See the code below.

On the listing page nosotros bring a Definition for the edit action:
<p:column headerText="#{msgs['common.update']}" style="width:50px">  <p:commandButton action="update.xhtml" ajax="false"   icon="ui-icon-pencil">         <f:param name="marketingCode" value="#{code.id}"></f:param>  </p:commandButton> </p:column> 

On the update.xhtml, nosotros bring to define a preRenderView event:
<f:metadata>  <f:param name="dummy"></f:param>  <f:viewParam name="marketingCode"   value="#{marketingCodeBean.marketingCode}"   converter="#{marketingCodeConverter}" />  <f:event listener="#{marketingCodeBean.preRenderViewEdit()}"   type="preRenderView" /> </f:metadata> 

Define the effect on the backing bean:
public void preRenderViewEdit() {  log.debug("preRenderViewEdit");  if (marketingCode == null) {   marketingCode = novel MarketingCode();  } } 

And lastly nosotros bring a salve push clit on the edit page. But alongside this approach nosotros volition run into the famous occupation alongside the preRenderView effect beingness called when the salve activity is invoke in addition to validation failed. Or when a partial cast is submitted. So you lot see nosotros bring to implement several checks on the preRender effect method only to acquire away alongside it. My uncomplicated solution, that fits my requirement is to laid upwards a backing edible bean belongings within the edit activity definition. So inwards my instance it'll be:
<p:commandButton action="update.xhtml" ajax="false"       icon="ui-icon-pencil">  <f:setPropertyActionListener   target="#{marketingCodeBean.marketingCode}" value="#{code}"></f:setPropertyActionListener> </p:commandButton> 

And that solves my occupation of transferring the id of the selected object from listing page to update page.
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.