Posts

Showing posts with the label jsf

How to include rowspan information with h:dataTable

There is a well known limitation in the h:dataTable component of JSF's RI 1.2 (Mojarra) that you cannot set the rowspan attribute in any way. Recently I needed such a feature and here is what I did... Step one : First you need to make the TableRenderer (com.sun.faces.renderkit.html_basic) work with the rowspan attribute. To do this, you need to create a new renderer that extends TableRenderer and overrides the renderRow() method. Next you copy the default implementation and after the line: writer.startElement("td", column); You insert : writer.writeAttribute("rowspan", rowspan, null); Voila, you have inserted your rowspan value for the current cell. Of course it is not yet evaluated so you need to think of the best way to calculate the rowspan in your case. Before that have a look at the final code (some other fixes included) I came up with for renderRow(): TableMetaInfo info = getMetaInfo(context, table); info.newRow(); int columnIndex = 0; ...

Optional actionListener for h:commandButton

Here is an implementation of the needed tag handler: public final class ActionListenerHandler extends TagHandler { private final static Class[] ACTION_LISTENER_SIG = new Class[]{ActionEvent.class}; private final TagAttribute value; public ActionListenerHandler(TagConfig config) { super(config); this.value = this.getRequiredAttribute("value"); } /* * (non-Javadoc) * * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext, * javax.faces.component.UIComponent) */ public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, ELException { if (parent instanceof ActionSource2) { if (ComponentSupport.isNew(parent)) { ((ActionSource2) parent).addActionListener(new MethodExpressionActionListener( value.getMethodExpression(ctx, null, ACTION_LISTENER_SIG))); } } else { throw new TagException(thi...

Optional valueChangeListener for h:selectonemenu

Here is an implementation of the needed tag handler: public final class ValueChangeListenerHandler extends TagHandler { private final static Class[] VALUECHANGE_SIG = new Class[] {ValueChangeEvent.class}; private final TagAttribute value; public ValueChangeListenerHandler(TagConfig config) { super(config); value = this.getRequiredAttribute("value"); } /* * (non-Javadoc) * * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext, * javax.faces.component.UIComponent) */ public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, ELException { if (parent instanceof EditableValueHolder) { if (ComponentSupport.isNew(parent)) { ((EditableValueHolder) parent).addValueChangeListener(new MethodExpressionValueChangeListener( value.getMethodExpression(ctx, null, VALUECHANGE_SIG))); } } else { throw new TagException(this.tag, "Parent is not of type EditableVa...