Is it possible to create a JSF page from a XML file? For example, i make a XML file containing what components i want to be created and displayed on the jsf page, and on loading, xml is parsed and components are created and showm. Either it is not possible , is there an alternative solution (a better way) to do it?
Related
As all JSPs are generated / translated to Servlets before their execution, is its true for Facelets too?
I am working with JSF 2.0 and Facelets and wanted to see its generated Java Code which might be Servlet.
No, Facelets files are parsed to a XML tree using a SAX parser. The XML tree is stored in the Facelet cache. The XML tree is during view build time turned into an UIComponent tree which is accessible by FacesContext#getViewRoot() (which you can traverse by getChildren() during runtime). The component tree normally generates HTML code by their own encodeXxx() methods or the ones on the associated Renderer, starting with UIViewRoot#encodeAll().
Facelets files do not generate any class files. The XML trees are by default stored in server's memory. Since JSF 2.1 you can however specify a custom FaceletCache implementation by <facelet-cache-factory> in faces-config.xml wherein you can write code to store the XML tree on for example the disk file system (which would be slower, though).
If you use <ui:debug> in the view and open it, then you can see the textual representation of the component tree behind UIViewRoot. See also how to debug JSF/EL
See also:
Why not JSF pages are precompiled (atleast partially) but instead parsed, evaluated each time view is built?
What's the view build time?
Measure the render time of a JSF view after a server request
Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?
Not exactly the same way, it gets cached. But it doesn't generate servlet code.
I generated Entity Classes from database then I generated JSF pages from them but when I click on any show table this message displays 3 times:
Warning this page calls for XML namespaces http://xlmns.jsp.org/jsffacelets declared with prefix ui but no taglibrary exists for that namespace
For UI tags you need to use following tag library.
xmlns:ui="http://java.sun.com/jsf/facelets
Please check following link,
http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/
I am working in C#.Net and Framework 4.0. I am having a aspx and ascx pages. In my ascx, i am generating a XML and binding that XML value to Treeview. These are done in code behind. i am calling this ascx in my aspx page.
My issue is, i am having large volume of XML Data. Because of this, the performance of the page is very slow. I tried with enableviewstate and viewstatemode. But nothing works for me.
Still the viewstate is holding large volume of XML Data. I dont want this XML Data to be in viewstate.
How to fix this.
Atlast, i had done with a temporary fix..Cleared the controls viewstate value in JQuery..This process had be done in submit button onclientclick.
$('#ctl00_ContentPlaceHolder1_TreeView').empty();
And, out side the postback in pageload, i had again generated the XML value
I have a form which one of it's fields is a code and description, also a button for opening a popup window that contains a list of all of the available codes.
when the user double clickes a row from that table i want to set these values to the code and description. - how can this be done?
Another question, I want to create this popup and table to be initialized dynamically - by that i mean that if i have a few forms in my application, when ever i have a field which has a description i want to be able to open this popup and to see the available list for that field. (every field can be from a diffrent table). is it possible to create something like that? if so, how?
Any help will be appritiated,
Thank's In Advance.
Yes, it is possible. Even more, many component libraries have ready to use popup/dialog components, such as RichFaces with <rich:popupPanel> and PrimeFaces with <p:dialog>.
If you do not want to use a component library for some reason, you would need to create a custom component for this which generates basically an absolutely positioned HTML <div> element with a CSS overlay which get shown/hidden by JS on a particular click/action. The HTML/CSS/JS part should be relatively simple if you are familiar with those languages. The JSF part is somewhat hard if you have never created a custom component before, but it should be possible with a composite component as well, so you could also just create one with pure XHTML. The updating/refreshing can just take place by the usual <f:ajax> means.
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.