0

I have the following button

<p:button 
    onclick='javascript:Open_2_Windows_SideBy_Side("#{bean.id}", "#{bean.title}"); return false;' value="View Item">
</p:button>

The javascript basically opens two browser windows, one is a help page with instructions for how to interact with the second window, which is details of the item retrieved with a GET from an external application using the item.id

In the help window, I simply only use #{param.title} but now I want to utilize more of the items properties. I don't want to send more URL parameters.

I tried

    <p:commandButton 
         onclick='javascript:Open_2_Windows_SideBy_Side("#{bean.id}", "#{bean.title}"); 
         return false;' value="View Item">
        <f:setPropertyActionListener value="#{item}" target="#{helpView.selectedItem}" />
    </p:commandButton>

And then in the help.xhtml I put

  #{helpView.selectedItem.title}"

But the selectedItem property is never set in the helpView backing bean.

Is there a way to set the selected item from first view to the help View, or do I need to requery that item in my helpView using the id set using o:viewParam and Converter?

My thought is I've already done the query to the database in the first view when I got a list of items and rather not have to requery the database.

jeff
  • 3,618
  • 9
  • 48
  • 101
  • 1
    Possible duplicate of [How do I process GET query string URL parameters in backing bean on page load?](http://stackoverflow.com/questions/10724428/how-do-i-process-get-query-string-url-parameters-in-backing-bean-on-page-load) – Jorge Campos Apr 24 '17 at 17:26
  • @JorgeCampos, I know how to process GET into backing bean. I already have my object (selected from a list in my datatable). I want to reuse this object into another bean/webpage without have to requery it using GET. But if it has to be GET, then I know how to implement, but to me then I am hitting the database twice just to use the same object – jeff Apr 24 '17 at 18:51
  • What is the scope of your beans? – Jorge Campos Apr 24 '17 at 19:05
  • The scope is @ViewScoped – jeff Apr 24 '17 at 19:09
  • 1
    Then you could just access the prior managedbean from the target managedbean. Something like in this answer here: http://stackoverflow.com/a/9601859/460557 – Jorge Campos Apr 24 '17 at 19:14
  • 1
    Use 'viewAccessScoped' from DeltaSpike here... – Kukeltje Apr 24 '17 at 20:40
  • if you would like to use data in multiple views, use custom/session scoped beans – The Bitman Apr 25 '17 at 22:39
  • Is the query big and resource intensive, or is your user load significant? If the answer to both of those is no and you're set on the two window design then just requery the data; it's probably the simplest code and simple code is usually good code. If you're willing to refactor you can emulate two windows and just use the same view scoped bean. – axemoi Apr 27 '17 at 18:56

1 Answers1

0

Create a form with required values in hidden inputs and bind them to the helpview backing bean and after opening the help window submit the form. This way you will not have to pass them as params and part of the url. You will have the values assigned in the helpview bean after submit and no need for using params. Please see How to submit form to new window? for submit example.

Community
  • 1
  • 1
OTM
  • 656
  • 5
  • 8