JSF Open new window and display bean data - jsf

I am running JSF 2.0 and the latest version of Primefaces 2.2RC1 I believe. I am trying to create a printer friendly window. When the user clicks on a p:commandLink I want a new window to open and display a xhtml file I have named printView.xhtml.
Now I can get the window working fine using JavaScript window.open but when I open the new window it will not render any values it just displays everything as #{myBean.value}. Does anyone know how to properly open a window and extend the current scope of the application into that window so I can call all of my managed beans properly and display the values etc. etc.

it just displays everything as #{myBean.value}
So, the FacesServlet wasn't been invoked. It is the one responsible for doing the JSF works. You need to ensure that the URL in the window.open() matches the url-pattern of the FacesServlet as definied in web.xml.
If it is for example *.jsf, then you need to open it as follows:
window.open('printView.jsf');

Just an FYI, 2.2.RC1 had some bugs. You'll want version 2.2.RC2.

Related

Is it possible to use PrimeFaces dataTable in IceFaces environment?

I have an application using IceFaces 3.3 (non-EE version) for user interface. I would like to replace some of the pages to PrimeFaces.
As a trivial case, I created a new page with only HTML and PrimeFaces tags on it. There is a sortable and filterable lazy dataTable on the page and nothing else. The table first loads fine but when I initiate a sorting or filtering operation, the entire table disappears.
When I inspect the page, I see IcePush is operating and the IceFaces Bridge is loaded. In case of the above mentioned partial page reload, in the response XML, the dataTable appears within delete tags however, it should be present within update tags instead.
It seems that adding org.icefaces.subtreeDiff=false to web.xml solves the problem.

How can I open a dialog when the page is opened

In one of our page we have a search button that open a search dialog so that the users can search and import some data from a remote system.
Now got I new requirement that this same dialog must be showed every time the page is opened - but only when the page will be used to create a new registry, in the update mode it should be showed only if the user click the button.
I've already tried some things, I can call the dialog by MB using Primefaces engine as below:
RequestContext.getCurrentInstance().execute("dialogArmaBos.show()")
This command Works great for the button case, but I can get it working when the page opens. If I try to use in the PostConstruct nothing happens.
I tried also <f:event type="preRenderView" ... with <f:metadata ... but nothing changes too.
Is there some way to make it?
According to the fabulous PrimeFaces documentation There is a visible attribute. Quote from the docs:
visible false Boolean When enabled, dialog is visible by default.
So simply use an EL in that attribute to have it show on pageload
<p:dialog visible="#{myBean.createMode}"... >
and have a boolean field in that bean that returns true if in creation mode.
For the rest you can show/hide it with the client-side api if needed

External link with jsf or primefaces

I want to pop up a new window when clicking on a link in order to go to an external URL outside my project, let's say www.google.com, problem is that when ever I try to do this using h:link or p:commandLink the outcome is searched on my project pages, and of course, I get an error. Is there a way to do this? I don't want to use simple HTML tag because i need to use the property rendered JSF and Pf provides me. Thanks!

Can Primefaces dialog framework display xhtml from an external domain?

when I read about the Primefaces Dialog Framework (DF), which is "used to open an external xhtml page in a dialog", I assumed this meant you could display xhtml from another domain.
If this is the case, how can I give an absolute url to the method...
requestContext.getCurrentInstance().openDialog(outcome)?
These don't seem to resolve.
If this is not the case, then what is the purpose/advantage of the DF? If I can only display xhtml from within the same app, why not just use the declarative <p:dialog> component? It can be put inside a <ui:composition> if you want to reuse a dialog from multiple pages, for instance.
OpenDialog enables the page author to open an xhtml referenced via a JSF navigation outcome in a dialog, the options are the configuration attributes for dialog like modal, draggable and finally the optional params are the view params to pass parameters to the dialog.
Actually the PrimeFaces blog entry referring to that means to use an internal application view outcome for the dialog to refer to. That bounds the path to your application JSF navigation cases.
Then what's the advantage of the dialog framework? I would say, bringing you the ability to specify the outcome and the dialog attributes at runtime. Let's say you have a car table, where you open a detail dialog when user clicks on one row. Suposing you need to display different content depending on car's branch, it would be easy to control what is going to be rendered inside the dialog:
String outcome = "dialogs/genericCar";
if (car.getBranch.equals("Ferrari")){
outcome = "dialogs/ferrariCar";
}
else if (car.getBranch.equals("Aston Martin")){
outcome = "dialogs/astonCar";
}
RequestContext.getCurrentInstance().openDialog(outcome);
Doing that would be so clean an straight forwarded. Otherwise with the classing p:dialog tag you're limited to a single dialog with conditional rendering inside depending on the content you want to display.
The chance of being able to change the dialog attributes depending on what you want to render seems interesting too.
See also:
PrimeFaces Dialog Framework
Blog entry

add the code for a widget (widget.xhtml) once but use it twice in same webpage, possible ? How?

I have a widget in my application that I need to display at two places(once in main page body and once through dialog box). Currently its code has been added twice in the page. Now I was thinking, If there was a way I could just include it only once and show the same instance in the dialog box, as in the main page body.
Can you suggest a way for this?
I'm Using:-
JSF 2.0 with Facelets
Primefaces 3.0 M3 Snapshot
JSF 2 has exactly the feature you want: it's called composite components. I bascially allows you to write a bunch of Facelet code into a file and use it just like any other JSF component, pass parameters to it, etc.

Resources