Comments on: It's a Chameleon! About JSF Pages that change their appearance mid-flight (or: programmatic manipulation of JSF UI Components) https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/ Friends of Oracle and Java Thu, 23 Apr 2015 12:54:46 +0000 hourly 1 http://wordpress.org/?v=4.2 By: Slip https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3237 Fri, 07 Oct 2011 01:05:14 +0000 http://technology.amis.nl/blog/?p=1187#comment-3237 REALLY useful!
I used your techniques to build a page/bean combo that dynamically displays any table in a database, using <h:dataTable>, generated based on the table’s database metadata – sure beats one page per table!

]]>
By: Stewart https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3236 Fri, 26 Oct 2007 16:02:48 +0000 http://technology.amis.nl/blog/?p=1187#comment-3236 In reply to my own comment, I have found that the best point to access the UIPanelGrid is in the setter from the binding. ie, if you have:
then in Bean.java you can have: setThePanel( UIPanel panel) { this.panel = panel; augmentPanel(); }
The panel that is passed in has nothing constructed on it and its id attribute is null, but you can still programmatically add components to it for it to render correctly.
In addition to this, if you have components added in the JSP also, they are preserved and merged with your programmatic additions.
Quite cool, really.
Regards,
Stewart

]]>
By: Stewart https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3235 Thu, 25 Oct 2007 17:24:39 +0000 http://technology.amis.nl/blog/?p=1187#comment-3235 Hi Lucas,
This is an excellent article, and I thank you for writing it.

One curious situation I have, which I have been unable to solve, is that of programmatically creating the initial page.
I have tried various ways of accessing the created components, such as through a bean or PhaseListener.
It appears the page is not constructed at any point up to and including before RENDER_RESPONSE;
however, if I try programmatic manipulation after RENDER_RESPONSE, apparently the page has already been written to the browser,
so it’s there on a refresh, but not that first time.

Anyone have any ideas?

Thanks,

Stewart

]]>
By: Heny https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3234 Tue, 09 Jan 2007 21:26:11 +0000 http://technology.amis.nl/blog/?p=1187#comment-3234 Could you send me or post the source code in zip file?

Thanks!

]]>
By: Jeanne https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3233 Wed, 17 May 2006 20:46:46 +0000 http://technology.amis.nl/blog/?p=1187#comment-3233 Lucas, Could you please expand on what happens after one hits ‘Post your answer’? I am asking because while I am doing something similar and have been able to the ‘value’ of the selectItem but have not been able to successfully utilize getItemLabel. If you needed to access the label portion of the item selected as an ‘Answer’, how would you do it? Thanks, Jeanne

]]>
By: giuseppe https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3232 Tue, 16 May 2006 14:07:53 +0000 http://technology.amis.nl/blog/?p=1187#comment-3232 I was thinking about a printable version or a pdf dowload of the article. I will copy and paste the content of the article. Thanks.

]]>
By: Lucas Jellema https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3231 Tue, 16 May 2006 07:04:56 +0000 http://technology.amis.nl/blog/?p=1187#comment-3231 Giuseppe, I am not entirely sure what you mean. All content is right there on the weblog. I have no Word document to back it up. You can just copy and paste it from the site – same as I would to provide this printable copy (at least if a Word document or something similar is what you are after). Is there anything in particular I can do for you?

]]>
By: giuseppe https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3230 Mon, 15 May 2006 16:52:00 +0000 http://technology.amis.nl/blog/?p=1187#comment-3230 Lucas, nice article as previous that I have seen in this blog. Is it possible to have a printable version of this article? Thanks in advance. Giuseppe

]]>
By: Lucas Jellema https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3229 Fri, 12 May 2006 09:21:51 +0000 http://technology.amis.nl/blog/?p=1187#comment-3229 See for an interesting debate on this article: The Server Side – Thread 40395

]]>
By: Lucas Jellema https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3228 Fri, 12 May 2006 06:51:36 +0000 http://technology.amis.nl/blog/?p=1187#comment-3228 Dmitry,
In this specific example, that would work. However, as I suggest in the article, there may be cases – especially when setting up a questionnaire style application – where the meta-data specifying the page’s look & feel are more maintained in a database and are much more voluminous and contain much more complicated – in part dynamically created – page fragment definitionis. It would be much harder to proactively anticipate al possible pieces of page elements (and their relative sequencing) in a JSP.

I agree that whenever a JSP can get you there with relatively simple (JSTL and EL) logic, it is preferable to defining the UI Components in code. But as soon as the JSP starts to grow fat with lots of if-conditions and repetitions of the same component definitions, resorting to code based run-time manipulation to me is certainly a valuable option.

By the way, how many lines of Servlet code would you need to achieve what this snippet of code does:

UIComponent answer = (HtmlSelectOneRadio)application.createComponent(HtmlSelectOneRadio.COMPONENT_TYPE);
ValueBinding answerBinding = application.createValueBinding(“#{pollPickerBacker.answer}”);
answer.getChildren().add(getAnswerOptionItems());
answer.setId(“answer”);
answer.setValueBinding(“value”, answerBinding);
children.add(answer);

You cannot make that comparison with out.println() too lightly: we are talking 7 lines of code vs. a very substantial number – in the Servlet approach you need to take care of so many things the UI Components in particular and JSF in general does for you.

]]>
By: Dmitry https://technology.amis.nl/2006/05/11/its-a-chamelon-about-jsf-pages-that-change-their-appearance-mid-flight-or-programmatic-manipulation-of-jsf-ui-components/#comment-3227 Thu, 11 May 2006 21:40:46 +0000 http://technology.amis.nl/blog/?p=1187#comment-3227 So, depending on the choice we need to render the different views. And view in this example is actually generated in our Java code. Like old servlets: out.println(…)
Sure it will work, but I prefer to keep code for controls in JSP. It is just much more easy to update. So this condition could be checked in JSP for example:

if (“s”.equalsIgnoreCase(getAnswerStyle()))

Dmitry
http://www.servletsuite.com/

]]>