<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Conditional Page Rendering in Java Web Frameworks &#8211; Best Practices?</title>
	<atom:link href="http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/</link>
	<description>About Technology in My Life</description>
	<lastBuildDate>Thu, 11 Mar 2010 05:52:37 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: sudha</title>
		<link>http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/comment-page-1/#comment-1860</link>
		<dc:creator>sudha</dc:creator>
		<pubDate>Thu, 14 Aug 2008 18:14:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/#comment-1860</guid>
		<description>i landed up on this page looking for something similar. 

I was looking for some kind of rule engine that would serve up the conditional parts of the code. And rules would have priority to determine from the best to the least fit one. Googling for JSP + rule engine or JSP + drools is not helping so much!</description>
		<content:encoded><![CDATA[<p>i landed up on this page looking for something similar. </p>
<p>I was looking for some kind of rule engine that would serve up the conditional parts of the code. And rules would have priority to determine from the best to the least fit one. Googling for JSP + rule engine or JSP + drools is not helping so much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Thomas</title>
		<link>http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/comment-page-1/#comment-917</link>
		<dc:creator>Peter Thomas</dc:creator>
		<pubDate>Sun, 01 Jun 2008 18:30:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/#comment-917</guid>
		<description>Wicket also has something called an &#039;enclosure&#039; that you could choose to use.  This is a convenience feature designed for those situations where the visibility of a whole section of HTML can be controlled by a single associated component.

This is explained in detail here:

http://www.systemmobile.com/?page_id=253</description>
		<content:encoded><![CDATA[<p>Wicket also has something called an &#8216;enclosure&#8217; that you could choose to use.  This is a convenience feature designed for those situations where the visibility of a whole section of HTML can be controlled by a single associated component.</p>
<p>This is explained in detail here:</p>
<p><a href="http://www.systemmobile.com/?page_id=253" rel="nofollow">http://www.systemmobile.com/?page_id=253</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: karthik</title>
		<link>http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/comment-page-1/#comment-814</link>
		<dc:creator>karthik</dc:creator>
		<pubDate>Mon, 19 May 2008 18:24:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/#comment-814</guid>
		<description>In Wicket, you have 2 options then - Fragments / Panels.
You can use Panel-s if the markup is reusable across several projects/ pages and fragments if you don&#039;t see it being used beyond that page for example.

So you would have a panel (TextFieldPanel) that just encapsulates a input text field.

And you will have another panel (AnotherPanel) that will encapsulate the image and the javascript stuff.
 
And in the page that conditionally renders them , you would now have a &quot;place holder&quot; like so -



and in the backing page, you can have something like this - 

if(someExpr){
 page.add(new TextFieldPanel(&quot;conditional&quot;));
}else{
 page.add(new AnotherPanel(&quot;conditional&quot;));
}

In Wicket, the view is pretty much dumbed out - it is used just for specifying markup/layout and as a result is very clean.</description>
		<content:encoded><![CDATA[<p>In Wicket, you have 2 options then &#8211; Fragments / Panels.<br />
You can use Panel-s if the markup is reusable across several projects/ pages and fragments if you don&#8217;t see it being used beyond that page for example.</p>
<p>So you would have a panel (TextFieldPanel) that just encapsulates a input text field.</p>
<p>And you will have another panel (AnotherPanel) that will encapsulate the image and the javascript stuff.</p>
<p>And in the page that conditionally renders them , you would now have a &#8220;place holder&#8221; like so -</p>
<p>and in the backing page, you can have something like this &#8211; </p>
<p>if(someExpr){<br />
 page.add(new TextFieldPanel(&#8221;conditional&#8221;));<br />
}else{<br />
 page.add(new AnotherPanel(&#8221;conditional&#8221;));<br />
}</p>
<p>In Wicket, the view is pretty much dumbed out &#8211; it is used just for specifying markup/layout and as a result is very clean.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: polesen</title>
		<link>http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/comment-page-1/#comment-797</link>
		<dc:creator>polesen</dc:creator>
		<pubDate>Sat, 17 May 2008 21:09:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/#comment-797</guid>
		<description>@svenmeier: Interesting. But that is *very* simple example (setting hidden true or false on an input field). How about rendering totally different, in case of true or false. Like this:

&lt;pre&gt;&lt;code&gt;
&lt;% if (someExpr) { %&gt;
  &lt;input type=&quot;text&quot;..../&gt;
  &lt;p&gt;and a lot of other stuff here&lt;/p&gt;
&lt;% } else { %&gt;
  &lt;img src=.../&gt;
  and then maybe a bunch of javascript here, 
  just to make the example a bit more interesting
&lt;% } end { %&gt;
&lt;/code&gt;&lt;/pre&gt;

Note: I am just dreaming up this example as I go, but how would the view (and backing bean) look like in wicket, to support this?</description>
		<content:encoded><![CDATA[<p>@svenmeier: Interesting. But that is *very* simple example (setting hidden true or false on an input field). How about rendering totally different, in case of true or false. Like this:</p>
<pre><code>
&lt;% if (someExpr) { %&gt;
  &lt;input type="text"..../&gt;
  &lt;p&gt;and a lot of other stuff here&lt;/p&gt;
&lt;% } else { %&gt;
  &lt;img src=.../&gt;
  and then maybe a bunch of javascript here,
  just to make the example a bit more interesting
&lt;% } end { %&gt;
</code></pre>
<p>Note: I am just dreaming up this example as I go, but how would the view (and backing bean) look like in wicket, to support this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: polesen</title>
		<link>http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/comment-page-1/#comment-796</link>
		<dc:creator>polesen</dc:creator>
		<pubDate>Sat, 17 May 2008 21:03:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/#comment-796</guid>
		<description>@Claus:

Interesting idea with a DisplayAttribute, though, as you mention, there gotta be a lot more extra work in this solution. Maybe something that lends itself better to code-generation. I was wondering: If running on Java5, one could annotate properties on the form-bean, to mark them visibile, hidden, disabled, etc. It would remove the need for extra methods. Just a thought.

I would fear this solution to not be able to cope with all the special cases, that large applications with complex views need. Like rendering the same property totally different, in case of true or false on some domain-specific expression (aka: Not just a role check). But I don&#039;t know, maybe it could be put into the tag-rendering stuff you mention.

Thanks for the input.</description>
		<content:encoded><![CDATA[<p>@Claus:</p>
<p>Interesting idea with a DisplayAttribute, though, as you mention, there gotta be a lot more extra work in this solution. Maybe something that lends itself better to code-generation. I was wondering: If running on Java5, one could annotate properties on the form-bean, to mark them visibile, hidden, disabled, etc. It would remove the need for extra methods. Just a thought.</p>
<p>I would fear this solution to not be able to cope with all the special cases, that large applications with complex views need. Like rendering the same property totally different, in case of true or false on some domain-specific expression (aka: Not just a role check). But I don&#8217;t know, maybe it could be put into the tag-rendering stuff you mention.</p>
<p>Thanks for the input.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: svenmeier</title>
		<link>http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/comment-page-1/#comment-794</link>
		<dc:creator>svenmeier</dc:creator>
		<pubDate>Sat, 17 May 2008 20:25:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/#comment-794</guid>
		<description>The view (this time escaped):

&lt;input type=&quot;text&quot; wicket:id=&quot;onlyIfSomeExpr&quot;/&gt;</description>
		<content:encoded><![CDATA[<p>The view (this time escaped):</p>
<p>&lt;input type=&#8221;text&#8221; wicket:id=&#8221;onlyIfSomeExpr&#8221;/&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: svenmeier</title>
		<link>http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/comment-page-1/#comment-793</link>
		<dc:creator>svenmeier</dc:creator>
		<pubDate>Sat, 17 May 2008 20:23:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/#comment-793</guid>
		<description>Well, in Wicket the view stays simple all the time:



In your Java code you can do anything you want:

add(new TextField(&quot;onlyIfSomeExpr&quot;) {
  public boolean isVisible() {
    // someExpr
  }
});</description>
		<content:encoded><![CDATA[<p>Well, in Wicket the view stays simple all the time:</p>
<p>In your Java code you can do anything you want:</p>
<p>add(new TextField(&#8221;onlyIfSomeExpr&#8221;) {<br />
  public boolean isVisible() {<br />
    // someExpr<br />
  }<br />
});</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Claus Myglegaard Vagner</title>
		<link>http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/comment-page-1/#comment-792</link>
		<dc:creator>Claus Myglegaard Vagner</dc:creator>
		<pubDate>Sat, 17 May 2008 20:02:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/2008/05/17/conditional-page-rendering-in-java-web-frameworks-best-practices/#comment-792</guid>
		<description>Hi Per,

I&#039;am not aware of any library out there, but I would like to share some experience from a project I have been working on.  Well the question in action is  - how do we avoid cluttering the view pages with all the conditional expressions needed by all applications?

This solution builds on the principle that all form fields in your view pages should have an accosiated DisplayAttribute in a backing code class. The value of the DisplayAttribute should determine if the current field should be read-only, hidden, disabled and so on...

When the page renders each field have some logic which can draw the html e.g. a taglib or a component. This logic should read the display attribute of the field and act upon it.

This gives you a clean JSP page where all the dynamic about the different conditions a determined by the value of the DisplayAttribute and the logic associated to act upon it.

When to update/change the DisplayAttribute? Well, this could be when the page is about to render. Here you need at method to hook into where all the view business logic could reside and change the DisplayAttribute accordingly. In Tapestry we had some possibilities with the PageBeginRenderListener interface.

On my project this was implemented with the Struts framework where every field on the Struts ActionForm had a DisplayAttribute. Of cource you need more code in your form class, but it would otherwise have been on the JSP page. It was possible to override a specific method for every form where view business logic could be coded and all the taglibs on the JSP page was implemented to adhere to the DisplayAttribute. 

Well this was one way of doing it and maybe not an easy one because you need to have a DisplayAttribute for all fields and the logic to draw the fields needs the value of the DisplayAttribute and should act accordingly. All of this should of course be supported by a web framework :-)

This can give you a better overview of the JSP, but you can also loose the overview since all the logic about when to display what is separated away.

What do you think? To cumbersome or?

Regards Claus</description>
		<content:encoded><![CDATA[<p>Hi Per,</p>
<p>I&#8217;am not aware of any library out there, but I would like to share some experience from a project I have been working on.  Well the question in action is  &#8211; how do we avoid cluttering the view pages with all the conditional expressions needed by all applications?</p>
<p>This solution builds on the principle that all form fields in your view pages should have an accosiated DisplayAttribute in a backing code class. The value of the DisplayAttribute should determine if the current field should be read-only, hidden, disabled and so on&#8230;</p>
<p>When the page renders each field have some logic which can draw the html e.g. a taglib or a component. This logic should read the display attribute of the field and act upon it.</p>
<p>This gives you a clean JSP page where all the dynamic about the different conditions a determined by the value of the DisplayAttribute and the logic associated to act upon it.</p>
<p>When to update/change the DisplayAttribute? Well, this could be when the page is about to render. Here you need at method to hook into where all the view business logic could reside and change the DisplayAttribute accordingly. In Tapestry we had some possibilities with the PageBeginRenderListener interface.</p>
<p>On my project this was implemented with the Struts framework where every field on the Struts ActionForm had a DisplayAttribute. Of cource you need more code in your form class, but it would otherwise have been on the JSP page. It was possible to override a specific method for every form where view business logic could be coded and all the taglibs on the JSP page was implemented to adhere to the DisplayAttribute. </p>
<p>Well this was one way of doing it and maybe not an easy one because you need to have a DisplayAttribute for all fields and the logic to draw the fields needs the value of the DisplayAttribute and should act accordingly. All of this should of course be supported by a web framework <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>This can give you a better overview of the JSP, but you can also loose the overview since all the logic about when to display what is separated away.</p>
<p>What do you think? To cumbersome or?</p>
<p>Regards Claus</p>
]]></content:encoded>
	</item>
</channel>
</rss>
