To start the day off I though I'd share a quick tip using JSF. Say you have a list of messages:
quicktip.Messages:
ITEM_1=First item
ITEM_2=Second item
ITEM_3=Third item
Now, on your JSF page you would like to show one of these messages depending on the ID of the item to display. For example, you might have an list of beans containing items you'd like to display:
quicktip.Item
package quicktip;
public class Item {
/** Unique ID of the item. */
private int id;
/** Number of items. */
private int count;
public Item() {}
...usual getters and setters...
}
So, in your backing bean to the JSF page you have a method that constructs a DataModel containing items (I won't go into those details as it's not very exciting). For the sake of this example the signature of the method is
public DataModel getItems();
Finally we get to the interesting bit, the actual JSF page.
... usual jsf stuff ...
<html>
<f:loadbundle basename="quicktip.Messages" var="msgs" />
<body>
<h:datatable value="#{backingBean.items}" var="item">
<h:column>
<c:set var="key" value="ITEM_#{item.id}" />
<h:outputtext value="#{msgs[key]}" />
</h:column>
<h:column>
<h:outputtext value="#{item.count}" />
</h:column>
</h:dataTable>
</body>
</html>
That's it. So, the real gist of the tip is that you can use the jstl
No comments:
Post a Comment