You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rene Perschon <Ch...@gmx.net> on 2014/02/13 12:44:03 UTC
Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Hi everyone!
I'm currently migrating an application from Glassfish 3.1.1 to TomEE. Now the problem is that this application contains a custom component which was unfortunately coded with hard dependencies on com.sun.faces classes (maven dependency jsf-impl).
Now my question is how can i port this component in such a way that it is independent from any concrete JSF implementation (or at least in such a way that it works with MyFaces).
Here's the component:
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.component.UINamingContainer;
import javax.faces.component.ValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.Converter;
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
import com.sun.faces.renderkit.Attribute;
import com.sun.faces.renderkit.AttributeManager;
import com.sun.faces.renderkit.RenderKitUtils;
import com.sun.faces.renderkit.html_basic.MenuRenderer;
import com.sun.faces.util.RequestStateManager;
import com.sun.faces.util.Util;
/**
* {@inheritDoc}.
*/
public class CustomSelectManyCheckboxListRenderer extends MenuRenderer
{
/** {@inheritDoc}. */
private static final Attribute[] ATTRIBUTES = AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
/** Representing the border string. */
private static final String BORDER = "border";
/** Representing the tr string. */
private static final String TR = "tr";
/** Representing the td string. */
private static final String TD = "td";
/** Representing the label string. */
private static final String LABEL = "label";
/** Representing the newline string. */
private static final String NEWLINE = "\n";
/** Representing the tab string. */
private static final String TAB = "\t";
/** Representing the class string. */
private static final String CLASS = "class";
/** Representing the style string. */
private static final String STYLE = "style";
/** Representing the valign string. */
private static final String VALIGN = "valign";
// ---------------------------------------------------------- Public Methods
@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
{
rendererParamsNotNull(context, component);
if (!shouldEncode(component))
{
return;
}
ResponseWriter writer = context.getResponseWriter();
assert (writer != null);
String alignStr;
Object borderObj;
boolean alignVertical = false;
int border = 0;
if (null != component.getAttributes().get("layout"))
{
alignStr = (String) component.getAttributes().get("layout");
alignVertical = alignStr.equalsIgnoreCase("pageDirection");
}
if (null != component.getAttributes().get(BORDER))
{
borderObj = component.getAttributes().get(BORDER);
border = (Integer) borderObj;
}
Converter converter = null;
if (component instanceof ValueHolder)
{
converter = ((ValueHolder)component).getConverter();
}
renderBeginText(component, border, alignVertical, context, true);
Iterator<SelectItem> items =
RenderKitUtils.getSelectItems(context, component);
Object currentSelections = getCurrentSelectedValues(component);
Object[] submittedValues = getSubmittedSelectedValues(component);
Map<String, Object> attributes = component.getAttributes();
OptionComponentInfo optionInfo =
new OptionComponentInfo((String) attributes.get("disabledClass"),
(String) attributes.get("enabledClass"),
(String) attributes.get("unselectedClass"),
(String) attributes.get("selectedClass"),
Util.componentIsDisabled(component),
isHideNoSelection(component));
int idx = -1;
while (items.hasNext())
{
SelectItem curItem = items.next();
idx++;
// If we come across a group of options, render them as a nested
// table.
if (curItem instanceof SelectItemGroup)
{
// write out the label for the group.
if (curItem.getLabel() != null)
{
if (alignVertical)
{
writer.startElement(TR, component);
}
writer.startElement(TD, component);
writer.writeText(curItem.getLabel(), component, LABEL);
writer.endElement(TD);
if (alignVertical)
{
writer.endElement(TR);
}
}
if (alignVertical)
{
writer.startElement(TR, component);
}
writer.startElement(TD, component);
writer.writeText(NEWLINE, component, null);
renderBeginText(component, 0, alignVertical,
context, false);
// render options of this group.
SelectItem[] itemsArray =
((SelectItemGroup) curItem).getSelectItems();
for (int i = 0; i < itemsArray.length; ++i)
{
renderOption(context,
component,
converter,
itemsArray[i],
currentSelections,
submittedValues,
alignVertical,
i,
optionInfo);
}
renderEndText(component, alignVertical, context);
writer.endElement(TD);
if (alignVertical)
{
writer.endElement(TR);
writer.writeText(NEWLINE, component, null);
}
}
else
{
renderOption(context,
component,
converter,
curItem,
currentSelections,
submittedValues,
alignVertical,
idx,
optionInfo);
}
}
renderEndText(component, alignVertical, context);
}
// ------------------------------------------------------- Protected Methods
/**
* {@inheritDoc}
*/
@Override
protected boolean isBehaviorSource(FacesContext ctx,
String behaviorSourceId,
String componentClientId)
{
if (behaviorSourceId == null)
{
return false;
}
char sepChar = UINamingContainer.getSeparatorChar(ctx);
String actualBehaviorId =
behaviorSourceId.substring(0, behaviorSourceId.lastIndexOf(sepChar));
return (actualBehaviorId.equals(componentClientId));
}
/**
* {@inheritDoc}
*/
protected void renderBeginText(UIComponent component, int border,
boolean alignVertical, FacesContext context,
boolean outerTable) throws IOException
{
ResponseWriter writer = context.getResponseWriter();
assert (writer != null);
writer.startElement("table", component);
if (border != Integer.MIN_VALUE)
{
writer.writeAttribute(BORDER, border, BORDER);
}
// render style and styleclass attribute on the outer table instead of
// rendering it as pass through attribute on every option in the list.
if (outerTable)
{
// render "id" only for outerTable.
if (shouldWriteIdAttribute(component))
{
writeIdAttributeIfNecessary(context, writer, component);
}
String styleClass = (String) component.getAttributes().get(
"styleClass");
String style = (String) component.getAttributes().get(STYLE);
if (styleClass != null)
{
writer.writeAttribute(CLASS, styleClass, CLASS);
}
if (style != null)
{
writer.writeAttribute(STYLE, style, STYLE);
}
}
writer.writeText(NEWLINE, component, null);
if (!alignVertical)
{
writer.writeText(TAB, component, null);
writer.startElement(TR, component);
writer.writeText(NEWLINE, component, null);
}
}
/**
* {@inheritDoc}
*/
protected void renderEndText(UIComponent component,
boolean alignVertical,
FacesContext context) throws IOException
{
ResponseWriter writer = context.getResponseWriter();
assert (writer != null);
if (!alignVertical)
{
writer.writeText(TAB, component, null);
writer.endElement(TR);
writer.writeText(NEWLINE, component, null);
}
writer.endElement("table");
}
/**
* {@inheritDoc}
*/
protected void renderOption(FacesContext context,
UIComponent component,
Converter converter,
SelectItem curItem,
Object currentSelections,
Object[] submittedValues,
boolean alignVertical,
int itemNumber,
OptionComponentInfo optionInfo) throws IOException
{
String valueString = getFormattedValue(context, component,
curItem.getValue(), converter);
Object valuesArray;
Object itemValue;
if (submittedValues != null)
{
valuesArray = submittedValues;
itemValue = valueString;
}
else
{
valuesArray = currentSelections;
itemValue = curItem.getValue();
}
RequestStateManager.set(context,
RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
component);
boolean isSelected = isSelected(context, component, itemValue, valuesArray, converter);
if (optionInfo.isHideNoSelection() &&
curItem.isNoSelectionOption() &&
currentSelections != null &&
!isSelected)
{
return;
}
ResponseWriter writer = context.getResponseWriter();
assert (writer != null);
if (alignVertical)
{
writer.writeText(TAB, component, null);
writer.startElement(TR, component);
writer.writeText(NEWLINE, component, null);
}
writer.startElement(TD, component);
writer.writeAttribute(VALIGN, "top", VALIGN);
writer.writeText(NEWLINE, component, null);
writer.startElement("input", component);
writer.writeAttribute("name", component.getClientId(context),
"clientId");
String idString = component.getClientId(context) +
UINamingContainer.getSeparatorChar(context) +
Integer.toString(itemNumber);
writer.writeAttribute("id", idString, "id");
writer.writeAttribute("value", valueString, "value");
writer.writeAttribute("type", "checkbox", null);
if (isSelected)
{
writer.writeAttribute(getSelectedTextString(), Boolean.TRUE, null);
}
// Don't render the disabled attribute twice if the 'parent'
// component is already marked disabled.
if (!optionInfo.isDisabled())
{
if (curItem.isDisabled())
{
writer.writeAttribute("disabled", true, "disabled");
}
}
// Apply HTML 4.x attributes specified on UISelectMany component to all
// items in the list except styleClass and style which are rendered as
// attributes of outer most table.
RenderKitUtils.renderPassThruAttributes(context,
writer,
component,
ATTRIBUTES,
getNonOnClickSelectBehaviors(component));
RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);
RenderKitUtils.renderSelectOnclick(context, component, true);
writer.endElement("input");
//--------------------------------------------------------
// New stuff for event selecting
//--------------------------------------------------------
writer.endElement(TD);
// starting the label td
writer.startElement(TD, component);
writer.writeAttribute(VALIGN, "top", VALIGN);
writer.writeAttribute("width", "80px", "width");
writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
String itemLabel = curItem.getLabel();
if (itemLabel == null)
{
itemLabel = valueString;
}
writer.writeText(" ", component, null);
writer.startElement(LABEL, component);
writer.writeAttribute("for", component.getClientId() + ":" + itemNumber, "for");
if (!curItem.isEscape())
{
// It seems the ResponseWriter API should
// have a writeText() with a boolean property
// to determine if it content written should
// be escaped or not.
writer.write(itemLabel);
}
else
{
writer.writeText(itemLabel, component, null);
}
writer.endElement(LABEL);
isSelected(context, component, itemValue, valuesArray, converter);
// if (isSelected(context, component, itemValue, valuesArray, converter))
// {
// // selected
// }
// else
// {
// // not selected
// }
writer.endElement(TD);
// starting the description td
writer.startElement(TD, component);
writer.writeAttribute(VALIGN, "top", VALIGN);
writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
String itemLabelDesc = curItem.getDescription();
if (itemLabelDesc == null)
{
itemLabelDesc = "";
}
writer.writeText(" ", component, null);
if (!curItem.isEscape())
{
// It seems the ResponseWriter API should
// have a writeText() with a boolean property
// to determine if it content written should
// be escaped or not.
writer.write(itemLabelDesc);
}
else
{
writer.writeText(itemLabelDesc, component, null);
}
writer.endElement(TD);
//--------------------------------------------------------
// New stuff for event selecting end
//--------------------------------------------------------
writer.writeText(NEWLINE, component, null);
if (alignVertical)
{
writer.writeText(TAB, component, null);
writer.endElement(TR);
writer.writeText(NEWLINE, component, null);
}
}
// ------------------------------------------------- Package Private Methods
/**
* {@inheritDoc}
*/
String getSelectedTextString()
{
return "checked";
}
}
Any help is appreciated!
Thanks!
René
Aw: Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Rene Perschon <Ch...@gmx.net>.
I didn't expect anyone to rewrite that code, i just wanted to present the whole problem :-)
As i said, i'd accept a MyFaces port too, it's just that my shots at a solution were unsuccessful. For example I tried to extend from Tobago's MenuRenderer instead of Mojarra's, but it said that MenuRenderer in Tobago is final, although I'm not sure that that's the correct approach in the first place.
Gesendet: Donnerstag, 13. Februar 2014 um 13:23 Uhr
Von: "Thomas Andraschko" <an...@gmail.com>
An: "MyFaces Discussion" <us...@myfaces.apache.org>
Betreff: Re: Problems with a custom component when migrating from Glassfish(mojarra) to TomEE
I don't think that anyone will port your complete code and give you a
complete solution ;)
The biggest problem is AFAIR that the renderer implementations are not in
the API packages. So you have to rebuild all this functionality without
dependencies to the Impl.
e.g.
Attribute,AttributeManager -> String[] with attribute namens
Move all the utils functions to your own code (Util.componentIsDisabled,
RenderKitUtils.getSelectItems. etc.)
The most code doesn't really depent on the IMPL code.
2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> Hi everyone!
>
> I'm currently migrating an application from Glassfish 3.1.1 to TomEE. Now
> the problem is that this application contains a custom component which was
> unfortunately coded with hard dependencies on com.sun.faces classes (maven
> dependency jsf-impl).
>
> Now my question is how can i port this component in such a way that it is
> independent from any concrete JSF implementation (or at least in such a way
> that it works with MyFaces).
>
> Here's the component:
>
> import java.io.IOException;
> import java.util.Iterator;
> import java.util.Map;
>
> import javax.faces.component.UIComponent;
> import javax.faces.component.UINamingContainer;
> import javax.faces.component.ValueHolder;
> import javax.faces.context.FacesContext;
> import javax.faces.context.ResponseWriter;
> import javax.faces.convert.Converter;
> import javax.faces.model.SelectItem;
> import javax.faces.model.SelectItemGroup;
>
> import com.sun.faces.renderkit.Attribute;
> import com.sun.faces.renderkit.AttributeManager;
> import com.sun.faces.renderkit.RenderKitUtils;
> import com.sun.faces.renderkit.html_basic.MenuRenderer;
> import com.sun.faces.util.RequestStateManager;
> import com.sun.faces.util.Util;
>
> /**
> * {@inheritDoc}.
> */
> public class CustomSelectManyCheckboxListRenderer extends MenuRenderer
> {
> /** {@inheritDoc}. */
> private static final Attribute[] ATTRIBUTES =
> AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> /** Representing the border string. */
> private static final String BORDER = "border";
> /** Representing the tr string. */
> private static final String TR = "tr";
> /** Representing the td string. */
> private static final String TD = "td";
> /** Representing the label string. */
> private static final String LABEL = "label";
> /** Representing the newline string. */
> private static final String NEWLINE = "\n";
> /** Representing the tab string. */
> private static final String TAB = "\t";
> /** Representing the class string. */
> private static final String CLASS = "class";
> /** Representing the style string. */
> private static final String STYLE = "style";
> /** Representing the valign string. */
> private static final String VALIGN = "valign";
>
>
> // ---------------------------------------------------------- Public
> Methods
>
>
> @Override
> public void encodeEnd(FacesContext context, UIComponent component)
> throws IOException
> {
>
> rendererParamsNotNull(context, component);
>
> if (!shouldEncode(component))
> {
> return;
> }
>
> ResponseWriter writer = context.getResponseWriter();
> assert (writer != null);
>
> String alignStr;
> Object borderObj;
> boolean alignVertical = false;
> int border = 0;
>
>
>
> if (null != component.getAttributes().get("layout"))
> {
> alignStr = (String) component.getAttributes().get("layout");
> alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> }
>
> if (null != component.getAttributes().get(BORDER))
> {
> borderObj = component.getAttributes().get(BORDER);
> border = (Integer) borderObj;
> }
>
> Converter converter = null;
> if (component instanceof ValueHolder)
> {
> converter = ((ValueHolder)component).getConverter();
> }
>
> renderBeginText(component, border, alignVertical, context, true);
>
> Iterator<SelectItem> items =
> RenderKitUtils.getSelectItems(context, component);
>
> Object currentSelections = getCurrentSelectedValues(component);
> Object[] submittedValues = getSubmittedSelectedValues(component);
> Map<String, Object> attributes = component.getAttributes();
> OptionComponentInfo optionInfo =
> new OptionComponentInfo((String)
> attributes.get("disabledClass"),
> (String)
> attributes.get("enabledClass"),
> (String)
> attributes.get("unselectedClass"),
> (String)
> attributes.get("selectedClass"),
> Util.componentIsDisabled(component),
> isHideNoSelection(component));
> int idx = -1;
> while (items.hasNext())
> {
> SelectItem curItem = items.next();
> idx++;
> // If we come across a group of options, render them as a
> nested
> // table.
> if (curItem instanceof SelectItemGroup)
> {
> // write out the label for the group.
> if (curItem.getLabel() != null)
> {
> if (alignVertical)
> {
> writer.startElement(TR, component);
> }
> writer.startElement(TD, component);
> writer.writeText(curItem.getLabel(), component, LABEL);
> writer.endElement(TD);
> if (alignVertical)
> {
> writer.endElement(TR);
> }
>
> }
> if (alignVertical)
> {
> writer.startElement(TR, component);
> }
> writer.startElement(TD, component);
> writer.writeText(NEWLINE, component, null);
> renderBeginText(component, 0, alignVertical,
> context, false);
> // render options of this group.
> SelectItem[] itemsArray =
> ((SelectItemGroup) curItem).getSelectItems();
> for (int i = 0; i < itemsArray.length; ++i)
> {
> renderOption(context,
> component,
> converter,
> itemsArray[i],
> currentSelections,
> submittedValues,
> alignVertical,
> i,
> optionInfo);
> }
> renderEndText(component, alignVertical, context);
> writer.endElement(TD);
> if (alignVertical)
> {
> writer.endElement(TR);
> writer.writeText(NEWLINE, component, null);
> }
> }
> else
> {
> renderOption(context,
> component,
> converter,
> curItem,
> currentSelections,
> submittedValues,
> alignVertical,
> idx,
> optionInfo);
> }
> }
>
> renderEndText(component, alignVertical, context);
>
> }
>
> // ------------------------------------------------------- Protected
> Methods
>
>
> /**
> * {@inheritDoc}
> */
> @Override
> protected boolean isBehaviorSource(FacesContext ctx,
> String behaviorSourceId,
> String componentClientId)
> {
>
> if (behaviorSourceId == null)
> {
> return false;
> }
> char sepChar = UINamingContainer.getSeparatorChar(ctx);
> String actualBehaviorId =
> behaviorSourceId.substring(0,
> behaviorSourceId.lastIndexOf(sepChar));
> return (actualBehaviorId.equals(componentClientId));
>
> }
>
> /**
> * {@inheritDoc}
> */
> protected void renderBeginText(UIComponent component, int border,
> boolean alignVertical, FacesContext
> context,
> boolean outerTable) throws IOException
> {
> ResponseWriter writer = context.getResponseWriter();
> assert (writer != null);
>
> writer.startElement("table", component);
> if (border != Integer.MIN_VALUE)
> {
> writer.writeAttribute(BORDER, border, BORDER);
> }
>
> // render style and styleclass attribute on the outer table
> instead of
> // rendering it as pass through attribute on every option in the
> list.
> if (outerTable)
> {
> // render "id" only for outerTable.
> if (shouldWriteIdAttribute(component))
> {
> writeIdAttributeIfNecessary(context, writer, component);
> }
> String styleClass = (String) component.getAttributes().get(
> "styleClass");
> String style = (String) component.getAttributes().get(STYLE);
> if (styleClass != null)
> {
> writer.writeAttribute(CLASS, styleClass, CLASS);
> }
> if (style != null)
> {
> writer.writeAttribute(STYLE, style, STYLE);
> }
> }
> writer.writeText(NEWLINE, component, null);
>
> if (!alignVertical)
> {
> writer.writeText(TAB, component, null);
> writer.startElement(TR, component);
> writer.writeText(NEWLINE, component, null);
> }
>
> }
>
> /**
> * {@inheritDoc}
> */
> protected void renderEndText(UIComponent component,
> boolean alignVertical,
> FacesContext context) throws IOException
> {
>
> ResponseWriter writer = context.getResponseWriter();
> assert (writer != null);
>
> if (!alignVertical)
> {
> writer.writeText(TAB, component, null);
> writer.endElement(TR);
> writer.writeText(NEWLINE, component, null);
> }
> writer.endElement("table");
>
> }
>
> /**
> * {@inheritDoc}
> */
> protected void renderOption(FacesContext context,
> UIComponent component,
> Converter converter,
> SelectItem curItem,
> Object currentSelections,
> Object[] submittedValues,
> boolean alignVertical,
> int itemNumber,
> OptionComponentInfo optionInfo) throws
> IOException
> {
>
> String valueString = getFormattedValue(context, component,
> curItem.getValue(),
> converter);
>
> Object valuesArray;
> Object itemValue;
> if (submittedValues != null)
> {
> valuesArray = submittedValues;
> itemValue = valueString;
> }
> else
> {
> valuesArray = currentSelections;
> itemValue = curItem.getValue();
> }
>
> RequestStateManager.set(context,
>
> RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> component);
>
> boolean isSelected = isSelected(context, component, itemValue,
> valuesArray, converter);
> if (optionInfo.isHideNoSelection() &&
> curItem.isNoSelectionOption() &&
> currentSelections != null &&
> !isSelected)
> {
> return;
> }
>
> ResponseWriter writer = context.getResponseWriter();
> assert (writer != null);
>
> if (alignVertical)
> {
> writer.writeText(TAB, component, null);
> writer.startElement(TR, component);
> writer.writeText(NEWLINE, component, null);
> }
> writer.startElement(TD, component);
> writer.writeAttribute(VALIGN, "top", VALIGN);
> writer.writeText(NEWLINE, component, null);
>
> writer.startElement("input", component);
> writer.writeAttribute("name", component.getClientId(context),
> "clientId");
> String idString = component.getClientId(context) +
> UINamingContainer.getSeparatorChar(context) +
> Integer.toString(itemNumber);
> writer.writeAttribute("id", idString, "id");
>
> writer.writeAttribute("value", valueString, "value");
> writer.writeAttribute("type", "checkbox", null);
>
> if (isSelected)
> {
> writer.writeAttribute(getSelectedTextString(), Boolean.TRUE,
> null);
> }
>
> // Don't render the disabled attribute twice if the 'parent'
> // component is already marked disabled.
> if (!optionInfo.isDisabled())
> {
> if (curItem.isDisabled())
> {
> writer.writeAttribute("disabled", true, "disabled");
> }
> }
>
> // Apply HTML 4.x attributes specified on UISelectMany component
> to all
> // items in the list except styleClass and style which are
> rendered as
> // attributes of outer most table.
> RenderKitUtils.renderPassThruAttributes(context,
> writer,
> component,
> ATTRIBUTES,
>
> getNonOnClickSelectBehaviors(component));
>
> RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> component);
>
> RenderKitUtils.renderSelectOnclick(context, component, true);
>
> writer.endElement("input");
>
> //--------------------------------------------------------
> // New stuff for event selecting
> //--------------------------------------------------------
>
> writer.endElement(TD);
>
> // starting the label td
> writer.startElement(TD, component);
> writer.writeAttribute(VALIGN, "top", VALIGN);
> writer.writeAttribute("width", "80px", "width");
> writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
>
> String itemLabel = curItem.getLabel();
> if (itemLabel == null)
> {
> itemLabel = valueString;
> }
>
> writer.writeText(" ", component, null);
> writer.startElement(LABEL, component);
> writer.writeAttribute("for", component.getClientId() + ":" +
> itemNumber, "for");
> if (!curItem.isEscape())
> {
> // It seems the ResponseWriter API should
> // have a writeText() with a boolean property
> // to determine if it content written should
> // be escaped or not.
> writer.write(itemLabel);
> }
> else
> {
> writer.writeText(itemLabel, component, null);
> }
> writer.endElement(LABEL);
>
> isSelected(context, component, itemValue, valuesArray, converter);
> // if (isSelected(context, component, itemValue, valuesArray,
> converter))
> // {
> // // selected
> // }
> // else
> // {
> // // not selected
> // }
> writer.endElement(TD);
>
> // starting the description td
> writer.startElement(TD, component);
> writer.writeAttribute(VALIGN, "top", VALIGN);
> writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
>
> String itemLabelDesc = curItem.getDescription();
> if (itemLabelDesc == null)
> {
> itemLabelDesc = "";
> }
> writer.writeText(" ", component, null);
> if (!curItem.isEscape())
> {
> // It seems the ResponseWriter API should
> // have a writeText() with a boolean property
> // to determine if it content written should
> // be escaped or not.
> writer.write(itemLabelDesc);
> }
> else
> {
> writer.writeText(itemLabelDesc, component, null);
> }
>
> writer.endElement(TD);
>
> //--------------------------------------------------------
> // New stuff for event selecting end
> //--------------------------------------------------------
>
> writer.writeText(NEWLINE, component, null);
> if (alignVertical)
> {
> writer.writeText(TAB, component, null);
> writer.endElement(TR);
> writer.writeText(NEWLINE, component, null);
> }
> }
>
>
> // ------------------------------------------------- Package Private
> Methods
>
> /**
> * {@inheritDoc}
> */
> String getSelectedTextString()
> {
> return "checked";
> }
> }
>
>
> Any help is appreciated!
> Thanks!
>
> René
>
Aw: Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Rene Perschon <Ch...@gmx.net>.
Agreed, i really don't want to deploy Mojarra to TomEE. Problem is I don't know how to port the Mojarra dependent code to MyFaces. It starts with me not knowing which MyFaces maven dependencies i need to import to "replace" the old imports..
Gesendet: Donnerstag, 13. Februar 2014 um 13:25 Uhr
Von: "Romain Manni-Bucau" <rm...@gmail.com>
An: "MyFaces Discussion" <us...@myfaces.apache.org>
Betreff: Re: Problems with a custom component when migrating from Glassfish(mojarra) to TomEE
in tomee you can also use mojarra but I'd just keep my component
portable with myfaces if possible
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau[http://fr.linkedin.com/in/rmannibucau]
Github: https://github.com/rmannibucau[https://github.com/rmannibucau]
2014-02-13 13:23 GMT+01:00 Thomas Andraschko <an...@gmail.com>:
> I don't think that anyone will port your complete code and give you a
> complete solution ;)
>
> The biggest problem is AFAIR that the renderer implementations are not in
> the API packages. So you have to rebuild all this functionality without
> dependencies to the Impl.
>
> e.g.
> Attribute,AttributeManager -> String[] with attribute namens
> Move all the utils functions to your own code (Util.componentIsDisabled,
> RenderKitUtils.getSelectItems. etc.)
>
> The most code doesn't really depent on the IMPL code.
>
>
> 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
>
>> Hi everyone!
>>
>> I'm currently migrating an application from Glassfish 3.1.1 to TomEE. Now
>> the problem is that this application contains a custom component which was
>> unfortunately coded with hard dependencies on com.sun.faces classes (maven
>> dependency jsf-impl).
>>
>> Now my question is how can i port this component in such a way that it is
>> independent from any concrete JSF implementation (or at least in such a way
>> that it works with MyFaces).
>>
>> Here's the component:
>>
>> import java.io.IOException;
>> import java.util.Iterator;
>> import java.util.Map;
>>
>> import javax.faces.component.UIComponent;
>> import javax.faces.component.UINamingContainer;
>> import javax.faces.component.ValueHolder;
>> import javax.faces.context.FacesContext;
>> import javax.faces.context.ResponseWriter;
>> import javax.faces.convert.Converter;
>> import javax.faces.model.SelectItem;
>> import javax.faces.model.SelectItemGroup;
>>
>> import com.sun.faces.renderkit.Attribute;
>> import com.sun.faces.renderkit.AttributeManager;
>> import com.sun.faces.renderkit.RenderKitUtils;
>> import com.sun.faces.renderkit.html_basic.MenuRenderer;
>> import com.sun.faces.util.RequestStateManager;
>> import com.sun.faces.util.Util;
>>
>> /**
>> * {@inheritDoc}.
>> */
>> public class CustomSelectManyCheckboxListRenderer extends MenuRenderer
>> {
>> /** {@inheritDoc}. */
>> private static final Attribute[] ATTRIBUTES =
>> AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
>> /** Representing the border string. */
>> private static final String BORDER = "border";
>> /** Representing the tr string. */
>> private static final String TR = "tr";
>> /** Representing the td string. */
>> private static final String TD = "td";
>> /** Representing the label string. */
>> private static final String LABEL = "label";
>> /** Representing the newline string. */
>> private static final String NEWLINE = "\n";
>> /** Representing the tab string. */
>> private static final String TAB = "\t";
>> /** Representing the class string. */
>> private static final String CLASS = "class";
>> /** Representing the style string. */
>> private static final String STYLE = "style";
>> /** Representing the valign string. */
>> private static final String VALIGN = "valign";
>>
>>
>> // ---------------------------------------------------------- Public
>> Methods
>>
>>
>> @Override
>> public void encodeEnd(FacesContext context, UIComponent component)
>> throws IOException
>> {
>>
>> rendererParamsNotNull(context, component);
>>
>> if (!shouldEncode(component))
>> {
>> return;
>> }
>>
>> ResponseWriter writer = context.getResponseWriter();
>> assert (writer != null);
>>
>> String alignStr;
>> Object borderObj;
>> boolean alignVertical = false;
>> int border = 0;
>>
>>
>>
>> if (null != component.getAttributes().get("layout"))
>> {
>> alignStr = (String) component.getAttributes().get("layout");
>> alignVertical = alignStr.equalsIgnoreCase("pageDirection");
>> }
>>
>> if (null != component.getAttributes().get(BORDER))
>> {
>> borderObj = component.getAttributes().get(BORDER);
>> border = (Integer) borderObj;
>> }
>>
>> Converter converter = null;
>> if (component instanceof ValueHolder)
>> {
>> converter = ((ValueHolder)component).getConverter();
>> }
>>
>> renderBeginText(component, border, alignVertical, context, true);
>>
>> Iterator<SelectItem> items =
>> RenderKitUtils.getSelectItems(context, component);
>>
>> Object currentSelections = getCurrentSelectedValues(component);
>> Object[] submittedValues = getSubmittedSelectedValues(component);
>> Map<String, Object> attributes = component.getAttributes();
>> OptionComponentInfo optionInfo =
>> new OptionComponentInfo((String)
>> attributes.get("disabledClass"),
>> (String)
>> attributes.get("enabledClass"),
>> (String)
>> attributes.get("unselectedClass"),
>> (String)
>> attributes.get("selectedClass"),
>> Util.componentIsDisabled(component),
>> isHideNoSelection(component));
>> int idx = -1;
>> while (items.hasNext())
>> {
>> SelectItem curItem = items.next();
>> idx++;
>> // If we come across a group of options, render them as a
>> nested
>> // table.
>> if (curItem instanceof SelectItemGroup)
>> {
>> // write out the label for the group.
>> if (curItem.getLabel() != null)
>> {
>> if (alignVertical)
>> {
>> writer.startElement(TR, component);
>> }
>> writer.startElement(TD, component);
>> writer.writeText(curItem.getLabel(), component, LABEL);
>> writer.endElement(TD);
>> if (alignVertical)
>> {
>> writer.endElement(TR);
>> }
>>
>> }
>> if (alignVertical)
>> {
>> writer.startElement(TR, component);
>> }
>> writer.startElement(TD, component);
>> writer.writeText(NEWLINE, component, null);
>> renderBeginText(component, 0, alignVertical,
>> context, false);
>> // render options of this group.
>> SelectItem[] itemsArray =
>> ((SelectItemGroup) curItem).getSelectItems();
>> for (int i = 0; i < itemsArray.length; ++i)
>> {
>> renderOption(context,
>> component,
>> converter,
>> itemsArray[i],
>> currentSelections,
>> submittedValues,
>> alignVertical,
>> i,
>> optionInfo);
>> }
>> renderEndText(component, alignVertical, context);
>> writer.endElement(TD);
>> if (alignVertical)
>> {
>> writer.endElement(TR);
>> writer.writeText(NEWLINE, component, null);
>> }
>> }
>> else
>> {
>> renderOption(context,
>> component,
>> converter,
>> curItem,
>> currentSelections,
>> submittedValues,
>> alignVertical,
>> idx,
>> optionInfo);
>> }
>> }
>>
>> renderEndText(component, alignVertical, context);
>>
>> }
>>
>> // ------------------------------------------------------- Protected
>> Methods
>>
>>
>> /**
>> * {@inheritDoc}
>> */
>> @Override
>> protected boolean isBehaviorSource(FacesContext ctx,
>> String behaviorSourceId,
>> String componentClientId)
>> {
>>
>> if (behaviorSourceId == null)
>> {
>> return false;
>> }
>> char sepChar = UINamingContainer.getSeparatorChar(ctx);
>> String actualBehaviorId =
>> behaviorSourceId.substring(0,
>> behaviorSourceId.lastIndexOf(sepChar));
>> return (actualBehaviorId.equals(componentClientId));
>>
>> }
>>
>> /**
>> * {@inheritDoc}
>> */
>> protected void renderBeginText(UIComponent component, int border,
>> boolean alignVertical, FacesContext
>> context,
>> boolean outerTable) throws IOException
>> {
>> ResponseWriter writer = context.getResponseWriter();
>> assert (writer != null);
>>
>> writer.startElement("table", component);
>> if (border != Integer.MIN_VALUE)
>> {
>> writer.writeAttribute(BORDER, border, BORDER);
>> }
>>
>> // render style and styleclass attribute on the outer table
>> instead of
>> // rendering it as pass through attribute on every option in the
>> list.
>> if (outerTable)
>> {
>> // render "id" only for outerTable.
>> if (shouldWriteIdAttribute(component))
>> {
>> writeIdAttributeIfNecessary(context, writer, component);
>> }
>> String styleClass = (String) component.getAttributes().get(
>> "styleClass");
>> String style = (String) component.getAttributes().get(STYLE);
>> if (styleClass != null)
>> {
>> writer.writeAttribute(CLASS, styleClass, CLASS);
>> }
>> if (style != null)
>> {
>> writer.writeAttribute(STYLE, style, STYLE);
>> }
>> }
>> writer.writeText(NEWLINE, component, null);
>>
>> if (!alignVertical)
>> {
>> writer.writeText(TAB, component, null);
>> writer.startElement(TR, component);
>> writer.writeText(NEWLINE, component, null);
>> }
>>
>> }
>>
>> /**
>> * {@inheritDoc}
>> */
>> protected void renderEndText(UIComponent component,
>> boolean alignVertical,
>> FacesContext context) throws IOException
>> {
>>
>> ResponseWriter writer = context.getResponseWriter();
>> assert (writer != null);
>>
>> if (!alignVertical)
>> {
>> writer.writeText(TAB, component, null);
>> writer.endElement(TR);
>> writer.writeText(NEWLINE, component, null);
>> }
>> writer.endElement("table");
>>
>> }
>>
>> /**
>> * {@inheritDoc}
>> */
>> protected void renderOption(FacesContext context,
>> UIComponent component,
>> Converter converter,
>> SelectItem curItem,
>> Object currentSelections,
>> Object[] submittedValues,
>> boolean alignVertical,
>> int itemNumber,
>> OptionComponentInfo optionInfo) throws
>> IOException
>> {
>>
>> String valueString = getFormattedValue(context, component,
>> curItem.getValue(),
>> converter);
>>
>> Object valuesArray;
>> Object itemValue;
>> if (submittedValues != null)
>> {
>> valuesArray = submittedValues;
>> itemValue = valueString;
>> }
>> else
>> {
>> valuesArray = currentSelections;
>> itemValue = curItem.getValue();
>> }
>>
>> RequestStateManager.set(context,
>>
>> RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
>> component);
>>
>> boolean isSelected = isSelected(context, component, itemValue,
>> valuesArray, converter);
>> if (optionInfo.isHideNoSelection() &&
>> curItem.isNoSelectionOption() &&
>> currentSelections != null &&
>> !isSelected)
>> {
>> return;
>> }
>>
>> ResponseWriter writer = context.getResponseWriter();
>> assert (writer != null);
>>
>> if (alignVertical)
>> {
>> writer.writeText(TAB, component, null);
>> writer.startElement(TR, component);
>> writer.writeText(NEWLINE, component, null);
>> }
>> writer.startElement(TD, component);
>> writer.writeAttribute(VALIGN, "top", VALIGN);
>> writer.writeText(NEWLINE, component, null);
>>
>> writer.startElement("input", component);
>> writer.writeAttribute("name", component.getClientId(context),
>> "clientId");
>> String idString = component.getClientId(context) +
>> UINamingContainer.getSeparatorChar(context) +
>> Integer.toString(itemNumber);
>> writer.writeAttribute("id", idString, "id");
>>
>> writer.writeAttribute("value", valueString, "value");
>> writer.writeAttribute("type", "checkbox", null);
>>
>> if (isSelected)
>> {
>> writer.writeAttribute(getSelectedTextString(), Boolean.TRUE,
>> null);
>> }
>>
>> // Don't render the disabled attribute twice if the 'parent'
>> // component is already marked disabled.
>> if (!optionInfo.isDisabled())
>> {
>> if (curItem.isDisabled())
>> {
>> writer.writeAttribute("disabled", true, "disabled");
>> }
>> }
>>
>> // Apply HTML 4.x attributes specified on UISelectMany component
>> to all
>> // items in the list except styleClass and style which are
>> rendered as
>> // attributes of outer most table.
>> RenderKitUtils.renderPassThruAttributes(context,
>> writer,
>> component,
>> ATTRIBUTES,
>>
>> getNonOnClickSelectBehaviors(component));
>>
>> RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
>> component);
>>
>> RenderKitUtils.renderSelectOnclick(context, component, true);
>>
>> writer.endElement("input");
>>
>> //--------------------------------------------------------
>> // New stuff for event selecting
>> //--------------------------------------------------------
>>
>> writer.endElement(TD);
>>
>> // starting the label td
>> writer.startElement(TD, component);
>> writer.writeAttribute(VALIGN, "top", VALIGN);
>> writer.writeAttribute("width", "80px", "width");
>> writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
>>
>> String itemLabel = curItem.getLabel();
>> if (itemLabel == null)
>> {
>> itemLabel = valueString;
>> }
>>
>> writer.writeText(" ", component, null);
>> writer.startElement(LABEL, component);
>> writer.writeAttribute("for", component.getClientId() + ":" +
>> itemNumber, "for");
>> if (!curItem.isEscape())
>> {
>> // It seems the ResponseWriter API should
>> // have a writeText() with a boolean property
>> // to determine if it content written should
>> // be escaped or not.
>> writer.write(itemLabel);
>> }
>> else
>> {
>> writer.writeText(itemLabel, component, null);
>> }
>> writer.endElement(LABEL);
>>
>> isSelected(context, component, itemValue, valuesArray, converter);
>> // if (isSelected(context, component, itemValue, valuesArray,
>> converter))
>> // {
>> // // selected
>> // }
>> // else
>> // {
>> // // not selected
>> // }
>> writer.endElement(TD);
>>
>> // starting the description td
>> writer.startElement(TD, component);
>> writer.writeAttribute(VALIGN, "top", VALIGN);
>> writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
>>
>> String itemLabelDesc = curItem.getDescription();
>> if (itemLabelDesc == null)
>> {
>> itemLabelDesc = "";
>> }
>> writer.writeText(" ", component, null);
>> if (!curItem.isEscape())
>> {
>> // It seems the ResponseWriter API should
>> // have a writeText() with a boolean property
>> // to determine if it content written should
>> // be escaped or not.
>> writer.write(itemLabelDesc);
>> }
>> else
>> {
>> writer.writeText(itemLabelDesc, component, null);
>> }
>>
>> writer.endElement(TD);
>>
>> //--------------------------------------------------------
>> // New stuff for event selecting end
>> //--------------------------------------------------------
>>
>> writer.writeText(NEWLINE, component, null);
>> if (alignVertical)
>> {
>> writer.writeText(TAB, component, null);
>> writer.endElement(TR);
>> writer.writeText(NEWLINE, component, null);
>> }
>> }
>>
>>
>> // ------------------------------------------------- Package Private
>> Methods
>>
>> /**
>> * {@inheritDoc}
>> */
>> String getSelectedTextString()
>> {
>> return "checked";
>> }
>> }
>>
>>
>> Any help is appreciated!
>> Thanks!
>>
>> René
>>
Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Romain Manni-Bucau <rm...@gmail.com>.
in tomee you can also use mojarra but I'd just keep my component
portable with myfaces if possible
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-02-13 13:23 GMT+01:00 Thomas Andraschko <an...@gmail.com>:
> I don't think that anyone will port your complete code and give you a
> complete solution ;)
>
> The biggest problem is AFAIR that the renderer implementations are not in
> the API packages. So you have to rebuild all this functionality without
> dependencies to the Impl.
>
> e.g.
> Attribute,AttributeManager -> String[] with attribute namens
> Move all the utils functions to your own code (Util.componentIsDisabled,
> RenderKitUtils.getSelectItems. etc.)
>
> The most code doesn't really depent on the IMPL code.
>
>
> 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
>
>> Hi everyone!
>>
>> I'm currently migrating an application from Glassfish 3.1.1 to TomEE. Now
>> the problem is that this application contains a custom component which was
>> unfortunately coded with hard dependencies on com.sun.faces classes (maven
>> dependency jsf-impl).
>>
>> Now my question is how can i port this component in such a way that it is
>> independent from any concrete JSF implementation (or at least in such a way
>> that it works with MyFaces).
>>
>> Here's the component:
>>
>> import java.io.IOException;
>> import java.util.Iterator;
>> import java.util.Map;
>>
>> import javax.faces.component.UIComponent;
>> import javax.faces.component.UINamingContainer;
>> import javax.faces.component.ValueHolder;
>> import javax.faces.context.FacesContext;
>> import javax.faces.context.ResponseWriter;
>> import javax.faces.convert.Converter;
>> import javax.faces.model.SelectItem;
>> import javax.faces.model.SelectItemGroup;
>>
>> import com.sun.faces.renderkit.Attribute;
>> import com.sun.faces.renderkit.AttributeManager;
>> import com.sun.faces.renderkit.RenderKitUtils;
>> import com.sun.faces.renderkit.html_basic.MenuRenderer;
>> import com.sun.faces.util.RequestStateManager;
>> import com.sun.faces.util.Util;
>>
>> /**
>> * {@inheritDoc}.
>> */
>> public class CustomSelectManyCheckboxListRenderer extends MenuRenderer
>> {
>> /** {@inheritDoc}. */
>> private static final Attribute[] ATTRIBUTES =
>> AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
>> /** Representing the border string. */
>> private static final String BORDER = "border";
>> /** Representing the tr string. */
>> private static final String TR = "tr";
>> /** Representing the td string. */
>> private static final String TD = "td";
>> /** Representing the label string. */
>> private static final String LABEL = "label";
>> /** Representing the newline string. */
>> private static final String NEWLINE = "\n";
>> /** Representing the tab string. */
>> private static final String TAB = "\t";
>> /** Representing the class string. */
>> private static final String CLASS = "class";
>> /** Representing the style string. */
>> private static final String STYLE = "style";
>> /** Representing the valign string. */
>> private static final String VALIGN = "valign";
>>
>>
>> // ---------------------------------------------------------- Public
>> Methods
>>
>>
>> @Override
>> public void encodeEnd(FacesContext context, UIComponent component)
>> throws IOException
>> {
>>
>> rendererParamsNotNull(context, component);
>>
>> if (!shouldEncode(component))
>> {
>> return;
>> }
>>
>> ResponseWriter writer = context.getResponseWriter();
>> assert (writer != null);
>>
>> String alignStr;
>> Object borderObj;
>> boolean alignVertical = false;
>> int border = 0;
>>
>>
>>
>> if (null != component.getAttributes().get("layout"))
>> {
>> alignStr = (String) component.getAttributes().get("layout");
>> alignVertical = alignStr.equalsIgnoreCase("pageDirection");
>> }
>>
>> if (null != component.getAttributes().get(BORDER))
>> {
>> borderObj = component.getAttributes().get(BORDER);
>> border = (Integer) borderObj;
>> }
>>
>> Converter converter = null;
>> if (component instanceof ValueHolder)
>> {
>> converter = ((ValueHolder)component).getConverter();
>> }
>>
>> renderBeginText(component, border, alignVertical, context, true);
>>
>> Iterator<SelectItem> items =
>> RenderKitUtils.getSelectItems(context, component);
>>
>> Object currentSelections = getCurrentSelectedValues(component);
>> Object[] submittedValues = getSubmittedSelectedValues(component);
>> Map<String, Object> attributes = component.getAttributes();
>> OptionComponentInfo optionInfo =
>> new OptionComponentInfo((String)
>> attributes.get("disabledClass"),
>> (String)
>> attributes.get("enabledClass"),
>> (String)
>> attributes.get("unselectedClass"),
>> (String)
>> attributes.get("selectedClass"),
>> Util.componentIsDisabled(component),
>> isHideNoSelection(component));
>> int idx = -1;
>> while (items.hasNext())
>> {
>> SelectItem curItem = items.next();
>> idx++;
>> // If we come across a group of options, render them as a
>> nested
>> // table.
>> if (curItem instanceof SelectItemGroup)
>> {
>> // write out the label for the group.
>> if (curItem.getLabel() != null)
>> {
>> if (alignVertical)
>> {
>> writer.startElement(TR, component);
>> }
>> writer.startElement(TD, component);
>> writer.writeText(curItem.getLabel(), component, LABEL);
>> writer.endElement(TD);
>> if (alignVertical)
>> {
>> writer.endElement(TR);
>> }
>>
>> }
>> if (alignVertical)
>> {
>> writer.startElement(TR, component);
>> }
>> writer.startElement(TD, component);
>> writer.writeText(NEWLINE, component, null);
>> renderBeginText(component, 0, alignVertical,
>> context, false);
>> // render options of this group.
>> SelectItem[] itemsArray =
>> ((SelectItemGroup) curItem).getSelectItems();
>> for (int i = 0; i < itemsArray.length; ++i)
>> {
>> renderOption(context,
>> component,
>> converter,
>> itemsArray[i],
>> currentSelections,
>> submittedValues,
>> alignVertical,
>> i,
>> optionInfo);
>> }
>> renderEndText(component, alignVertical, context);
>> writer.endElement(TD);
>> if (alignVertical)
>> {
>> writer.endElement(TR);
>> writer.writeText(NEWLINE, component, null);
>> }
>> }
>> else
>> {
>> renderOption(context,
>> component,
>> converter,
>> curItem,
>> currentSelections,
>> submittedValues,
>> alignVertical,
>> idx,
>> optionInfo);
>> }
>> }
>>
>> renderEndText(component, alignVertical, context);
>>
>> }
>>
>> // ------------------------------------------------------- Protected
>> Methods
>>
>>
>> /**
>> * {@inheritDoc}
>> */
>> @Override
>> protected boolean isBehaviorSource(FacesContext ctx,
>> String behaviorSourceId,
>> String componentClientId)
>> {
>>
>> if (behaviorSourceId == null)
>> {
>> return false;
>> }
>> char sepChar = UINamingContainer.getSeparatorChar(ctx);
>> String actualBehaviorId =
>> behaviorSourceId.substring(0,
>> behaviorSourceId.lastIndexOf(sepChar));
>> return (actualBehaviorId.equals(componentClientId));
>>
>> }
>>
>> /**
>> * {@inheritDoc}
>> */
>> protected void renderBeginText(UIComponent component, int border,
>> boolean alignVertical, FacesContext
>> context,
>> boolean outerTable) throws IOException
>> {
>> ResponseWriter writer = context.getResponseWriter();
>> assert (writer != null);
>>
>> writer.startElement("table", component);
>> if (border != Integer.MIN_VALUE)
>> {
>> writer.writeAttribute(BORDER, border, BORDER);
>> }
>>
>> // render style and styleclass attribute on the outer table
>> instead of
>> // rendering it as pass through attribute on every option in the
>> list.
>> if (outerTable)
>> {
>> // render "id" only for outerTable.
>> if (shouldWriteIdAttribute(component))
>> {
>> writeIdAttributeIfNecessary(context, writer, component);
>> }
>> String styleClass = (String) component.getAttributes().get(
>> "styleClass");
>> String style = (String) component.getAttributes().get(STYLE);
>> if (styleClass != null)
>> {
>> writer.writeAttribute(CLASS, styleClass, CLASS);
>> }
>> if (style != null)
>> {
>> writer.writeAttribute(STYLE, style, STYLE);
>> }
>> }
>> writer.writeText(NEWLINE, component, null);
>>
>> if (!alignVertical)
>> {
>> writer.writeText(TAB, component, null);
>> writer.startElement(TR, component);
>> writer.writeText(NEWLINE, component, null);
>> }
>>
>> }
>>
>> /**
>> * {@inheritDoc}
>> */
>> protected void renderEndText(UIComponent component,
>> boolean alignVertical,
>> FacesContext context) throws IOException
>> {
>>
>> ResponseWriter writer = context.getResponseWriter();
>> assert (writer != null);
>>
>> if (!alignVertical)
>> {
>> writer.writeText(TAB, component, null);
>> writer.endElement(TR);
>> writer.writeText(NEWLINE, component, null);
>> }
>> writer.endElement("table");
>>
>> }
>>
>> /**
>> * {@inheritDoc}
>> */
>> protected void renderOption(FacesContext context,
>> UIComponent component,
>> Converter converter,
>> SelectItem curItem,
>> Object currentSelections,
>> Object[] submittedValues,
>> boolean alignVertical,
>> int itemNumber,
>> OptionComponentInfo optionInfo) throws
>> IOException
>> {
>>
>> String valueString = getFormattedValue(context, component,
>> curItem.getValue(),
>> converter);
>>
>> Object valuesArray;
>> Object itemValue;
>> if (submittedValues != null)
>> {
>> valuesArray = submittedValues;
>> itemValue = valueString;
>> }
>> else
>> {
>> valuesArray = currentSelections;
>> itemValue = curItem.getValue();
>> }
>>
>> RequestStateManager.set(context,
>>
>> RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
>> component);
>>
>> boolean isSelected = isSelected(context, component, itemValue,
>> valuesArray, converter);
>> if (optionInfo.isHideNoSelection() &&
>> curItem.isNoSelectionOption() &&
>> currentSelections != null &&
>> !isSelected)
>> {
>> return;
>> }
>>
>> ResponseWriter writer = context.getResponseWriter();
>> assert (writer != null);
>>
>> if (alignVertical)
>> {
>> writer.writeText(TAB, component, null);
>> writer.startElement(TR, component);
>> writer.writeText(NEWLINE, component, null);
>> }
>> writer.startElement(TD, component);
>> writer.writeAttribute(VALIGN, "top", VALIGN);
>> writer.writeText(NEWLINE, component, null);
>>
>> writer.startElement("input", component);
>> writer.writeAttribute("name", component.getClientId(context),
>> "clientId");
>> String idString = component.getClientId(context) +
>> UINamingContainer.getSeparatorChar(context) +
>> Integer.toString(itemNumber);
>> writer.writeAttribute("id", idString, "id");
>>
>> writer.writeAttribute("value", valueString, "value");
>> writer.writeAttribute("type", "checkbox", null);
>>
>> if (isSelected)
>> {
>> writer.writeAttribute(getSelectedTextString(), Boolean.TRUE,
>> null);
>> }
>>
>> // Don't render the disabled attribute twice if the 'parent'
>> // component is already marked disabled.
>> if (!optionInfo.isDisabled())
>> {
>> if (curItem.isDisabled())
>> {
>> writer.writeAttribute("disabled", true, "disabled");
>> }
>> }
>>
>> // Apply HTML 4.x attributes specified on UISelectMany component
>> to all
>> // items in the list except styleClass and style which are
>> rendered as
>> // attributes of outer most table.
>> RenderKitUtils.renderPassThruAttributes(context,
>> writer,
>> component,
>> ATTRIBUTES,
>>
>> getNonOnClickSelectBehaviors(component));
>>
>> RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
>> component);
>>
>> RenderKitUtils.renderSelectOnclick(context, component, true);
>>
>> writer.endElement("input");
>>
>> //--------------------------------------------------------
>> // New stuff for event selecting
>> //--------------------------------------------------------
>>
>> writer.endElement(TD);
>>
>> // starting the label td
>> writer.startElement(TD, component);
>> writer.writeAttribute(VALIGN, "top", VALIGN);
>> writer.writeAttribute("width", "80px", "width");
>> writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
>>
>> String itemLabel = curItem.getLabel();
>> if (itemLabel == null)
>> {
>> itemLabel = valueString;
>> }
>>
>> writer.writeText(" ", component, null);
>> writer.startElement(LABEL, component);
>> writer.writeAttribute("for", component.getClientId() + ":" +
>> itemNumber, "for");
>> if (!curItem.isEscape())
>> {
>> // It seems the ResponseWriter API should
>> // have a writeText() with a boolean property
>> // to determine if it content written should
>> // be escaped or not.
>> writer.write(itemLabel);
>> }
>> else
>> {
>> writer.writeText(itemLabel, component, null);
>> }
>> writer.endElement(LABEL);
>>
>> isSelected(context, component, itemValue, valuesArray, converter);
>> // if (isSelected(context, component, itemValue, valuesArray,
>> converter))
>> // {
>> // // selected
>> // }
>> // else
>> // {
>> // // not selected
>> // }
>> writer.endElement(TD);
>>
>> // starting the description td
>> writer.startElement(TD, component);
>> writer.writeAttribute(VALIGN, "top", VALIGN);
>> writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
>>
>> String itemLabelDesc = curItem.getDescription();
>> if (itemLabelDesc == null)
>> {
>> itemLabelDesc = "";
>> }
>> writer.writeText(" ", component, null);
>> if (!curItem.isEscape())
>> {
>> // It seems the ResponseWriter API should
>> // have a writeText() with a boolean property
>> // to determine if it content written should
>> // be escaped or not.
>> writer.write(itemLabelDesc);
>> }
>> else
>> {
>> writer.writeText(itemLabelDesc, component, null);
>> }
>>
>> writer.endElement(TD);
>>
>> //--------------------------------------------------------
>> // New stuff for event selecting end
>> //--------------------------------------------------------
>>
>> writer.writeText(NEWLINE, component, null);
>> if (alignVertical)
>> {
>> writer.writeText(TAB, component, null);
>> writer.endElement(TR);
>> writer.writeText(NEWLINE, component, null);
>> }
>> }
>>
>>
>> // ------------------------------------------------- Package Private
>> Methods
>>
>> /**
>> * {@inheritDoc}
>> */
>> String getSelectedTextString()
>> {
>> return "checked";
>> }
>> }
>>
>>
>> Any help is appreciated!
>> Thanks!
>>
>> René
>>
Re: Re: Re: Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Karl Kildén <ka...@gmail.com>.
Well I don't understand why they call it a MenuRenderer, as far as I can
see it's a superclass for uiselectone uiselectmany... No equalent
superclass is used for myfaces by the looks of things.
So you might need to rewrite the whole thing from scratch and paying
attention to making it portable. What you have there seems to be a
hierarchy like <ul> <li> but with checkboxes instead.
How does it work exactly? You select parent and it auto selects child
nodes? Anyway if it's a bunch of selectone in a hierarchy you should be
able to do it with css and ui:repeat and ajax?
Give me a proper specification please
Cheers
On 14 February 2014 08:52, Rene Perschon <Ch...@gmx.net> wrote:
> Well the imports of com.sun.faces are offending, starting with
> MenuRenderer from which our custom renderer extends..
> I've already tried to just swap the imports (for example for Apache
> Tobago's MenuRenderer, but it's final). I barely know about com.sun.faces
> and i've never used MyFaces before, so it's really hard for me to figure
> out the equivalents here
>
>
>
> Gesendet: Freitag, 14. Februar 2014 um 08:49 Uhr
> Von: "Karl Kildén" <ka...@gmail.com>
> An: "MyFaces Discussion" <us...@myfaces.apache.org>
> Betreff: Re: Re: Re: Problems with a custom component when migrating from
> Glassfish(mojarra) to TomEE
> Rene, I at least can't see anything.
>
> Another thing to think about it what impl stuff you have actually worked
> with? I mean mojarra should have about the same stuff as myfaces?
> To make myself clear, what does the components and stuff you extend really
> belong to? Shouldn't be impossible to find equivalents in myfaces...
>
>
> On 14 February 2014 08:45, Rene Perschon <Ch...@gmx.net> wrote:
>
> > Yes, here it is. It's a two-stage component which displays a hierarchical
> > (2 levels) selection choice.
> >
> >
> >
> > Gesendet: Donnerstag, 13. Februar 2014 um 16:57 Uhr
> > Von: "Howard W. Smith, Jr." <sm...@gmail.com>
> > An: "MyFaces Discussion" <us...@myfaces.apache.org>
> > Betreff: Re: Re: Problems with a custom component when migrating from
> > Glassfish(mojarra) to TomEE
> > do you have a screen capture or some type of demo of the Select
> component?
> >
> >
> >
> > On Thu, Feb 13, 2014 at 8:39 AM, Rene Perschon <Ch...@gmx.net>
> > wrote:
> >
> > > I don't think a TagHandler or a custom component can do what that code
> > > does. It's used to display a Select in a very specific way.
> > >
> > >
> > >
> > > Gesendet: Donnerstag, 13. Februar 2014 um 14:29 Uhr
> > > Von: "Karl Kildén" <ka...@gmail.com>
> > > An: "MyFaces Discussion" <us...@myfaces.apache.org>
> > > Betreff: Re: Problems with a custom component when migrating from
> > > Glassfish(mojarra) to TomEE
> > > Have you considered a custom tagHandler / composite component instead?
> > >
> > > I took a quick look but I don't recognize much sorry.
> > >
> > >
> > > On 13 February 2014 14:09, Howard W. Smith, Jr. <
> smithh032772@gmail.com
> > > >wrote:
> > >
> > > > I think Leonardo, Gerhard, or one of the other committers may provide
> > her
> > > > some good help, just to get another MyFaces user, especially when one
> > is
> > > > migrating from Mojarra to MyFaces.
> > > >
> > > > @Renee, +1 your goal/request.
> > > >
> > > > I migrated from Mojarra to MyFaces, first, and then 2 months later, I
> > > > migrated from Glassfish to tomee (and JSF managed beans to CDI
> managed
> > > > beans at same time). Thomas, Romain, Mark Struberg, and others
> provided
> > > > great help and motivation. Apache tomee, MyFaces, tomcat user mail
> > lists
> > > > are definitely the place to be.
> > > >
> > > > But I didn't have code dependent on the Mojarra library like you do.
> > > Still,
> > > > it took me about a week to migrate from Mojarra to MyFaces. Thomas
> and
> > > > Leonardo motivated me to start the migration after reading about the
> > > > performance comparison between Mojarra and MyFaces. Mark Struberg
> blog,
> > > why
> > > > is OpenWebBeans so fast, motivated me to migrate to CDI and tomee.
> :-)
> > > >
> > > > I love high performance, that's why I opted to use MyFaces, tomee,
> > > > OpenWebBeans, and JUEL.
> > > >
> > > > Wishing you much success.
> > > > On Feb 13, 2014 7:23 AM, "Thomas Andraschko" <
> > > andraschko.thomas@gmail.com>
> > > > wrote:
> > > >
> > > > > I don't think that anyone will port your complete code and give
> you a
> > > > > complete solution ;)
> > > > >
> > > > > The biggest problem is AFAIR that the renderer implementations are
> > not
> > > in
> > > > > the API packages. So you have to rebuild all this functionality
> > without
> > > > > dependencies to the Impl.
> > > > >
> > > > > e.g.
> > > > > Attribute,AttributeManager -> String[] with attribute namens
> > > > > Move all the utils functions to your own code
> > > (Util.componentIsDisabled,
> > > > > RenderKitUtils.getSelectItems. etc.)
> > > > >
> > > > > The most code doesn't really depent on the IMPL code.
> > > > >
> > > > >
> > > > > 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> > > > >
> > > > > > Hi everyone!
> > > > > >
> > > > > > I'm currently migrating an application from Glassfish 3.1.1 to
> > TomEE.
> > > > Now
> > > > > > the problem is that this application contains a custom component
> > > which
> > > > > was
> > > > > > unfortunately coded with hard dependencies on com.sun.faces
> classes
> > > > > (maven
> > > > > > dependency jsf-impl).
> > > > > >
> > > > > > Now my question is how can i port this component in such a way
> that
> > > it
> > > > is
> > > > > > independent from any concrete JSF implementation (or at least in
> > > such a
> > > > > way
> > > > > > that it works with MyFaces).
> > > > > >
> > > > > > Here's the component:
> > > > > >
> > > > > > import java.io.IOException;
> > > > > > import java.util.Iterator;
> > > > > > import java.util.Map;
> > > > > >
> > > > > > import javax.faces.component.UIComponent;
> > > > > > import javax.faces.component.UINamingContainer;
> > > > > > import javax.faces.component.ValueHolder;
> > > > > > import javax.faces.context.FacesContext;
> > > > > > import javax.faces.context.ResponseWriter;
> > > > > > import javax.faces.convert.Converter;
> > > > > > import javax.faces.model.SelectItem;
> > > > > > import javax.faces.model.SelectItemGroup;
> > > > > >
> > > > > > import com.sun.faces.renderkit.Attribute;
> > > > > > import com.sun.faces.renderkit.AttributeManager;
> > > > > > import com.sun.faces.renderkit.RenderKitUtils;
> > > > > > import com.sun.faces.renderkit.html_basic.MenuRenderer;
> > > > > > import com.sun.faces.util.RequestStateManager;
> > > > > > import com.sun.faces.util.Util;
> > > > > >
> > > > > > /**
> > > > > > * {@inheritDoc}.
> > > > > > */
> > > > > > public class CustomSelectManyCheckboxListRenderer extends
> > > MenuRenderer
> > > > > > {
> > > > > > /** {@inheritDoc}. */
> > > > > > private static final Attribute[] ATTRIBUTES =
> > > > > >
> > > >
> > AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> > > > > > /** Representing the border string. */
> > > > > > private static final String BORDER = "border";
> > > > > > /** Representing the tr string. */
> > > > > > private static final String TR = "tr";
> > > > > > /** Representing the td string. */
> > > > > > private static final String TD = "td";
> > > > > > /** Representing the label string. */
> > > > > > private static final String LABEL = "label";
> > > > > > /** Representing the newline string. */
> > > > > > private static final String NEWLINE = "\n";
> > > > > > /** Representing the tab string. */
> > > > > > private static final String TAB = "\t";
> > > > > > /** Representing the class string. */
> > > > > > private static final String CLASS = "class";
> > > > > > /** Representing the style string. */
> > > > > > private static final String STYLE = "style";
> > > > > > /** Representing the valign string. */
> > > > > > private static final String VALIGN = "valign";
> > > > > >
> > > > > >
> > > > > > // ----------------------------------------------------------
> > > > Public
> > > > > > Methods
> > > > > >
> > > > > >
> > > > > > @Override
> > > > > > public void encodeEnd(FacesContext context, UIComponent
> component)
> > > > > > throws IOException
> > > > > > {
> > > > > >
> > > > > > rendererParamsNotNull(context, component);
> > > > > >
> > > > > > if (!shouldEncode(component))
> > > > > > {
> > > > > > return;
> > > > > > }
> > > > > >
> > > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > > assert (writer != null);
> > > > > >
> > > > > > String alignStr;
> > > > > > Object borderObj;
> > > > > > boolean alignVertical = false;
> > > > > > int border = 0;
> > > > > >
> > > > > >
> > > > > >
> > > > > > if (null != component.getAttributes().get("layout"))
> > > > > > {
> > > > > > alignStr = (String)
> > > > component.getAttributes().get("layout");
> > > > > > alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> > > > > > }
> > > > > >
> > > > > > if (null != component.getAttributes().get(BORDER))
> > > > > > {
> > > > > > borderObj = component.getAttributes().get(BORDER);
> > > > > > border = (Integer) borderObj;
> > > > > > }
> > > > > >
> > > > > > Converter converter = null;
> > > > > > if (component instanceof ValueHolder)
> > > > > > {
> > > > > > converter = ((ValueHolder)component).getConverter();
> > > > > > }
> > > > > >
> > > > > > renderBeginText(component, border, alignVertical, context,
> > > > true);
> > > > > >
> > > > > > Iterator<SelectItem> items =
> > > > > > RenderKitUtils.getSelectItems(context, component);
> > > > > >
> > > > > > Object currentSelections = getCurrentSelectedValues(component);
> > > > > > Object[] submittedValues =
> > > > getSubmittedSelectedValues(component);
> > > > > > Map<String, Object> attributes = component.getAttributes();
> > > > > > OptionComponentInfo optionInfo =
> > > > > > new OptionComponentInfo((String)
> > > > > > attributes.get("disabledClass"),
> > > > > > (String)
> > > > > > attributes.get("enabledClass"),
> > > > > > (String)
> > > > > > attributes.get("unselectedClass"),
> > > > > > (String)
> > > > > > attributes.get("selectedClass"),
> > > > > >
> > > > > Util.componentIsDisabled(component),
> > > > > > isHideNoSelection(component));
> > > > > > int idx = -1;
> > > > > > while (items.hasNext())
> > > > > > {
> > > > > > SelectItem curItem = items.next();
> > > > > > idx++;
> > > > > > // If we come across a group of options, render them as a
> > > > > > nested
> > > > > > // table.
> > > > > > if (curItem instanceof SelectItemGroup)
> > > > > > {
> > > > > > // write out the label for the group.
> > > > > > if (curItem.getLabel() != null)
> > > > > > {
> > > > > > if (alignVertical)
> > > > > > {
> > > > > > writer.startElement(TR, component);
> > > > > > }
> > > > > > writer.startElement(TD, component);
> > > > > > writer.writeText(curItem.getLabel(), component,
> > > > > LABEL);
> > > > > > writer.endElement(TD);
> > > > > > if (alignVertical)
> > > > > > {
> > > > > > writer.endElement(TR);
> > > > > > }
> > > > > >
> > > > > > }
> > > > > > if (alignVertical)
> > > > > > {
> > > > > > writer.startElement(TR, component);
> > > > > > }
> > > > > > writer.startElement(TD, component);
> > > > > > writer.writeText(NEWLINE, component, null);
> > > > > > renderBeginText(component, 0, alignVertical,
> > > > > > context, false);
> > > > > > // render options of this group.
> > > > > > SelectItem[] itemsArray =
> > > > > > ((SelectItemGroup) curItem).getSelectItems();
> > > > > > for (int i = 0; i < itemsArray.length; ++i)
> > > > > > {
> > > > > > renderOption(context,
> > > > > > component,
> > > > > > converter,
> > > > > > itemsArray[i],
> > > > > > currentSelections,
> > > > > > submittedValues,
> > > > > > alignVertical,
> > > > > > i,
> > > > > > optionInfo);
> > > > > > }
> > > > > > renderEndText(component, alignVertical, context);
> > > > > > writer.endElement(TD);
> > > > > > if (alignVertical)
> > > > > > {
> > > > > > writer.endElement(TR);
> > > > > > writer.writeText(NEWLINE, component, null);
> > > > > > }
> > > > > > }
> > > > > > else
> > > > > > {
> > > > > > renderOption(context,
> > > > > > component,
> > > > > > converter,
> > > > > > curItem,
> > > > > > currentSelections,
> > > > > > submittedValues,
> > > > > > alignVertical,
> > > > > > idx,
> > > > > > optionInfo);
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > renderEndText(component, alignVertical, context);
> > > > > >
> > > > > > }
> > > > > >
> > > > > > // -------------------------------------------------------
> > > > Protected
> > > > > > Methods
> > > > > >
> > > > > >
> > > > > > /**
> > > > > > * {@inheritDoc}
> > > > > > */
> > > > > > @Override
> > > > > > protected boolean isBehaviorSource(FacesContext ctx,
> > > > > > String behaviorSourceId,
> > > > > > String componentClientId)
> > > > > > {
> > > > > >
> > > > > > if (behaviorSourceId == null)
> > > > > > {
> > > > > > return false;
> > > > > > }
> > > > > > char sepChar = UINamingContainer.getSeparatorChar(ctx);
> > > > > > String actualBehaviorId =
> > > > > > behaviorSourceId.substring(0,
> > > > > > behaviorSourceId.lastIndexOf(sepChar));
> > > > > > return (actualBehaviorId.equals(componentClientId));
> > > > > >
> > > > > > }
> > > > > >
> > > > > > /**
> > > > > > * {@inheritDoc}
> > > > > > */
> > > > > > protected void renderBeginText(UIComponent component, int border,
> > > > > > boolean alignVertical, FacesContext
> > > > > > context,
> > > > > > boolean outerTable) throws
> > > > IOException
> > > > > > {
> > > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > > assert (writer != null);
> > > > > >
> > > > > > writer.startElement("table", component);
> > > > > > if (border != Integer.MIN_VALUE)
> > > > > > {
> > > > > > writer.writeAttribute(BORDER, border, BORDER);
> > > > > > }
> > > > > >
> > > > > > // render style and styleclass attribute on the outer table
> > > > > > instead of
> > > > > > // rendering it as pass through attribute on every option in
> > > > the
> > > > > > list.
> > > > > > if (outerTable)
> > > > > > {
> > > > > > // render "id" only for outerTable.
> > > > > > if (shouldWriteIdAttribute(component))
> > > > > > {
> > > > > > writeIdAttributeIfNecessary(context, writer,
> > > > component);
> > > > > > }
> > > > > > String styleClass = (String) component.getAttributes().get(
> > > > > > "styleClass");
> > > > > > String style = (String)
> > > > component.getAttributes().get(STYLE);
> > > > > > if (styleClass != null)
> > > > > > {
> > > > > > writer.writeAttribute(CLASS, styleClass, CLASS);
> > > > > > }
> > > > > > if (style != null)
> > > > > > {
> > > > > > writer.writeAttribute(STYLE, style, STYLE);
> > > > > > }
> > > > > > }
> > > > > > writer.writeText(NEWLINE, component, null);
> > > > > >
> > > > > > if (!alignVertical)
> > > > > > {
> > > > > > writer.writeText(TAB, component, null);
> > > > > > writer.startElement(TR, component);
> > > > > > writer.writeText(NEWLINE, component, null);
> > > > > > }
> > > > > >
> > > > > > }
> > > > > >
> > > > > > /**
> > > > > > * {@inheritDoc}
> > > > > > */
> > > > > > protected void renderEndText(UIComponent component,
> > > > > > boolean alignVertical,
> > > > > > FacesContext context) throws
> > > > IOException
> > > > > > {
> > > > > >
> > > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > > assert (writer != null);
> > > > > >
> > > > > > if (!alignVertical)
> > > > > > {
> > > > > > writer.writeText(TAB, component, null);
> > > > > > writer.endElement(TR);
> > > > > > writer.writeText(NEWLINE, component, null);
> > > > > > }
> > > > > > writer.endElement("table");
> > > > > >
> > > > > > }
> > > > > >
> > > > > > /**
> > > > > > * {@inheritDoc}
> > > > > > */
> > > > > > protected void renderOption(FacesContext context,
> > > > > > UIComponent component,
> > > > > > Converter converter,
> > > > > > SelectItem curItem,
> > > > > > Object currentSelections,
> > > > > > Object[] submittedValues,
> > > > > > boolean alignVertical,
> > > > > > int itemNumber,
> > > > > > OptionComponentInfo optionInfo) throws
> > > > > > IOException
> > > > > > {
> > > > > >
> > > > > > String valueString = getFormattedValue(context, component,
> > > > > > curItem.getValue(),
> > > > > > converter);
> > > > > >
> > > > > > Object valuesArray;
> > > > > > Object itemValue;
> > > > > > if (submittedValues != null)
> > > > > > {
> > > > > > valuesArray = submittedValues;
> > > > > > itemValue = valueString;
> > > > > > }
> > > > > > else
> > > > > > {
> > > > > > valuesArray = currentSelections;
> > > > > > itemValue = curItem.getValue();
> > > > > > }
> > > > > >
> > > > > > RequestStateManager.set(context,
> > > > > >
> > > > > > RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> > > > > > component);
> > > > > >
> > > > > > boolean isSelected = isSelected(context, component, itemValue,
> > > > > > valuesArray, converter);
> > > > > > if (optionInfo.isHideNoSelection() &&
> > > > > > curItem.isNoSelectionOption() &&
> > > > > > currentSelections != null &&
> > > > > > !isSelected)
> > > > > > {
> > > > > > return;
> > > > > > }
> > > > > >
> > > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > > assert (writer != null);
> > > > > >
> > > > > > if (alignVertical)
> > > > > > {
> > > > > > writer.writeText(TAB, component, null);
> > > > > > writer.startElement(TR, component);
> > > > > > writer.writeText(NEWLINE, component, null);
> > > > > > }
> > > > > > writer.startElement(TD, component);
> > > > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > > > writer.writeText(NEWLINE, component, null);
> > > > > >
> > > > > > writer.startElement("input", component);
> > > > > > writer.writeAttribute("name", component.getClientId(context),
> > > > > > "clientId");
> > > > > > String idString = component.getClientId(context) +
> > > > > > UINamingContainer.getSeparatorChar(context) +
> > > > > > Integer.toString(itemNumber);
> > > > > > writer.writeAttribute("id", idString, "id");
> > > > > >
> > > > > > writer.writeAttribute("value", valueString, "value");
> > > > > > writer.writeAttribute("type", "checkbox", null);
> > > > > >
> > > > > > if (isSelected)
> > > > > > {
> > > > > > writer.writeAttribute(getSelectedTextString(),
> > > > Boolean.TRUE,
> > > > > > null);
> > > > > > }
> > > > > >
> > > > > > // Don't render the disabled attribute twice if the 'parent'
> > > > > > // component is already marked disabled.
> > > > > > if (!optionInfo.isDisabled())
> > > > > > {
> > > > > > if (curItem.isDisabled())
> > > > > > {
> > > > > > writer.writeAttribute("disabled", true, "disabled");
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > // Apply HTML 4.x attributes specified on UISelectMany
> > > > component
> > > > > > to all
> > > > > > // items in the list except styleClass and style which are
> > > > > > rendered as
> > > > > > // attributes of outer most table.
> > > > > > RenderKitUtils.renderPassThruAttributes(context,
> > > > > > writer,
> > > > > > component,
> > > > > > ATTRIBUTES,
> > > > > >
> > > > > > getNonOnClickSelectBehaviors(component));
> > > > > >
> > > > > > RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> > > > > > component);
> > > > > >
> > > > > > RenderKitUtils.renderSelectOnclick(context, component, true);
> > > > > >
> > > > > > writer.endElement("input");
> > > > > >
> > > > > > //--------------------------------------------------------
> > > > > > // New stuff for event selecting
> > > > > > //--------------------------------------------------------
> > > > > >
> > > > > > writer.endElement(TD);
> > > > > >
> > > > > > // starting the label td
> > > > > > writer.startElement(TD, component);
> > > > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > > > writer.writeAttribute("width", "80px", "width");
> > > > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > > > >
> > > > > > String itemLabel = curItem.getLabel();
> > > > > > if (itemLabel == null)
> > > > > > {
> > > > > > itemLabel = valueString;
> > > > > > }
> > > > > >
> > > > > > writer.writeText(" ", component, null);
> > > > > > writer.startElement(LABEL, component);
> > > > > > writer.writeAttribute("for", component.getClientId() + ":" +
> > > > > > itemNumber, "for");
> > > > > > if (!curItem.isEscape())
> > > > > > {
> > > > > > // It seems the ResponseWriter API should
> > > > > > // have a writeText() with a boolean property
> > > > > > // to determine if it content written should
> > > > > > // be escaped or not.
> > > > > > writer.write(itemLabel);
> > > > > > }
> > > > > > else
> > > > > > {
> > > > > > writer.writeText(itemLabel, component, null);
> > > > > > }
> > > > > > writer.endElement(LABEL);
> > > > > >
> > > > > > isSelected(context, component, itemValue, valuesArray,
> > > > > converter);
> > > > > > // if (isSelected(context, component, itemValue,
> > > > valuesArray,
> > > > > > converter))
> > > > > > // {
> > > > > > // // selected
> > > > > > // }
> > > > > > // else
> > > > > > // {
> > > > > > // // not selected
> > > > > > // }
> > > > > > writer.endElement(TD);
> > > > > >
> > > > > > // starting the description td
> > > > > > writer.startElement(TD, component);
> > > > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > > > >
> > > > > > String itemLabelDesc = curItem.getDescription();
> > > > > > if (itemLabelDesc == null)
> > > > > > {
> > > > > > itemLabelDesc = "";
> > > > > > }
> > > > > > writer.writeText(" ", component, null);
> > > > > > if (!curItem.isEscape())
> > > > > > {
> > > > > > // It seems the ResponseWriter API should
> > > > > > // have a writeText() with a boolean property
> > > > > > // to determine if it content written should
> > > > > > // be escaped or not.
> > > > > > writer.write(itemLabelDesc);
> > > > > > }
> > > > > > else
> > > > > > {
> > > > > > writer.writeText(itemLabelDesc, component, null);
> > > > > > }
> > > > > >
> > > > > > writer.endElement(TD);
> > > > > >
> > > > > > //--------------------------------------------------------
> > > > > > // New stuff for event selecting end
> > > > > > //--------------------------------------------------------
> > > > > >
> > > > > > writer.writeText(NEWLINE, component, null);
> > > > > > if (alignVertical)
> > > > > > {
> > > > > > writer.writeText(TAB, component, null);
> > > > > > writer.endElement(TR);
> > > > > > writer.writeText(NEWLINE, component, null);
> > > > > > }
> > > > > > }
> > > > > >
> > > > > >
> > > > > > // ------------------------------------------------- Package
> > > > Private
> > > > > > Methods
> > > > > >
> > > > > > /**
> > > > > > * {@inheritDoc}
> > > > > > */
> > > > > > String getSelectedTextString()
> > > > > > {
> > > > > > return "checked";
> > > > > > }
> > > > > > }
> > > > > >
> > > > > >
> > > > > > Any help is appreciated!
> > > > > > Thanks!
> > > > > >
> > > > > > René
> > > > > >
> > > > >
> > > >
> > >
> >
>
Aw: Re: Re: Re: Problems with a custom component when migrating
from Glassfish(mojarra) to TomEE
Posted by Rene Perschon <Ch...@gmx.net>.
Well the imports of com.sun.faces are offending, starting with MenuRenderer from which our custom renderer extends..
I've already tried to just swap the imports (for example for Apache Tobago's MenuRenderer, but it's final). I barely know about com.sun.faces and i've never used MyFaces before, so it's really hard for me to figure out the equivalents here
Gesendet: Freitag, 14. Februar 2014 um 08:49 Uhr
Von: "Karl Kildén" <ka...@gmail.com>
An: "MyFaces Discussion" <us...@myfaces.apache.org>
Betreff: Re: Re: Re: Problems with a custom component when migrating from Glassfish(mojarra) to TomEE
Rene, I at least can't see anything.
Another thing to think about it what impl stuff you have actually worked
with? I mean mojarra should have about the same stuff as myfaces?
To make myself clear, what does the components and stuff you extend really
belong to? Shouldn't be impossible to find equivalents in myfaces...
On 14 February 2014 08:45, Rene Perschon <Ch...@gmx.net> wrote:
> Yes, here it is. It's a two-stage component which displays a hierarchical
> (2 levels) selection choice.
>
>
>
> Gesendet: Donnerstag, 13. Februar 2014 um 16:57 Uhr
> Von: "Howard W. Smith, Jr." <sm...@gmail.com>
> An: "MyFaces Discussion" <us...@myfaces.apache.org>
> Betreff: Re: Re: Problems with a custom component when migrating from
> Glassfish(mojarra) to TomEE
> do you have a screen capture or some type of demo of the Select component?
>
>
>
> On Thu, Feb 13, 2014 at 8:39 AM, Rene Perschon <Ch...@gmx.net>
> wrote:
>
> > I don't think a TagHandler or a custom component can do what that code
> > does. It's used to display a Select in a very specific way.
> >
> >
> >
> > Gesendet: Donnerstag, 13. Februar 2014 um 14:29 Uhr
> > Von: "Karl Kildén" <ka...@gmail.com>
> > An: "MyFaces Discussion" <us...@myfaces.apache.org>
> > Betreff: Re: Problems with a custom component when migrating from
> > Glassfish(mojarra) to TomEE
> > Have you considered a custom tagHandler / composite component instead?
> >
> > I took a quick look but I don't recognize much sorry.
> >
> >
> > On 13 February 2014 14:09, Howard W. Smith, Jr. <smithh032772@gmail.com
> > >wrote:
> >
> > > I think Leonardo, Gerhard, or one of the other committers may provide
> her
> > > some good help, just to get another MyFaces user, especially when one
> is
> > > migrating from Mojarra to MyFaces.
> > >
> > > @Renee, +1 your goal/request.
> > >
> > > I migrated from Mojarra to MyFaces, first, and then 2 months later, I
> > > migrated from Glassfish to tomee (and JSF managed beans to CDI managed
> > > beans at same time). Thomas, Romain, Mark Struberg, and others provided
> > > great help and motivation. Apache tomee, MyFaces, tomcat user mail
> lists
> > > are definitely the place to be.
> > >
> > > But I didn't have code dependent on the Mojarra library like you do.
> > Still,
> > > it took me about a week to migrate from Mojarra to MyFaces. Thomas and
> > > Leonardo motivated me to start the migration after reading about the
> > > performance comparison between Mojarra and MyFaces. Mark Struberg blog,
> > why
> > > is OpenWebBeans so fast, motivated me to migrate to CDI and tomee. :-)
> > >
> > > I love high performance, that's why I opted to use MyFaces, tomee,
> > > OpenWebBeans, and JUEL.
> > >
> > > Wishing you much success.
> > > On Feb 13, 2014 7:23 AM, "Thomas Andraschko" <
> > andraschko.thomas@gmail.com>
> > > wrote:
> > >
> > > > I don't think that anyone will port your complete code and give you a
> > > > complete solution ;)
> > > >
> > > > The biggest problem is AFAIR that the renderer implementations are
> not
> > in
> > > > the API packages. So you have to rebuild all this functionality
> without
> > > > dependencies to the Impl.
> > > >
> > > > e.g.
> > > > Attribute,AttributeManager -> String[] with attribute namens
> > > > Move all the utils functions to your own code
> > (Util.componentIsDisabled,
> > > > RenderKitUtils.getSelectItems. etc.)
> > > >
> > > > The most code doesn't really depent on the IMPL code.
> > > >
> > > >
> > > > 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> > > >
> > > > > Hi everyone!
> > > > >
> > > > > I'm currently migrating an application from Glassfish 3.1.1 to
> TomEE.
> > > Now
> > > > > the problem is that this application contains a custom component
> > which
> > > > was
> > > > > unfortunately coded with hard dependencies on com.sun.faces classes
> > > > (maven
> > > > > dependency jsf-impl).
> > > > >
> > > > > Now my question is how can i port this component in such a way that
> > it
> > > is
> > > > > independent from any concrete JSF implementation (or at least in
> > such a
> > > > way
> > > > > that it works with MyFaces).
> > > > >
> > > > > Here's the component:
> > > > >
> > > > > import java.io.IOException;
> > > > > import java.util.Iterator;
> > > > > import java.util.Map;
> > > > >
> > > > > import javax.faces.component.UIComponent;
> > > > > import javax.faces.component.UINamingContainer;
> > > > > import javax.faces.component.ValueHolder;
> > > > > import javax.faces.context.FacesContext;
> > > > > import javax.faces.context.ResponseWriter;
> > > > > import javax.faces.convert.Converter;
> > > > > import javax.faces.model.SelectItem;
> > > > > import javax.faces.model.SelectItemGroup;
> > > > >
> > > > > import com.sun.faces.renderkit.Attribute;
> > > > > import com.sun.faces.renderkit.AttributeManager;
> > > > > import com.sun.faces.renderkit.RenderKitUtils;
> > > > > import com.sun.faces.renderkit.html_basic.MenuRenderer;
> > > > > import com.sun.faces.util.RequestStateManager;
> > > > > import com.sun.faces.util.Util;
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}.
> > > > > */
> > > > > public class CustomSelectManyCheckboxListRenderer extends
> > MenuRenderer
> > > > > {
> > > > > /** {@inheritDoc}. */
> > > > > private static final Attribute[] ATTRIBUTES =
> > > > >
> > >
> AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> > > > > /** Representing the border string. */
> > > > > private static final String BORDER = "border";
> > > > > /** Representing the tr string. */
> > > > > private static final String TR = "tr";
> > > > > /** Representing the td string. */
> > > > > private static final String TD = "td";
> > > > > /** Representing the label string. */
> > > > > private static final String LABEL = "label";
> > > > > /** Representing the newline string. */
> > > > > private static final String NEWLINE = "\n";
> > > > > /** Representing the tab string. */
> > > > > private static final String TAB = "\t";
> > > > > /** Representing the class string. */
> > > > > private static final String CLASS = "class";
> > > > > /** Representing the style string. */
> > > > > private static final String STYLE = "style";
> > > > > /** Representing the valign string. */
> > > > > private static final String VALIGN = "valign";
> > > > >
> > > > >
> > > > > // ----------------------------------------------------------
> > > Public
> > > > > Methods
> > > > >
> > > > >
> > > > > @Override
> > > > > public void encodeEnd(FacesContext context, UIComponent component)
> > > > > throws IOException
> > > > > {
> > > > >
> > > > > rendererParamsNotNull(context, component);
> > > > >
> > > > > if (!shouldEncode(component))
> > > > > {
> > > > > return;
> > > > > }
> > > > >
> > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > assert (writer != null);
> > > > >
> > > > > String alignStr;
> > > > > Object borderObj;
> > > > > boolean alignVertical = false;
> > > > > int border = 0;
> > > > >
> > > > >
> > > > >
> > > > > if (null != component.getAttributes().get("layout"))
> > > > > {
> > > > > alignStr = (String)
> > > component.getAttributes().get("layout");
> > > > > alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> > > > > }
> > > > >
> > > > > if (null != component.getAttributes().get(BORDER))
> > > > > {
> > > > > borderObj = component.getAttributes().get(BORDER);
> > > > > border = (Integer) borderObj;
> > > > > }
> > > > >
> > > > > Converter converter = null;
> > > > > if (component instanceof ValueHolder)
> > > > > {
> > > > > converter = ((ValueHolder)component).getConverter();
> > > > > }
> > > > >
> > > > > renderBeginText(component, border, alignVertical, context,
> > > true);
> > > > >
> > > > > Iterator<SelectItem> items =
> > > > > RenderKitUtils.getSelectItems(context, component);
> > > > >
> > > > > Object currentSelections = getCurrentSelectedValues(component);
> > > > > Object[] submittedValues =
> > > getSubmittedSelectedValues(component);
> > > > > Map<String, Object> attributes = component.getAttributes();
> > > > > OptionComponentInfo optionInfo =
> > > > > new OptionComponentInfo((String)
> > > > > attributes.get("disabledClass"),
> > > > > (String)
> > > > > attributes.get("enabledClass"),
> > > > > (String)
> > > > > attributes.get("unselectedClass"),
> > > > > (String)
> > > > > attributes.get("selectedClass"),
> > > > >
> > > > Util.componentIsDisabled(component),
> > > > > isHideNoSelection(component));
> > > > > int idx = -1;
> > > > > while (items.hasNext())
> > > > > {
> > > > > SelectItem curItem = items.next();
> > > > > idx++;
> > > > > // If we come across a group of options, render them as a
> > > > > nested
> > > > > // table.
> > > > > if (curItem instanceof SelectItemGroup)
> > > > > {
> > > > > // write out the label for the group.
> > > > > if (curItem.getLabel() != null)
> > > > > {
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.startElement(TR, component);
> > > > > }
> > > > > writer.startElement(TD, component);
> > > > > writer.writeText(curItem.getLabel(), component,
> > > > LABEL);
> > > > > writer.endElement(TD);
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.endElement(TR);
> > > > > }
> > > > >
> > > > > }
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.startElement(TR, component);
> > > > > }
> > > > > writer.startElement(TD, component);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > renderBeginText(component, 0, alignVertical,
> > > > > context, false);
> > > > > // render options of this group.
> > > > > SelectItem[] itemsArray =
> > > > > ((SelectItemGroup) curItem).getSelectItems();
> > > > > for (int i = 0; i < itemsArray.length; ++i)
> > > > > {
> > > > > renderOption(context,
> > > > > component,
> > > > > converter,
> > > > > itemsArray[i],
> > > > > currentSelections,
> > > > > submittedValues,
> > > > > alignVertical,
> > > > > i,
> > > > > optionInfo);
> > > > > }
> > > > > renderEndText(component, alignVertical, context);
> > > > > writer.endElement(TD);
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.endElement(TR);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > > }
> > > > > else
> > > > > {
> > > > > renderOption(context,
> > > > > component,
> > > > > converter,
> > > > > curItem,
> > > > > currentSelections,
> > > > > submittedValues,
> > > > > alignVertical,
> > > > > idx,
> > > > > optionInfo);
> > > > > }
> > > > > }
> > > > >
> > > > > renderEndText(component, alignVertical, context);
> > > > >
> > > > > }
> > > > >
> > > > > // -------------------------------------------------------
> > > Protected
> > > > > Methods
> > > > >
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > @Override
> > > > > protected boolean isBehaviorSource(FacesContext ctx,
> > > > > String behaviorSourceId,
> > > > > String componentClientId)
> > > > > {
> > > > >
> > > > > if (behaviorSourceId == null)
> > > > > {
> > > > > return false;
> > > > > }
> > > > > char sepChar = UINamingContainer.getSeparatorChar(ctx);
> > > > > String actualBehaviorId =
> > > > > behaviorSourceId.substring(0,
> > > > > behaviorSourceId.lastIndexOf(sepChar));
> > > > > return (actualBehaviorId.equals(componentClientId));
> > > > >
> > > > > }
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > protected void renderBeginText(UIComponent component, int border,
> > > > > boolean alignVertical, FacesContext
> > > > > context,
> > > > > boolean outerTable) throws
> > > IOException
> > > > > {
> > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > assert (writer != null);
> > > > >
> > > > > writer.startElement("table", component);
> > > > > if (border != Integer.MIN_VALUE)
> > > > > {
> > > > > writer.writeAttribute(BORDER, border, BORDER);
> > > > > }
> > > > >
> > > > > // render style and styleclass attribute on the outer table
> > > > > instead of
> > > > > // rendering it as pass through attribute on every option in
> > > the
> > > > > list.
> > > > > if (outerTable)
> > > > > {
> > > > > // render "id" only for outerTable.
> > > > > if (shouldWriteIdAttribute(component))
> > > > > {
> > > > > writeIdAttributeIfNecessary(context, writer,
> > > component);
> > > > > }
> > > > > String styleClass = (String) component.getAttributes().get(
> > > > > "styleClass");
> > > > > String style = (String)
> > > component.getAttributes().get(STYLE);
> > > > > if (styleClass != null)
> > > > > {
> > > > > writer.writeAttribute(CLASS, styleClass, CLASS);
> > > > > }
> > > > > if (style != null)
> > > > > {
> > > > > writer.writeAttribute(STYLE, style, STYLE);
> > > > > }
> > > > > }
> > > > > writer.writeText(NEWLINE, component, null);
> > > > >
> > > > > if (!alignVertical)
> > > > > {
> > > > > writer.writeText(TAB, component, null);
> > > > > writer.startElement(TR, component);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > protected void renderEndText(UIComponent component,
> > > > > boolean alignVertical,
> > > > > FacesContext context) throws
> > > IOException
> > > > > {
> > > > >
> > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > assert (writer != null);
> > > > >
> > > > > if (!alignVertical)
> > > > > {
> > > > > writer.writeText(TAB, component, null);
> > > > > writer.endElement(TR);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > > writer.endElement("table");
> > > > >
> > > > > }
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > protected void renderOption(FacesContext context,
> > > > > UIComponent component,
> > > > > Converter converter,
> > > > > SelectItem curItem,
> > > > > Object currentSelections,
> > > > > Object[] submittedValues,
> > > > > boolean alignVertical,
> > > > > int itemNumber,
> > > > > OptionComponentInfo optionInfo) throws
> > > > > IOException
> > > > > {
> > > > >
> > > > > String valueString = getFormattedValue(context, component,
> > > > > curItem.getValue(),
> > > > > converter);
> > > > >
> > > > > Object valuesArray;
> > > > > Object itemValue;
> > > > > if (submittedValues != null)
> > > > > {
> > > > > valuesArray = submittedValues;
> > > > > itemValue = valueString;
> > > > > }
> > > > > else
> > > > > {
> > > > > valuesArray = currentSelections;
> > > > > itemValue = curItem.getValue();
> > > > > }
> > > > >
> > > > > RequestStateManager.set(context,
> > > > >
> > > > > RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> > > > > component);
> > > > >
> > > > > boolean isSelected = isSelected(context, component, itemValue,
> > > > > valuesArray, converter);
> > > > > if (optionInfo.isHideNoSelection() &&
> > > > > curItem.isNoSelectionOption() &&
> > > > > currentSelections != null &&
> > > > > !isSelected)
> > > > > {
> > > > > return;
> > > > > }
> > > > >
> > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > assert (writer != null);
> > > > >
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.writeText(TAB, component, null);
> > > > > writer.startElement(TR, component);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > > writer.startElement(TD, component);
> > > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > >
> > > > > writer.startElement("input", component);
> > > > > writer.writeAttribute("name", component.getClientId(context),
> > > > > "clientId");
> > > > > String idString = component.getClientId(context) +
> > > > > UINamingContainer.getSeparatorChar(context) +
> > > > > Integer.toString(itemNumber);
> > > > > writer.writeAttribute("id", idString, "id");
> > > > >
> > > > > writer.writeAttribute("value", valueString, "value");
> > > > > writer.writeAttribute("type", "checkbox", null);
> > > > >
> > > > > if (isSelected)
> > > > > {
> > > > > writer.writeAttribute(getSelectedTextString(),
> > > Boolean.TRUE,
> > > > > null);
> > > > > }
> > > > >
> > > > > // Don't render the disabled attribute twice if the 'parent'
> > > > > // component is already marked disabled.
> > > > > if (!optionInfo.isDisabled())
> > > > > {
> > > > > if (curItem.isDisabled())
> > > > > {
> > > > > writer.writeAttribute("disabled", true, "disabled");
> > > > > }
> > > > > }
> > > > >
> > > > > // Apply HTML 4.x attributes specified on UISelectMany
> > > component
> > > > > to all
> > > > > // items in the list except styleClass and style which are
> > > > > rendered as
> > > > > // attributes of outer most table.
> > > > > RenderKitUtils.renderPassThruAttributes(context,
> > > > > writer,
> > > > > component,
> > > > > ATTRIBUTES,
> > > > >
> > > > > getNonOnClickSelectBehaviors(component));
> > > > >
> > > > > RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> > > > > component);
> > > > >
> > > > > RenderKitUtils.renderSelectOnclick(context, component, true);
> > > > >
> > > > > writer.endElement("input");
> > > > >
> > > > > //--------------------------------------------------------
> > > > > // New stuff for event selecting
> > > > > //--------------------------------------------------------
> > > > >
> > > > > writer.endElement(TD);
> > > > >
> > > > > // starting the label td
> > > > > writer.startElement(TD, component);
> > > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > > writer.writeAttribute("width", "80px", "width");
> > > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > > >
> > > > > String itemLabel = curItem.getLabel();
> > > > > if (itemLabel == null)
> > > > > {
> > > > > itemLabel = valueString;
> > > > > }
> > > > >
> > > > > writer.writeText(" ", component, null);
> > > > > writer.startElement(LABEL, component);
> > > > > writer.writeAttribute("for", component.getClientId() + ":" +
> > > > > itemNumber, "for");
> > > > > if (!curItem.isEscape())
> > > > > {
> > > > > // It seems the ResponseWriter API should
> > > > > // have a writeText() with a boolean property
> > > > > // to determine if it content written should
> > > > > // be escaped or not.
> > > > > writer.write(itemLabel);
> > > > > }
> > > > > else
> > > > > {
> > > > > writer.writeText(itemLabel, component, null);
> > > > > }
> > > > > writer.endElement(LABEL);
> > > > >
> > > > > isSelected(context, component, itemValue, valuesArray,
> > > > converter);
> > > > > // if (isSelected(context, component, itemValue,
> > > valuesArray,
> > > > > converter))
> > > > > // {
> > > > > // // selected
> > > > > // }
> > > > > // else
> > > > > // {
> > > > > // // not selected
> > > > > // }
> > > > > writer.endElement(TD);
> > > > >
> > > > > // starting the description td
> > > > > writer.startElement(TD, component);
> > > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > > >
> > > > > String itemLabelDesc = curItem.getDescription();
> > > > > if (itemLabelDesc == null)
> > > > > {
> > > > > itemLabelDesc = "";
> > > > > }
> > > > > writer.writeText(" ", component, null);
> > > > > if (!curItem.isEscape())
> > > > > {
> > > > > // It seems the ResponseWriter API should
> > > > > // have a writeText() with a boolean property
> > > > > // to determine if it content written should
> > > > > // be escaped or not.
> > > > > writer.write(itemLabelDesc);
> > > > > }
> > > > > else
> > > > > {
> > > > > writer.writeText(itemLabelDesc, component, null);
> > > > > }
> > > > >
> > > > > writer.endElement(TD);
> > > > >
> > > > > //--------------------------------------------------------
> > > > > // New stuff for event selecting end
> > > > > //--------------------------------------------------------
> > > > >
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.writeText(TAB, component, null);
> > > > > writer.endElement(TR);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > > }
> > > > >
> > > > >
> > > > > // ------------------------------------------------- Package
> > > Private
> > > > > Methods
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > String getSelectedTextString()
> > > > > {
> > > > > return "checked";
> > > > > }
> > > > > }
> > > > >
> > > > >
> > > > > Any help is appreciated!
> > > > > Thanks!
> > > > >
> > > > > René
> > > > >
> > > >
> > >
> >
>
Re: Re: Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Karl Kildén <ka...@gmail.com>.
Rene, I at least can't see anything.
Another thing to think about it what impl stuff you have actually worked
with? I mean mojarra should have about the same stuff as myfaces?
To make myself clear, what does the components and stuff you extend really
belong to? Shouldn't be impossible to find equivalents in myfaces...
On 14 February 2014 08:45, Rene Perschon <Ch...@gmx.net> wrote:
> Yes, here it is. It's a two-stage component which displays a hierarchical
> (2 levels) selection choice.
>
>
>
> Gesendet: Donnerstag, 13. Februar 2014 um 16:57 Uhr
> Von: "Howard W. Smith, Jr." <sm...@gmail.com>
> An: "MyFaces Discussion" <us...@myfaces.apache.org>
> Betreff: Re: Re: Problems with a custom component when migrating from
> Glassfish(mojarra) to TomEE
> do you have a screen capture or some type of demo of the Select component?
>
>
>
> On Thu, Feb 13, 2014 at 8:39 AM, Rene Perschon <Ch...@gmx.net>
> wrote:
>
> > I don't think a TagHandler or a custom component can do what that code
> > does. It's used to display a Select in a very specific way.
> >
> >
> >
> > Gesendet: Donnerstag, 13. Februar 2014 um 14:29 Uhr
> > Von: "Karl Kildén" <ka...@gmail.com>
> > An: "MyFaces Discussion" <us...@myfaces.apache.org>
> > Betreff: Re: Problems with a custom component when migrating from
> > Glassfish(mojarra) to TomEE
> > Have you considered a custom tagHandler / composite component instead?
> >
> > I took a quick look but I don't recognize much sorry.
> >
> >
> > On 13 February 2014 14:09, Howard W. Smith, Jr. <smithh032772@gmail.com
> > >wrote:
> >
> > > I think Leonardo, Gerhard, or one of the other committers may provide
> her
> > > some good help, just to get another MyFaces user, especially when one
> is
> > > migrating from Mojarra to MyFaces.
> > >
> > > @Renee, +1 your goal/request.
> > >
> > > I migrated from Mojarra to MyFaces, first, and then 2 months later, I
> > > migrated from Glassfish to tomee (and JSF managed beans to CDI managed
> > > beans at same time). Thomas, Romain, Mark Struberg, and others provided
> > > great help and motivation. Apache tomee, MyFaces, tomcat user mail
> lists
> > > are definitely the place to be.
> > >
> > > But I didn't have code dependent on the Mojarra library like you do.
> > Still,
> > > it took me about a week to migrate from Mojarra to MyFaces. Thomas and
> > > Leonardo motivated me to start the migration after reading about the
> > > performance comparison between Mojarra and MyFaces. Mark Struberg blog,
> > why
> > > is OpenWebBeans so fast, motivated me to migrate to CDI and tomee. :-)
> > >
> > > I love high performance, that's why I opted to use MyFaces, tomee,
> > > OpenWebBeans, and JUEL.
> > >
> > > Wishing you much success.
> > > On Feb 13, 2014 7:23 AM, "Thomas Andraschko" <
> > andraschko.thomas@gmail.com>
> > > wrote:
> > >
> > > > I don't think that anyone will port your complete code and give you a
> > > > complete solution ;)
> > > >
> > > > The biggest problem is AFAIR that the renderer implementations are
> not
> > in
> > > > the API packages. So you have to rebuild all this functionality
> without
> > > > dependencies to the Impl.
> > > >
> > > > e.g.
> > > > Attribute,AttributeManager -> String[] with attribute namens
> > > > Move all the utils functions to your own code
> > (Util.componentIsDisabled,
> > > > RenderKitUtils.getSelectItems. etc.)
> > > >
> > > > The most code doesn't really depent on the IMPL code.
> > > >
> > > >
> > > > 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> > > >
> > > > > Hi everyone!
> > > > >
> > > > > I'm currently migrating an application from Glassfish 3.1.1 to
> TomEE.
> > > Now
> > > > > the problem is that this application contains a custom component
> > which
> > > > was
> > > > > unfortunately coded with hard dependencies on com.sun.faces classes
> > > > (maven
> > > > > dependency jsf-impl).
> > > > >
> > > > > Now my question is how can i port this component in such a way that
> > it
> > > is
> > > > > independent from any concrete JSF implementation (or at least in
> > such a
> > > > way
> > > > > that it works with MyFaces).
> > > > >
> > > > > Here's the component:
> > > > >
> > > > > import java.io.IOException;
> > > > > import java.util.Iterator;
> > > > > import java.util.Map;
> > > > >
> > > > > import javax.faces.component.UIComponent;
> > > > > import javax.faces.component.UINamingContainer;
> > > > > import javax.faces.component.ValueHolder;
> > > > > import javax.faces.context.FacesContext;
> > > > > import javax.faces.context.ResponseWriter;
> > > > > import javax.faces.convert.Converter;
> > > > > import javax.faces.model.SelectItem;
> > > > > import javax.faces.model.SelectItemGroup;
> > > > >
> > > > > import com.sun.faces.renderkit.Attribute;
> > > > > import com.sun.faces.renderkit.AttributeManager;
> > > > > import com.sun.faces.renderkit.RenderKitUtils;
> > > > > import com.sun.faces.renderkit.html_basic.MenuRenderer;
> > > > > import com.sun.faces.util.RequestStateManager;
> > > > > import com.sun.faces.util.Util;
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}.
> > > > > */
> > > > > public class CustomSelectManyCheckboxListRenderer extends
> > MenuRenderer
> > > > > {
> > > > > /** {@inheritDoc}. */
> > > > > private static final Attribute[] ATTRIBUTES =
> > > > >
> > >
> AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> > > > > /** Representing the border string. */
> > > > > private static final String BORDER = "border";
> > > > > /** Representing the tr string. */
> > > > > private static final String TR = "tr";
> > > > > /** Representing the td string. */
> > > > > private static final String TD = "td";
> > > > > /** Representing the label string. */
> > > > > private static final String LABEL = "label";
> > > > > /** Representing the newline string. */
> > > > > private static final String NEWLINE = "\n";
> > > > > /** Representing the tab string. */
> > > > > private static final String TAB = "\t";
> > > > > /** Representing the class string. */
> > > > > private static final String CLASS = "class";
> > > > > /** Representing the style string. */
> > > > > private static final String STYLE = "style";
> > > > > /** Representing the valign string. */
> > > > > private static final String VALIGN = "valign";
> > > > >
> > > > >
> > > > > // ----------------------------------------------------------
> > > Public
> > > > > Methods
> > > > >
> > > > >
> > > > > @Override
> > > > > public void encodeEnd(FacesContext context, UIComponent component)
> > > > > throws IOException
> > > > > {
> > > > >
> > > > > rendererParamsNotNull(context, component);
> > > > >
> > > > > if (!shouldEncode(component))
> > > > > {
> > > > > return;
> > > > > }
> > > > >
> > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > assert (writer != null);
> > > > >
> > > > > String alignStr;
> > > > > Object borderObj;
> > > > > boolean alignVertical = false;
> > > > > int border = 0;
> > > > >
> > > > >
> > > > >
> > > > > if (null != component.getAttributes().get("layout"))
> > > > > {
> > > > > alignStr = (String)
> > > component.getAttributes().get("layout");
> > > > > alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> > > > > }
> > > > >
> > > > > if (null != component.getAttributes().get(BORDER))
> > > > > {
> > > > > borderObj = component.getAttributes().get(BORDER);
> > > > > border = (Integer) borderObj;
> > > > > }
> > > > >
> > > > > Converter converter = null;
> > > > > if (component instanceof ValueHolder)
> > > > > {
> > > > > converter = ((ValueHolder)component).getConverter();
> > > > > }
> > > > >
> > > > > renderBeginText(component, border, alignVertical, context,
> > > true);
> > > > >
> > > > > Iterator<SelectItem> items =
> > > > > RenderKitUtils.getSelectItems(context, component);
> > > > >
> > > > > Object currentSelections = getCurrentSelectedValues(component);
> > > > > Object[] submittedValues =
> > > getSubmittedSelectedValues(component);
> > > > > Map<String, Object> attributes = component.getAttributes();
> > > > > OptionComponentInfo optionInfo =
> > > > > new OptionComponentInfo((String)
> > > > > attributes.get("disabledClass"),
> > > > > (String)
> > > > > attributes.get("enabledClass"),
> > > > > (String)
> > > > > attributes.get("unselectedClass"),
> > > > > (String)
> > > > > attributes.get("selectedClass"),
> > > > >
> > > > Util.componentIsDisabled(component),
> > > > > isHideNoSelection(component));
> > > > > int idx = -1;
> > > > > while (items.hasNext())
> > > > > {
> > > > > SelectItem curItem = items.next();
> > > > > idx++;
> > > > > // If we come across a group of options, render them as a
> > > > > nested
> > > > > // table.
> > > > > if (curItem instanceof SelectItemGroup)
> > > > > {
> > > > > // write out the label for the group.
> > > > > if (curItem.getLabel() != null)
> > > > > {
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.startElement(TR, component);
> > > > > }
> > > > > writer.startElement(TD, component);
> > > > > writer.writeText(curItem.getLabel(), component,
> > > > LABEL);
> > > > > writer.endElement(TD);
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.endElement(TR);
> > > > > }
> > > > >
> > > > > }
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.startElement(TR, component);
> > > > > }
> > > > > writer.startElement(TD, component);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > renderBeginText(component, 0, alignVertical,
> > > > > context, false);
> > > > > // render options of this group.
> > > > > SelectItem[] itemsArray =
> > > > > ((SelectItemGroup) curItem).getSelectItems();
> > > > > for (int i = 0; i < itemsArray.length; ++i)
> > > > > {
> > > > > renderOption(context,
> > > > > component,
> > > > > converter,
> > > > > itemsArray[i],
> > > > > currentSelections,
> > > > > submittedValues,
> > > > > alignVertical,
> > > > > i,
> > > > > optionInfo);
> > > > > }
> > > > > renderEndText(component, alignVertical, context);
> > > > > writer.endElement(TD);
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.endElement(TR);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > > }
> > > > > else
> > > > > {
> > > > > renderOption(context,
> > > > > component,
> > > > > converter,
> > > > > curItem,
> > > > > currentSelections,
> > > > > submittedValues,
> > > > > alignVertical,
> > > > > idx,
> > > > > optionInfo);
> > > > > }
> > > > > }
> > > > >
> > > > > renderEndText(component, alignVertical, context);
> > > > >
> > > > > }
> > > > >
> > > > > // -------------------------------------------------------
> > > Protected
> > > > > Methods
> > > > >
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > @Override
> > > > > protected boolean isBehaviorSource(FacesContext ctx,
> > > > > String behaviorSourceId,
> > > > > String componentClientId)
> > > > > {
> > > > >
> > > > > if (behaviorSourceId == null)
> > > > > {
> > > > > return false;
> > > > > }
> > > > > char sepChar = UINamingContainer.getSeparatorChar(ctx);
> > > > > String actualBehaviorId =
> > > > > behaviorSourceId.substring(0,
> > > > > behaviorSourceId.lastIndexOf(sepChar));
> > > > > return (actualBehaviorId.equals(componentClientId));
> > > > >
> > > > > }
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > protected void renderBeginText(UIComponent component, int border,
> > > > > boolean alignVertical, FacesContext
> > > > > context,
> > > > > boolean outerTable) throws
> > > IOException
> > > > > {
> > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > assert (writer != null);
> > > > >
> > > > > writer.startElement("table", component);
> > > > > if (border != Integer.MIN_VALUE)
> > > > > {
> > > > > writer.writeAttribute(BORDER, border, BORDER);
> > > > > }
> > > > >
> > > > > // render style and styleclass attribute on the outer table
> > > > > instead of
> > > > > // rendering it as pass through attribute on every option in
> > > the
> > > > > list.
> > > > > if (outerTable)
> > > > > {
> > > > > // render "id" only for outerTable.
> > > > > if (shouldWriteIdAttribute(component))
> > > > > {
> > > > > writeIdAttributeIfNecessary(context, writer,
> > > component);
> > > > > }
> > > > > String styleClass = (String) component.getAttributes().get(
> > > > > "styleClass");
> > > > > String style = (String)
> > > component.getAttributes().get(STYLE);
> > > > > if (styleClass != null)
> > > > > {
> > > > > writer.writeAttribute(CLASS, styleClass, CLASS);
> > > > > }
> > > > > if (style != null)
> > > > > {
> > > > > writer.writeAttribute(STYLE, style, STYLE);
> > > > > }
> > > > > }
> > > > > writer.writeText(NEWLINE, component, null);
> > > > >
> > > > > if (!alignVertical)
> > > > > {
> > > > > writer.writeText(TAB, component, null);
> > > > > writer.startElement(TR, component);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > protected void renderEndText(UIComponent component,
> > > > > boolean alignVertical,
> > > > > FacesContext context) throws
> > > IOException
> > > > > {
> > > > >
> > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > assert (writer != null);
> > > > >
> > > > > if (!alignVertical)
> > > > > {
> > > > > writer.writeText(TAB, component, null);
> > > > > writer.endElement(TR);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > > writer.endElement("table");
> > > > >
> > > > > }
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > protected void renderOption(FacesContext context,
> > > > > UIComponent component,
> > > > > Converter converter,
> > > > > SelectItem curItem,
> > > > > Object currentSelections,
> > > > > Object[] submittedValues,
> > > > > boolean alignVertical,
> > > > > int itemNumber,
> > > > > OptionComponentInfo optionInfo) throws
> > > > > IOException
> > > > > {
> > > > >
> > > > > String valueString = getFormattedValue(context, component,
> > > > > curItem.getValue(),
> > > > > converter);
> > > > >
> > > > > Object valuesArray;
> > > > > Object itemValue;
> > > > > if (submittedValues != null)
> > > > > {
> > > > > valuesArray = submittedValues;
> > > > > itemValue = valueString;
> > > > > }
> > > > > else
> > > > > {
> > > > > valuesArray = currentSelections;
> > > > > itemValue = curItem.getValue();
> > > > > }
> > > > >
> > > > > RequestStateManager.set(context,
> > > > >
> > > > > RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> > > > > component);
> > > > >
> > > > > boolean isSelected = isSelected(context, component, itemValue,
> > > > > valuesArray, converter);
> > > > > if (optionInfo.isHideNoSelection() &&
> > > > > curItem.isNoSelectionOption() &&
> > > > > currentSelections != null &&
> > > > > !isSelected)
> > > > > {
> > > > > return;
> > > > > }
> > > > >
> > > > > ResponseWriter writer = context.getResponseWriter();
> > > > > assert (writer != null);
> > > > >
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.writeText(TAB, component, null);
> > > > > writer.startElement(TR, component);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > > writer.startElement(TD, component);
> > > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > >
> > > > > writer.startElement("input", component);
> > > > > writer.writeAttribute("name", component.getClientId(context),
> > > > > "clientId");
> > > > > String idString = component.getClientId(context) +
> > > > > UINamingContainer.getSeparatorChar(context) +
> > > > > Integer.toString(itemNumber);
> > > > > writer.writeAttribute("id", idString, "id");
> > > > >
> > > > > writer.writeAttribute("value", valueString, "value");
> > > > > writer.writeAttribute("type", "checkbox", null);
> > > > >
> > > > > if (isSelected)
> > > > > {
> > > > > writer.writeAttribute(getSelectedTextString(),
> > > Boolean.TRUE,
> > > > > null);
> > > > > }
> > > > >
> > > > > // Don't render the disabled attribute twice if the 'parent'
> > > > > // component is already marked disabled.
> > > > > if (!optionInfo.isDisabled())
> > > > > {
> > > > > if (curItem.isDisabled())
> > > > > {
> > > > > writer.writeAttribute("disabled", true, "disabled");
> > > > > }
> > > > > }
> > > > >
> > > > > // Apply HTML 4.x attributes specified on UISelectMany
> > > component
> > > > > to all
> > > > > // items in the list except styleClass and style which are
> > > > > rendered as
> > > > > // attributes of outer most table.
> > > > > RenderKitUtils.renderPassThruAttributes(context,
> > > > > writer,
> > > > > component,
> > > > > ATTRIBUTES,
> > > > >
> > > > > getNonOnClickSelectBehaviors(component));
> > > > >
> > > > > RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> > > > > component);
> > > > >
> > > > > RenderKitUtils.renderSelectOnclick(context, component, true);
> > > > >
> > > > > writer.endElement("input");
> > > > >
> > > > > //--------------------------------------------------------
> > > > > // New stuff for event selecting
> > > > > //--------------------------------------------------------
> > > > >
> > > > > writer.endElement(TD);
> > > > >
> > > > > // starting the label td
> > > > > writer.startElement(TD, component);
> > > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > > writer.writeAttribute("width", "80px", "width");
> > > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > > >
> > > > > String itemLabel = curItem.getLabel();
> > > > > if (itemLabel == null)
> > > > > {
> > > > > itemLabel = valueString;
> > > > > }
> > > > >
> > > > > writer.writeText(" ", component, null);
> > > > > writer.startElement(LABEL, component);
> > > > > writer.writeAttribute("for", component.getClientId() + ":" +
> > > > > itemNumber, "for");
> > > > > if (!curItem.isEscape())
> > > > > {
> > > > > // It seems the ResponseWriter API should
> > > > > // have a writeText() with a boolean property
> > > > > // to determine if it content written should
> > > > > // be escaped or not.
> > > > > writer.write(itemLabel);
> > > > > }
> > > > > else
> > > > > {
> > > > > writer.writeText(itemLabel, component, null);
> > > > > }
> > > > > writer.endElement(LABEL);
> > > > >
> > > > > isSelected(context, component, itemValue, valuesArray,
> > > > converter);
> > > > > // if (isSelected(context, component, itemValue,
> > > valuesArray,
> > > > > converter))
> > > > > // {
> > > > > // // selected
> > > > > // }
> > > > > // else
> > > > > // {
> > > > > // // not selected
> > > > > // }
> > > > > writer.endElement(TD);
> > > > >
> > > > > // starting the description td
> > > > > writer.startElement(TD, component);
> > > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > > >
> > > > > String itemLabelDesc = curItem.getDescription();
> > > > > if (itemLabelDesc == null)
> > > > > {
> > > > > itemLabelDesc = "";
> > > > > }
> > > > > writer.writeText(" ", component, null);
> > > > > if (!curItem.isEscape())
> > > > > {
> > > > > // It seems the ResponseWriter API should
> > > > > // have a writeText() with a boolean property
> > > > > // to determine if it content written should
> > > > > // be escaped or not.
> > > > > writer.write(itemLabelDesc);
> > > > > }
> > > > > else
> > > > > {
> > > > > writer.writeText(itemLabelDesc, component, null);
> > > > > }
> > > > >
> > > > > writer.endElement(TD);
> > > > >
> > > > > //--------------------------------------------------------
> > > > > // New stuff for event selecting end
> > > > > //--------------------------------------------------------
> > > > >
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > if (alignVertical)
> > > > > {
> > > > > writer.writeText(TAB, component, null);
> > > > > writer.endElement(TR);
> > > > > writer.writeText(NEWLINE, component, null);
> > > > > }
> > > > > }
> > > > >
> > > > >
> > > > > // ------------------------------------------------- Package
> > > Private
> > > > > Methods
> > > > >
> > > > > /**
> > > > > * {@inheritDoc}
> > > > > */
> > > > > String getSelectedTextString()
> > > > > {
> > > > > return "checked";
> > > > > }
> > > > > }
> > > > >
> > > > >
> > > > > Any help is appreciated!
> > > > > Thanks!
> > > > >
> > > > > René
> > > > >
> > > >
> > >
> >
>
Aw: Re: Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Rene Perschon <Ch...@gmx.net>.
Yes, here it is. It's a two-stage component which displays a hierarchical (2 levels) selection choice.
Gesendet: Donnerstag, 13. Februar 2014 um 16:57 Uhr
Von: "Howard W. Smith, Jr." <sm...@gmail.com>
An: "MyFaces Discussion" <us...@myfaces.apache.org>
Betreff: Re: Re: Problems with a custom component when migrating from Glassfish(mojarra) to TomEE
do you have a screen capture or some type of demo of the Select component?
On Thu, Feb 13, 2014 at 8:39 AM, Rene Perschon <Ch...@gmx.net> wrote:
> I don't think a TagHandler or a custom component can do what that code
> does. It's used to display a Select in a very specific way.
>
>
>
> Gesendet: Donnerstag, 13. Februar 2014 um 14:29 Uhr
> Von: "Karl Kildén" <ka...@gmail.com>
> An: "MyFaces Discussion" <us...@myfaces.apache.org>
> Betreff: Re: Problems with a custom component when migrating from
> Glassfish(mojarra) to TomEE
> Have you considered a custom tagHandler / composite component instead?
>
> I took a quick look but I don't recognize much sorry.
>
>
> On 13 February 2014 14:09, Howard W. Smith, Jr. <smithh032772@gmail.com
> >wrote:
>
> > I think Leonardo, Gerhard, or one of the other committers may provide her
> > some good help, just to get another MyFaces user, especially when one is
> > migrating from Mojarra to MyFaces.
> >
> > @Renee, +1 your goal/request.
> >
> > I migrated from Mojarra to MyFaces, first, and then 2 months later, I
> > migrated from Glassfish to tomee (and JSF managed beans to CDI managed
> > beans at same time). Thomas, Romain, Mark Struberg, and others provided
> > great help and motivation. Apache tomee, MyFaces, tomcat user mail lists
> > are definitely the place to be.
> >
> > But I didn't have code dependent on the Mojarra library like you do.
> Still,
> > it took me about a week to migrate from Mojarra to MyFaces. Thomas and
> > Leonardo motivated me to start the migration after reading about the
> > performance comparison between Mojarra and MyFaces. Mark Struberg blog,
> why
> > is OpenWebBeans so fast, motivated me to migrate to CDI and tomee. :-)
> >
> > I love high performance, that's why I opted to use MyFaces, tomee,
> > OpenWebBeans, and JUEL.
> >
> > Wishing you much success.
> > On Feb 13, 2014 7:23 AM, "Thomas Andraschko" <
> andraschko.thomas@gmail.com>
> > wrote:
> >
> > > I don't think that anyone will port your complete code and give you a
> > > complete solution ;)
> > >
> > > The biggest problem is AFAIR that the renderer implementations are not
> in
> > > the API packages. So you have to rebuild all this functionality without
> > > dependencies to the Impl.
> > >
> > > e.g.
> > > Attribute,AttributeManager -> String[] with attribute namens
> > > Move all the utils functions to your own code
> (Util.componentIsDisabled,
> > > RenderKitUtils.getSelectItems. etc.)
> > >
> > > The most code doesn't really depent on the IMPL code.
> > >
> > >
> > > 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> > >
> > > > Hi everyone!
> > > >
> > > > I'm currently migrating an application from Glassfish 3.1.1 to TomEE.
> > Now
> > > > the problem is that this application contains a custom component
> which
> > > was
> > > > unfortunately coded with hard dependencies on com.sun.faces classes
> > > (maven
> > > > dependency jsf-impl).
> > > >
> > > > Now my question is how can i port this component in such a way that
> it
> > is
> > > > independent from any concrete JSF implementation (or at least in
> such a
> > > way
> > > > that it works with MyFaces).
> > > >
> > > > Here's the component:
> > > >
> > > > import java.io.IOException;
> > > > import java.util.Iterator;
> > > > import java.util.Map;
> > > >
> > > > import javax.faces.component.UIComponent;
> > > > import javax.faces.component.UINamingContainer;
> > > > import javax.faces.component.ValueHolder;
> > > > import javax.faces.context.FacesContext;
> > > > import javax.faces.context.ResponseWriter;
> > > > import javax.faces.convert.Converter;
> > > > import javax.faces.model.SelectItem;
> > > > import javax.faces.model.SelectItemGroup;
> > > >
> > > > import com.sun.faces.renderkit.Attribute;
> > > > import com.sun.faces.renderkit.AttributeManager;
> > > > import com.sun.faces.renderkit.RenderKitUtils;
> > > > import com.sun.faces.renderkit.html_basic.MenuRenderer;
> > > > import com.sun.faces.util.RequestStateManager;
> > > > import com.sun.faces.util.Util;
> > > >
> > > > /**
> > > > * {@inheritDoc}.
> > > > */
> > > > public class CustomSelectManyCheckboxListRenderer extends
> MenuRenderer
> > > > {
> > > > /** {@inheritDoc}. */
> > > > private static final Attribute[] ATTRIBUTES =
> > > >
> > AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> > > > /** Representing the border string. */
> > > > private static final String BORDER = "border";
> > > > /** Representing the tr string. */
> > > > private static final String TR = "tr";
> > > > /** Representing the td string. */
> > > > private static final String TD = "td";
> > > > /** Representing the label string. */
> > > > private static final String LABEL = "label";
> > > > /** Representing the newline string. */
> > > > private static final String NEWLINE = "\n";
> > > > /** Representing the tab string. */
> > > > private static final String TAB = "\t";
> > > > /** Representing the class string. */
> > > > private static final String CLASS = "class";
> > > > /** Representing the style string. */
> > > > private static final String STYLE = "style";
> > > > /** Representing the valign string. */
> > > > private static final String VALIGN = "valign";
> > > >
> > > >
> > > > // ----------------------------------------------------------
> > Public
> > > > Methods
> > > >
> > > >
> > > > @Override
> > > > public void encodeEnd(FacesContext context, UIComponent component)
> > > > throws IOException
> > > > {
> > > >
> > > > rendererParamsNotNull(context, component);
> > > >
> > > > if (!shouldEncode(component))
> > > > {
> > > > return;
> > > > }
> > > >
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > String alignStr;
> > > > Object borderObj;
> > > > boolean alignVertical = false;
> > > > int border = 0;
> > > >
> > > >
> > > >
> > > > if (null != component.getAttributes().get("layout"))
> > > > {
> > > > alignStr = (String)
> > component.getAttributes().get("layout");
> > > > alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> > > > }
> > > >
> > > > if (null != component.getAttributes().get(BORDER))
> > > > {
> > > > borderObj = component.getAttributes().get(BORDER);
> > > > border = (Integer) borderObj;
> > > > }
> > > >
> > > > Converter converter = null;
> > > > if (component instanceof ValueHolder)
> > > > {
> > > > converter = ((ValueHolder)component).getConverter();
> > > > }
> > > >
> > > > renderBeginText(component, border, alignVertical, context,
> > true);
> > > >
> > > > Iterator<SelectItem> items =
> > > > RenderKitUtils.getSelectItems(context, component);
> > > >
> > > > Object currentSelections = getCurrentSelectedValues(component);
> > > > Object[] submittedValues =
> > getSubmittedSelectedValues(component);
> > > > Map<String, Object> attributes = component.getAttributes();
> > > > OptionComponentInfo optionInfo =
> > > > new OptionComponentInfo((String)
> > > > attributes.get("disabledClass"),
> > > > (String)
> > > > attributes.get("enabledClass"),
> > > > (String)
> > > > attributes.get("unselectedClass"),
> > > > (String)
> > > > attributes.get("selectedClass"),
> > > >
> > > Util.componentIsDisabled(component),
> > > > isHideNoSelection(component));
> > > > int idx = -1;
> > > > while (items.hasNext())
> > > > {
> > > > SelectItem curItem = items.next();
> > > > idx++;
> > > > // If we come across a group of options, render them as a
> > > > nested
> > > > // table.
> > > > if (curItem instanceof SelectItemGroup)
> > > > {
> > > > // write out the label for the group.
> > > > if (curItem.getLabel() != null)
> > > > {
> > > > if (alignVertical)
> > > > {
> > > > writer.startElement(TR, component);
> > > > }
> > > > writer.startElement(TD, component);
> > > > writer.writeText(curItem.getLabel(), component,
> > > LABEL);
> > > > writer.endElement(TD);
> > > > if (alignVertical)
> > > > {
> > > > writer.endElement(TR);
> > > > }
> > > >
> > > > }
> > > > if (alignVertical)
> > > > {
> > > > writer.startElement(TR, component);
> > > > }
> > > > writer.startElement(TD, component);
> > > > writer.writeText(NEWLINE, component, null);
> > > > renderBeginText(component, 0, alignVertical,
> > > > context, false);
> > > > // render options of this group.
> > > > SelectItem[] itemsArray =
> > > > ((SelectItemGroup) curItem).getSelectItems();
> > > > for (int i = 0; i < itemsArray.length; ++i)
> > > > {
> > > > renderOption(context,
> > > > component,
> > > > converter,
> > > > itemsArray[i],
> > > > currentSelections,
> > > > submittedValues,
> > > > alignVertical,
> > > > i,
> > > > optionInfo);
> > > > }
> > > > renderEndText(component, alignVertical, context);
> > > > writer.endElement(TD);
> > > > if (alignVertical)
> > > > {
> > > > writer.endElement(TR);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > }
> > > > else
> > > > {
> > > > renderOption(context,
> > > > component,
> > > > converter,
> > > > curItem,
> > > > currentSelections,
> > > > submittedValues,
> > > > alignVertical,
> > > > idx,
> > > > optionInfo);
> > > > }
> > > > }
> > > >
> > > > renderEndText(component, alignVertical, context);
> > > >
> > > > }
> > > >
> > > > // -------------------------------------------------------
> > Protected
> > > > Methods
> > > >
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > @Override
> > > > protected boolean isBehaviorSource(FacesContext ctx,
> > > > String behaviorSourceId,
> > > > String componentClientId)
> > > > {
> > > >
> > > > if (behaviorSourceId == null)
> > > > {
> > > > return false;
> > > > }
> > > > char sepChar = UINamingContainer.getSeparatorChar(ctx);
> > > > String actualBehaviorId =
> > > > behaviorSourceId.substring(0,
> > > > behaviorSourceId.lastIndexOf(sepChar));
> > > > return (actualBehaviorId.equals(componentClientId));
> > > >
> > > > }
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > protected void renderBeginText(UIComponent component, int border,
> > > > boolean alignVertical, FacesContext
> > > > context,
> > > > boolean outerTable) throws
> > IOException
> > > > {
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > writer.startElement("table", component);
> > > > if (border != Integer.MIN_VALUE)
> > > > {
> > > > writer.writeAttribute(BORDER, border, BORDER);
> > > > }
> > > >
> > > > // render style and styleclass attribute on the outer table
> > > > instead of
> > > > // rendering it as pass through attribute on every option in
> > the
> > > > list.
> > > > if (outerTable)
> > > > {
> > > > // render "id" only for outerTable.
> > > > if (shouldWriteIdAttribute(component))
> > > > {
> > > > writeIdAttributeIfNecessary(context, writer,
> > component);
> > > > }
> > > > String styleClass = (String) component.getAttributes().get(
> > > > "styleClass");
> > > > String style = (String)
> > component.getAttributes().get(STYLE);
> > > > if (styleClass != null)
> > > > {
> > > > writer.writeAttribute(CLASS, styleClass, CLASS);
> > > > }
> > > > if (style != null)
> > > > {
> > > > writer.writeAttribute(STYLE, style, STYLE);
> > > > }
> > > > }
> > > > writer.writeText(NEWLINE, component, null);
> > > >
> > > > if (!alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.startElement(TR, component);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > >
> > > > }
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > protected void renderEndText(UIComponent component,
> > > > boolean alignVertical,
> > > > FacesContext context) throws
> > IOException
> > > > {
> > > >
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > if (!alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.endElement(TR);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > writer.endElement("table");
> > > >
> > > > }
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > protected void renderOption(FacesContext context,
> > > > UIComponent component,
> > > > Converter converter,
> > > > SelectItem curItem,
> > > > Object currentSelections,
> > > > Object[] submittedValues,
> > > > boolean alignVertical,
> > > > int itemNumber,
> > > > OptionComponentInfo optionInfo) throws
> > > > IOException
> > > > {
> > > >
> > > > String valueString = getFormattedValue(context, component,
> > > > curItem.getValue(),
> > > > converter);
> > > >
> > > > Object valuesArray;
> > > > Object itemValue;
> > > > if (submittedValues != null)
> > > > {
> > > > valuesArray = submittedValues;
> > > > itemValue = valueString;
> > > > }
> > > > else
> > > > {
> > > > valuesArray = currentSelections;
> > > > itemValue = curItem.getValue();
> > > > }
> > > >
> > > > RequestStateManager.set(context,
> > > >
> > > > RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> > > > component);
> > > >
> > > > boolean isSelected = isSelected(context, component, itemValue,
> > > > valuesArray, converter);
> > > > if (optionInfo.isHideNoSelection() &&
> > > > curItem.isNoSelectionOption() &&
> > > > currentSelections != null &&
> > > > !isSelected)
> > > > {
> > > > return;
> > > > }
> > > >
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > if (alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.startElement(TR, component);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > writer.startElement(TD, component);
> > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > writer.writeText(NEWLINE, component, null);
> > > >
> > > > writer.startElement("input", component);
> > > > writer.writeAttribute("name", component.getClientId(context),
> > > > "clientId");
> > > > String idString = component.getClientId(context) +
> > > > UINamingContainer.getSeparatorChar(context) +
> > > > Integer.toString(itemNumber);
> > > > writer.writeAttribute("id", idString, "id");
> > > >
> > > > writer.writeAttribute("value", valueString, "value");
> > > > writer.writeAttribute("type", "checkbox", null);
> > > >
> > > > if (isSelected)
> > > > {
> > > > writer.writeAttribute(getSelectedTextString(),
> > Boolean.TRUE,
> > > > null);
> > > > }
> > > >
> > > > // Don't render the disabled attribute twice if the 'parent'
> > > > // component is already marked disabled.
> > > > if (!optionInfo.isDisabled())
> > > > {
> > > > if (curItem.isDisabled())
> > > > {
> > > > writer.writeAttribute("disabled", true, "disabled");
> > > > }
> > > > }
> > > >
> > > > // Apply HTML 4.x attributes specified on UISelectMany
> > component
> > > > to all
> > > > // items in the list except styleClass and style which are
> > > > rendered as
> > > > // attributes of outer most table.
> > > > RenderKitUtils.renderPassThruAttributes(context,
> > > > writer,
> > > > component,
> > > > ATTRIBUTES,
> > > >
> > > > getNonOnClickSelectBehaviors(component));
> > > >
> > > > RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> > > > component);
> > > >
> > > > RenderKitUtils.renderSelectOnclick(context, component, true);
> > > >
> > > > writer.endElement("input");
> > > >
> > > > //--------------------------------------------------------
> > > > // New stuff for event selecting
> > > > //--------------------------------------------------------
> > > >
> > > > writer.endElement(TD);
> > > >
> > > > // starting the label td
> > > > writer.startElement(TD, component);
> > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > writer.writeAttribute("width", "80px", "width");
> > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > >
> > > > String itemLabel = curItem.getLabel();
> > > > if (itemLabel == null)
> > > > {
> > > > itemLabel = valueString;
> > > > }
> > > >
> > > > writer.writeText(" ", component, null);
> > > > writer.startElement(LABEL, component);
> > > > writer.writeAttribute("for", component.getClientId() + ":" +
> > > > itemNumber, "for");
> > > > if (!curItem.isEscape())
> > > > {
> > > > // It seems the ResponseWriter API should
> > > > // have a writeText() with a boolean property
> > > > // to determine if it content written should
> > > > // be escaped or not.
> > > > writer.write(itemLabel);
> > > > }
> > > > else
> > > > {
> > > > writer.writeText(itemLabel, component, null);
> > > > }
> > > > writer.endElement(LABEL);
> > > >
> > > > isSelected(context, component, itemValue, valuesArray,
> > > converter);
> > > > // if (isSelected(context, component, itemValue,
> > valuesArray,
> > > > converter))
> > > > // {
> > > > // // selected
> > > > // }
> > > > // else
> > > > // {
> > > > // // not selected
> > > > // }
> > > > writer.endElement(TD);
> > > >
> > > > // starting the description td
> > > > writer.startElement(TD, component);
> > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > >
> > > > String itemLabelDesc = curItem.getDescription();
> > > > if (itemLabelDesc == null)
> > > > {
> > > > itemLabelDesc = "";
> > > > }
> > > > writer.writeText(" ", component, null);
> > > > if (!curItem.isEscape())
> > > > {
> > > > // It seems the ResponseWriter API should
> > > > // have a writeText() with a boolean property
> > > > // to determine if it content written should
> > > > // be escaped or not.
> > > > writer.write(itemLabelDesc);
> > > > }
> > > > else
> > > > {
> > > > writer.writeText(itemLabelDesc, component, null);
> > > > }
> > > >
> > > > writer.endElement(TD);
> > > >
> > > > //--------------------------------------------------------
> > > > // New stuff for event selecting end
> > > > //--------------------------------------------------------
> > > >
> > > > writer.writeText(NEWLINE, component, null);
> > > > if (alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.endElement(TR);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > }
> > > >
> > > >
> > > > // ------------------------------------------------- Package
> > Private
> > > > Methods
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > String getSelectedTextString()
> > > > {
> > > > return "checked";
> > > > }
> > > > }
> > > >
> > > >
> > > > Any help is appreciated!
> > > > Thanks!
> > > >
> > > > René
> > > >
> > >
> >
>
Aw: Re: Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Rene Perschon <Ch...@gmx.net>.
of course, no attachments....
https://dl.dropboxusercontent.com/u/16379590/screens/custom_1.png
https://dl.dropboxusercontent.com/u/16379590/screens/custom_2.png
Gesendet: Donnerstag, 13. Februar 2014 um 16:57 Uhr
Von: "Howard W. Smith, Jr." <sm...@gmail.com>
An: "MyFaces Discussion" <us...@myfaces.apache.org>
Betreff: Re: Re: Problems with a custom component when migrating from Glassfish(mojarra) to TomEE
do you have a screen capture or some type of demo of the Select component?
On Thu, Feb 13, 2014 at 8:39 AM, Rene Perschon <Ch...@gmx.net> wrote:
> I don't think a TagHandler or a custom component can do what that code
> does. It's used to display a Select in a very specific way.
>
>
>
> Gesendet: Donnerstag, 13. Februar 2014 um 14:29 Uhr
> Von: "Karl Kildén" <ka...@gmail.com>
> An: "MyFaces Discussion" <us...@myfaces.apache.org>
> Betreff: Re: Problems with a custom component when migrating from
> Glassfish(mojarra) to TomEE
> Have you considered a custom tagHandler / composite component instead?
>
> I took a quick look but I don't recognize much sorry.
>
>
> On 13 February 2014 14:09, Howard W. Smith, Jr. <smithh032772@gmail.com
> >wrote:
>
> > I think Leonardo, Gerhard, or one of the other committers may provide her
> > some good help, just to get another MyFaces user, especially when one is
> > migrating from Mojarra to MyFaces.
> >
> > @Renee, +1 your goal/request.
> >
> > I migrated from Mojarra to MyFaces, first, and then 2 months later, I
> > migrated from Glassfish to tomee (and JSF managed beans to CDI managed
> > beans at same time). Thomas, Romain, Mark Struberg, and others provided
> > great help and motivation. Apache tomee, MyFaces, tomcat user mail lists
> > are definitely the place to be.
> >
> > But I didn't have code dependent on the Mojarra library like you do.
> Still,
> > it took me about a week to migrate from Mojarra to MyFaces. Thomas and
> > Leonardo motivated me to start the migration after reading about the
> > performance comparison between Mojarra and MyFaces. Mark Struberg blog,
> why
> > is OpenWebBeans so fast, motivated me to migrate to CDI and tomee. :-)
> >
> > I love high performance, that's why I opted to use MyFaces, tomee,
> > OpenWebBeans, and JUEL.
> >
> > Wishing you much success.
> > On Feb 13, 2014 7:23 AM, "Thomas Andraschko" <
> andraschko.thomas@gmail.com>
> > wrote:
> >
> > > I don't think that anyone will port your complete code and give you a
> > > complete solution ;)
> > >
> > > The biggest problem is AFAIR that the renderer implementations are not
> in
> > > the API packages. So you have to rebuild all this functionality without
> > > dependencies to the Impl.
> > >
> > > e.g.
> > > Attribute,AttributeManager -> String[] with attribute namens
> > > Move all the utils functions to your own code
> (Util.componentIsDisabled,
> > > RenderKitUtils.getSelectItems. etc.)
> > >
> > > The most code doesn't really depent on the IMPL code.
> > >
> > >
> > > 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> > >
> > > > Hi everyone!
> > > >
> > > > I'm currently migrating an application from Glassfish 3.1.1 to TomEE.
> > Now
> > > > the problem is that this application contains a custom component
> which
> > > was
> > > > unfortunately coded with hard dependencies on com.sun.faces classes
> > > (maven
> > > > dependency jsf-impl).
> > > >
> > > > Now my question is how can i port this component in such a way that
> it
> > is
> > > > independent from any concrete JSF implementation (or at least in
> such a
> > > way
> > > > that it works with MyFaces).
> > > >
> > > > Here's the component:
> > > >
> > > > import java.io.IOException;
> > > > import java.util.Iterator;
> > > > import java.util.Map;
> > > >
> > > > import javax.faces.component.UIComponent;
> > > > import javax.faces.component.UINamingContainer;
> > > > import javax.faces.component.ValueHolder;
> > > > import javax.faces.context.FacesContext;
> > > > import javax.faces.context.ResponseWriter;
> > > > import javax.faces.convert.Converter;
> > > > import javax.faces.model.SelectItem;
> > > > import javax.faces.model.SelectItemGroup;
> > > >
> > > > import com.sun.faces.renderkit.Attribute;
> > > > import com.sun.faces.renderkit.AttributeManager;
> > > > import com.sun.faces.renderkit.RenderKitUtils;
> > > > import com.sun.faces.renderkit.html_basic.MenuRenderer;
> > > > import com.sun.faces.util.RequestStateManager;
> > > > import com.sun.faces.util.Util;
> > > >
> > > > /**
> > > > * {@inheritDoc}.
> > > > */
> > > > public class CustomSelectManyCheckboxListRenderer extends
> MenuRenderer
> > > > {
> > > > /** {@inheritDoc}. */
> > > > private static final Attribute[] ATTRIBUTES =
> > > >
> > AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> > > > /** Representing the border string. */
> > > > private static final String BORDER = "border";
> > > > /** Representing the tr string. */
> > > > private static final String TR = "tr";
> > > > /** Representing the td string. */
> > > > private static final String TD = "td";
> > > > /** Representing the label string. */
> > > > private static final String LABEL = "label";
> > > > /** Representing the newline string. */
> > > > private static final String NEWLINE = "\n";
> > > > /** Representing the tab string. */
> > > > private static final String TAB = "\t";
> > > > /** Representing the class string. */
> > > > private static final String CLASS = "class";
> > > > /** Representing the style string. */
> > > > private static final String STYLE = "style";
> > > > /** Representing the valign string. */
> > > > private static final String VALIGN = "valign";
> > > >
> > > >
> > > > // ----------------------------------------------------------
> > Public
> > > > Methods
> > > >
> > > >
> > > > @Override
> > > > public void encodeEnd(FacesContext context, UIComponent component)
> > > > throws IOException
> > > > {
> > > >
> > > > rendererParamsNotNull(context, component);
> > > >
> > > > if (!shouldEncode(component))
> > > > {
> > > > return;
> > > > }
> > > >
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > String alignStr;
> > > > Object borderObj;
> > > > boolean alignVertical = false;
> > > > int border = 0;
> > > >
> > > >
> > > >
> > > > if (null != component.getAttributes().get("layout"))
> > > > {
> > > > alignStr = (String)
> > component.getAttributes().get("layout");
> > > > alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> > > > }
> > > >
> > > > if (null != component.getAttributes().get(BORDER))
> > > > {
> > > > borderObj = component.getAttributes().get(BORDER);
> > > > border = (Integer) borderObj;
> > > > }
> > > >
> > > > Converter converter = null;
> > > > if (component instanceof ValueHolder)
> > > > {
> > > > converter = ((ValueHolder)component).getConverter();
> > > > }
> > > >
> > > > renderBeginText(component, border, alignVertical, context,
> > true);
> > > >
> > > > Iterator<SelectItem> items =
> > > > RenderKitUtils.getSelectItems(context, component);
> > > >
> > > > Object currentSelections = getCurrentSelectedValues(component);
> > > > Object[] submittedValues =
> > getSubmittedSelectedValues(component);
> > > > Map<String, Object> attributes = component.getAttributes();
> > > > OptionComponentInfo optionInfo =
> > > > new OptionComponentInfo((String)
> > > > attributes.get("disabledClass"),
> > > > (String)
> > > > attributes.get("enabledClass"),
> > > > (String)
> > > > attributes.get("unselectedClass"),
> > > > (String)
> > > > attributes.get("selectedClass"),
> > > >
> > > Util.componentIsDisabled(component),
> > > > isHideNoSelection(component));
> > > > int idx = -1;
> > > > while (items.hasNext())
> > > > {
> > > > SelectItem curItem = items.next();
> > > > idx++;
> > > > // If we come across a group of options, render them as a
> > > > nested
> > > > // table.
> > > > if (curItem instanceof SelectItemGroup)
> > > > {
> > > > // write out the label for the group.
> > > > if (curItem.getLabel() != null)
> > > > {
> > > > if (alignVertical)
> > > > {
> > > > writer.startElement(TR, component);
> > > > }
> > > > writer.startElement(TD, component);
> > > > writer.writeText(curItem.getLabel(), component,
> > > LABEL);
> > > > writer.endElement(TD);
> > > > if (alignVertical)
> > > > {
> > > > writer.endElement(TR);
> > > > }
> > > >
> > > > }
> > > > if (alignVertical)
> > > > {
> > > > writer.startElement(TR, component);
> > > > }
> > > > writer.startElement(TD, component);
> > > > writer.writeText(NEWLINE, component, null);
> > > > renderBeginText(component, 0, alignVertical,
> > > > context, false);
> > > > // render options of this group.
> > > > SelectItem[] itemsArray =
> > > > ((SelectItemGroup) curItem).getSelectItems();
> > > > for (int i = 0; i < itemsArray.length; ++i)
> > > > {
> > > > renderOption(context,
> > > > component,
> > > > converter,
> > > > itemsArray[i],
> > > > currentSelections,
> > > > submittedValues,
> > > > alignVertical,
> > > > i,
> > > > optionInfo);
> > > > }
> > > > renderEndText(component, alignVertical, context);
> > > > writer.endElement(TD);
> > > > if (alignVertical)
> > > > {
> > > > writer.endElement(TR);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > }
> > > > else
> > > > {
> > > > renderOption(context,
> > > > component,
> > > > converter,
> > > > curItem,
> > > > currentSelections,
> > > > submittedValues,
> > > > alignVertical,
> > > > idx,
> > > > optionInfo);
> > > > }
> > > > }
> > > >
> > > > renderEndText(component, alignVertical, context);
> > > >
> > > > }
> > > >
> > > > // -------------------------------------------------------
> > Protected
> > > > Methods
> > > >
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > @Override
> > > > protected boolean isBehaviorSource(FacesContext ctx,
> > > > String behaviorSourceId,
> > > > String componentClientId)
> > > > {
> > > >
> > > > if (behaviorSourceId == null)
> > > > {
> > > > return false;
> > > > }
> > > > char sepChar = UINamingContainer.getSeparatorChar(ctx);
> > > > String actualBehaviorId =
> > > > behaviorSourceId.substring(0,
> > > > behaviorSourceId.lastIndexOf(sepChar));
> > > > return (actualBehaviorId.equals(componentClientId));
> > > >
> > > > }
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > protected void renderBeginText(UIComponent component, int border,
> > > > boolean alignVertical, FacesContext
> > > > context,
> > > > boolean outerTable) throws
> > IOException
> > > > {
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > writer.startElement("table", component);
> > > > if (border != Integer.MIN_VALUE)
> > > > {
> > > > writer.writeAttribute(BORDER, border, BORDER);
> > > > }
> > > >
> > > > // render style and styleclass attribute on the outer table
> > > > instead of
> > > > // rendering it as pass through attribute on every option in
> > the
> > > > list.
> > > > if (outerTable)
> > > > {
> > > > // render "id" only for outerTable.
> > > > if (shouldWriteIdAttribute(component))
> > > > {
> > > > writeIdAttributeIfNecessary(context, writer,
> > component);
> > > > }
> > > > String styleClass = (String) component.getAttributes().get(
> > > > "styleClass");
> > > > String style = (String)
> > component.getAttributes().get(STYLE);
> > > > if (styleClass != null)
> > > > {
> > > > writer.writeAttribute(CLASS, styleClass, CLASS);
> > > > }
> > > > if (style != null)
> > > > {
> > > > writer.writeAttribute(STYLE, style, STYLE);
> > > > }
> > > > }
> > > > writer.writeText(NEWLINE, component, null);
> > > >
> > > > if (!alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.startElement(TR, component);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > >
> > > > }
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > protected void renderEndText(UIComponent component,
> > > > boolean alignVertical,
> > > > FacesContext context) throws
> > IOException
> > > > {
> > > >
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > if (!alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.endElement(TR);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > writer.endElement("table");
> > > >
> > > > }
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > protected void renderOption(FacesContext context,
> > > > UIComponent component,
> > > > Converter converter,
> > > > SelectItem curItem,
> > > > Object currentSelections,
> > > > Object[] submittedValues,
> > > > boolean alignVertical,
> > > > int itemNumber,
> > > > OptionComponentInfo optionInfo) throws
> > > > IOException
> > > > {
> > > >
> > > > String valueString = getFormattedValue(context, component,
> > > > curItem.getValue(),
> > > > converter);
> > > >
> > > > Object valuesArray;
> > > > Object itemValue;
> > > > if (submittedValues != null)
> > > > {
> > > > valuesArray = submittedValues;
> > > > itemValue = valueString;
> > > > }
> > > > else
> > > > {
> > > > valuesArray = currentSelections;
> > > > itemValue = curItem.getValue();
> > > > }
> > > >
> > > > RequestStateManager.set(context,
> > > >
> > > > RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> > > > component);
> > > >
> > > > boolean isSelected = isSelected(context, component, itemValue,
> > > > valuesArray, converter);
> > > > if (optionInfo.isHideNoSelection() &&
> > > > curItem.isNoSelectionOption() &&
> > > > currentSelections != null &&
> > > > !isSelected)
> > > > {
> > > > return;
> > > > }
> > > >
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > if (alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.startElement(TR, component);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > writer.startElement(TD, component);
> > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > writer.writeText(NEWLINE, component, null);
> > > >
> > > > writer.startElement("input", component);
> > > > writer.writeAttribute("name", component.getClientId(context),
> > > > "clientId");
> > > > String idString = component.getClientId(context) +
> > > > UINamingContainer.getSeparatorChar(context) +
> > > > Integer.toString(itemNumber);
> > > > writer.writeAttribute("id", idString, "id");
> > > >
> > > > writer.writeAttribute("value", valueString, "value");
> > > > writer.writeAttribute("type", "checkbox", null);
> > > >
> > > > if (isSelected)
> > > > {
> > > > writer.writeAttribute(getSelectedTextString(),
> > Boolean.TRUE,
> > > > null);
> > > > }
> > > >
> > > > // Don't render the disabled attribute twice if the 'parent'
> > > > // component is already marked disabled.
> > > > if (!optionInfo.isDisabled())
> > > > {
> > > > if (curItem.isDisabled())
> > > > {
> > > > writer.writeAttribute("disabled", true, "disabled");
> > > > }
> > > > }
> > > >
> > > > // Apply HTML 4.x attributes specified on UISelectMany
> > component
> > > > to all
> > > > // items in the list except styleClass and style which are
> > > > rendered as
> > > > // attributes of outer most table.
> > > > RenderKitUtils.renderPassThruAttributes(context,
> > > > writer,
> > > > component,
> > > > ATTRIBUTES,
> > > >
> > > > getNonOnClickSelectBehaviors(component));
> > > >
> > > > RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> > > > component);
> > > >
> > > > RenderKitUtils.renderSelectOnclick(context, component, true);
> > > >
> > > > writer.endElement("input");
> > > >
> > > > //--------------------------------------------------------
> > > > // New stuff for event selecting
> > > > //--------------------------------------------------------
> > > >
> > > > writer.endElement(TD);
> > > >
> > > > // starting the label td
> > > > writer.startElement(TD, component);
> > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > writer.writeAttribute("width", "80px", "width");
> > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > >
> > > > String itemLabel = curItem.getLabel();
> > > > if (itemLabel == null)
> > > > {
> > > > itemLabel = valueString;
> > > > }
> > > >
> > > > writer.writeText(" ", component, null);
> > > > writer.startElement(LABEL, component);
> > > > writer.writeAttribute("for", component.getClientId() + ":" +
> > > > itemNumber, "for");
> > > > if (!curItem.isEscape())
> > > > {
> > > > // It seems the ResponseWriter API should
> > > > // have a writeText() with a boolean property
> > > > // to determine if it content written should
> > > > // be escaped or not.
> > > > writer.write(itemLabel);
> > > > }
> > > > else
> > > > {
> > > > writer.writeText(itemLabel, component, null);
> > > > }
> > > > writer.endElement(LABEL);
> > > >
> > > > isSelected(context, component, itemValue, valuesArray,
> > > converter);
> > > > // if (isSelected(context, component, itemValue,
> > valuesArray,
> > > > converter))
> > > > // {
> > > > // // selected
> > > > // }
> > > > // else
> > > > // {
> > > > // // not selected
> > > > // }
> > > > writer.endElement(TD);
> > > >
> > > > // starting the description td
> > > > writer.startElement(TD, component);
> > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > >
> > > > String itemLabelDesc = curItem.getDescription();
> > > > if (itemLabelDesc == null)
> > > > {
> > > > itemLabelDesc = "";
> > > > }
> > > > writer.writeText(" ", component, null);
> > > > if (!curItem.isEscape())
> > > > {
> > > > // It seems the ResponseWriter API should
> > > > // have a writeText() with a boolean property
> > > > // to determine if it content written should
> > > > // be escaped or not.
> > > > writer.write(itemLabelDesc);
> > > > }
> > > > else
> > > > {
> > > > writer.writeText(itemLabelDesc, component, null);
> > > > }
> > > >
> > > > writer.endElement(TD);
> > > >
> > > > //--------------------------------------------------------
> > > > // New stuff for event selecting end
> > > > //--------------------------------------------------------
> > > >
> > > > writer.writeText(NEWLINE, component, null);
> > > > if (alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.endElement(TR);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > }
> > > >
> > > >
> > > > // ------------------------------------------------- Package
> > Private
> > > > Methods
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > String getSelectedTextString()
> > > > {
> > > > return "checked";
> > > > }
> > > > }
> > > >
> > > >
> > > > Any help is appreciated!
> > > > Thanks!
> > > >
> > > > René
> > > >
> > >
> >
>
Re: Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
do you have a screen capture or some type of demo of the Select component?
On Thu, Feb 13, 2014 at 8:39 AM, Rene Perschon <Ch...@gmx.net> wrote:
> I don't think a TagHandler or a custom component can do what that code
> does. It's used to display a Select in a very specific way.
>
>
>
> Gesendet: Donnerstag, 13. Februar 2014 um 14:29 Uhr
> Von: "Karl Kildén" <ka...@gmail.com>
> An: "MyFaces Discussion" <us...@myfaces.apache.org>
> Betreff: Re: Problems with a custom component when migrating from
> Glassfish(mojarra) to TomEE
> Have you considered a custom tagHandler / composite component instead?
>
> I took a quick look but I don't recognize much sorry.
>
>
> On 13 February 2014 14:09, Howard W. Smith, Jr. <smithh032772@gmail.com
> >wrote:
>
> > I think Leonardo, Gerhard, or one of the other committers may provide her
> > some good help, just to get another MyFaces user, especially when one is
> > migrating from Mojarra to MyFaces.
> >
> > @Renee, +1 your goal/request.
> >
> > I migrated from Mojarra to MyFaces, first, and then 2 months later, I
> > migrated from Glassfish to tomee (and JSF managed beans to CDI managed
> > beans at same time). Thomas, Romain, Mark Struberg, and others provided
> > great help and motivation. Apache tomee, MyFaces, tomcat user mail lists
> > are definitely the place to be.
> >
> > But I didn't have code dependent on the Mojarra library like you do.
> Still,
> > it took me about a week to migrate from Mojarra to MyFaces. Thomas and
> > Leonardo motivated me to start the migration after reading about the
> > performance comparison between Mojarra and MyFaces. Mark Struberg blog,
> why
> > is OpenWebBeans so fast, motivated me to migrate to CDI and tomee. :-)
> >
> > I love high performance, that's why I opted to use MyFaces, tomee,
> > OpenWebBeans, and JUEL.
> >
> > Wishing you much success.
> > On Feb 13, 2014 7:23 AM, "Thomas Andraschko" <
> andraschko.thomas@gmail.com>
> > wrote:
> >
> > > I don't think that anyone will port your complete code and give you a
> > > complete solution ;)
> > >
> > > The biggest problem is AFAIR that the renderer implementations are not
> in
> > > the API packages. So you have to rebuild all this functionality without
> > > dependencies to the Impl.
> > >
> > > e.g.
> > > Attribute,AttributeManager -> String[] with attribute namens
> > > Move all the utils functions to your own code
> (Util.componentIsDisabled,
> > > RenderKitUtils.getSelectItems. etc.)
> > >
> > > The most code doesn't really depent on the IMPL code.
> > >
> > >
> > > 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> > >
> > > > Hi everyone!
> > > >
> > > > I'm currently migrating an application from Glassfish 3.1.1 to TomEE.
> > Now
> > > > the problem is that this application contains a custom component
> which
> > > was
> > > > unfortunately coded with hard dependencies on com.sun.faces classes
> > > (maven
> > > > dependency jsf-impl).
> > > >
> > > > Now my question is how can i port this component in such a way that
> it
> > is
> > > > independent from any concrete JSF implementation (or at least in
> such a
> > > way
> > > > that it works with MyFaces).
> > > >
> > > > Here's the component:
> > > >
> > > > import java.io.IOException;
> > > > import java.util.Iterator;
> > > > import java.util.Map;
> > > >
> > > > import javax.faces.component.UIComponent;
> > > > import javax.faces.component.UINamingContainer;
> > > > import javax.faces.component.ValueHolder;
> > > > import javax.faces.context.FacesContext;
> > > > import javax.faces.context.ResponseWriter;
> > > > import javax.faces.convert.Converter;
> > > > import javax.faces.model.SelectItem;
> > > > import javax.faces.model.SelectItemGroup;
> > > >
> > > > import com.sun.faces.renderkit.Attribute;
> > > > import com.sun.faces.renderkit.AttributeManager;
> > > > import com.sun.faces.renderkit.RenderKitUtils;
> > > > import com.sun.faces.renderkit.html_basic.MenuRenderer;
> > > > import com.sun.faces.util.RequestStateManager;
> > > > import com.sun.faces.util.Util;
> > > >
> > > > /**
> > > > * {@inheritDoc}.
> > > > */
> > > > public class CustomSelectManyCheckboxListRenderer extends
> MenuRenderer
> > > > {
> > > > /** {@inheritDoc}. */
> > > > private static final Attribute[] ATTRIBUTES =
> > > >
> > AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> > > > /** Representing the border string. */
> > > > private static final String BORDER = "border";
> > > > /** Representing the tr string. */
> > > > private static final String TR = "tr";
> > > > /** Representing the td string. */
> > > > private static final String TD = "td";
> > > > /** Representing the label string. */
> > > > private static final String LABEL = "label";
> > > > /** Representing the newline string. */
> > > > private static final String NEWLINE = "\n";
> > > > /** Representing the tab string. */
> > > > private static final String TAB = "\t";
> > > > /** Representing the class string. */
> > > > private static final String CLASS = "class";
> > > > /** Representing the style string. */
> > > > private static final String STYLE = "style";
> > > > /** Representing the valign string. */
> > > > private static final String VALIGN = "valign";
> > > >
> > > >
> > > > // ----------------------------------------------------------
> > Public
> > > > Methods
> > > >
> > > >
> > > > @Override
> > > > public void encodeEnd(FacesContext context, UIComponent component)
> > > > throws IOException
> > > > {
> > > >
> > > > rendererParamsNotNull(context, component);
> > > >
> > > > if (!shouldEncode(component))
> > > > {
> > > > return;
> > > > }
> > > >
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > String alignStr;
> > > > Object borderObj;
> > > > boolean alignVertical = false;
> > > > int border = 0;
> > > >
> > > >
> > > >
> > > > if (null != component.getAttributes().get("layout"))
> > > > {
> > > > alignStr = (String)
> > component.getAttributes().get("layout");
> > > > alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> > > > }
> > > >
> > > > if (null != component.getAttributes().get(BORDER))
> > > > {
> > > > borderObj = component.getAttributes().get(BORDER);
> > > > border = (Integer) borderObj;
> > > > }
> > > >
> > > > Converter converter = null;
> > > > if (component instanceof ValueHolder)
> > > > {
> > > > converter = ((ValueHolder)component).getConverter();
> > > > }
> > > >
> > > > renderBeginText(component, border, alignVertical, context,
> > true);
> > > >
> > > > Iterator<SelectItem> items =
> > > > RenderKitUtils.getSelectItems(context, component);
> > > >
> > > > Object currentSelections = getCurrentSelectedValues(component);
> > > > Object[] submittedValues =
> > getSubmittedSelectedValues(component);
> > > > Map<String, Object> attributes = component.getAttributes();
> > > > OptionComponentInfo optionInfo =
> > > > new OptionComponentInfo((String)
> > > > attributes.get("disabledClass"),
> > > > (String)
> > > > attributes.get("enabledClass"),
> > > > (String)
> > > > attributes.get("unselectedClass"),
> > > > (String)
> > > > attributes.get("selectedClass"),
> > > >
> > > Util.componentIsDisabled(component),
> > > > isHideNoSelection(component));
> > > > int idx = -1;
> > > > while (items.hasNext())
> > > > {
> > > > SelectItem curItem = items.next();
> > > > idx++;
> > > > // If we come across a group of options, render them as a
> > > > nested
> > > > // table.
> > > > if (curItem instanceof SelectItemGroup)
> > > > {
> > > > // write out the label for the group.
> > > > if (curItem.getLabel() != null)
> > > > {
> > > > if (alignVertical)
> > > > {
> > > > writer.startElement(TR, component);
> > > > }
> > > > writer.startElement(TD, component);
> > > > writer.writeText(curItem.getLabel(), component,
> > > LABEL);
> > > > writer.endElement(TD);
> > > > if (alignVertical)
> > > > {
> > > > writer.endElement(TR);
> > > > }
> > > >
> > > > }
> > > > if (alignVertical)
> > > > {
> > > > writer.startElement(TR, component);
> > > > }
> > > > writer.startElement(TD, component);
> > > > writer.writeText(NEWLINE, component, null);
> > > > renderBeginText(component, 0, alignVertical,
> > > > context, false);
> > > > // render options of this group.
> > > > SelectItem[] itemsArray =
> > > > ((SelectItemGroup) curItem).getSelectItems();
> > > > for (int i = 0; i < itemsArray.length; ++i)
> > > > {
> > > > renderOption(context,
> > > > component,
> > > > converter,
> > > > itemsArray[i],
> > > > currentSelections,
> > > > submittedValues,
> > > > alignVertical,
> > > > i,
> > > > optionInfo);
> > > > }
> > > > renderEndText(component, alignVertical, context);
> > > > writer.endElement(TD);
> > > > if (alignVertical)
> > > > {
> > > > writer.endElement(TR);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > }
> > > > else
> > > > {
> > > > renderOption(context,
> > > > component,
> > > > converter,
> > > > curItem,
> > > > currentSelections,
> > > > submittedValues,
> > > > alignVertical,
> > > > idx,
> > > > optionInfo);
> > > > }
> > > > }
> > > >
> > > > renderEndText(component, alignVertical, context);
> > > >
> > > > }
> > > >
> > > > // -------------------------------------------------------
> > Protected
> > > > Methods
> > > >
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > @Override
> > > > protected boolean isBehaviorSource(FacesContext ctx,
> > > > String behaviorSourceId,
> > > > String componentClientId)
> > > > {
> > > >
> > > > if (behaviorSourceId == null)
> > > > {
> > > > return false;
> > > > }
> > > > char sepChar = UINamingContainer.getSeparatorChar(ctx);
> > > > String actualBehaviorId =
> > > > behaviorSourceId.substring(0,
> > > > behaviorSourceId.lastIndexOf(sepChar));
> > > > return (actualBehaviorId.equals(componentClientId));
> > > >
> > > > }
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > protected void renderBeginText(UIComponent component, int border,
> > > > boolean alignVertical, FacesContext
> > > > context,
> > > > boolean outerTable) throws
> > IOException
> > > > {
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > writer.startElement("table", component);
> > > > if (border != Integer.MIN_VALUE)
> > > > {
> > > > writer.writeAttribute(BORDER, border, BORDER);
> > > > }
> > > >
> > > > // render style and styleclass attribute on the outer table
> > > > instead of
> > > > // rendering it as pass through attribute on every option in
> > the
> > > > list.
> > > > if (outerTable)
> > > > {
> > > > // render "id" only for outerTable.
> > > > if (shouldWriteIdAttribute(component))
> > > > {
> > > > writeIdAttributeIfNecessary(context, writer,
> > component);
> > > > }
> > > > String styleClass = (String) component.getAttributes().get(
> > > > "styleClass");
> > > > String style = (String)
> > component.getAttributes().get(STYLE);
> > > > if (styleClass != null)
> > > > {
> > > > writer.writeAttribute(CLASS, styleClass, CLASS);
> > > > }
> > > > if (style != null)
> > > > {
> > > > writer.writeAttribute(STYLE, style, STYLE);
> > > > }
> > > > }
> > > > writer.writeText(NEWLINE, component, null);
> > > >
> > > > if (!alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.startElement(TR, component);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > >
> > > > }
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > protected void renderEndText(UIComponent component,
> > > > boolean alignVertical,
> > > > FacesContext context) throws
> > IOException
> > > > {
> > > >
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > if (!alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.endElement(TR);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > writer.endElement("table");
> > > >
> > > > }
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > protected void renderOption(FacesContext context,
> > > > UIComponent component,
> > > > Converter converter,
> > > > SelectItem curItem,
> > > > Object currentSelections,
> > > > Object[] submittedValues,
> > > > boolean alignVertical,
> > > > int itemNumber,
> > > > OptionComponentInfo optionInfo) throws
> > > > IOException
> > > > {
> > > >
> > > > String valueString = getFormattedValue(context, component,
> > > > curItem.getValue(),
> > > > converter);
> > > >
> > > > Object valuesArray;
> > > > Object itemValue;
> > > > if (submittedValues != null)
> > > > {
> > > > valuesArray = submittedValues;
> > > > itemValue = valueString;
> > > > }
> > > > else
> > > > {
> > > > valuesArray = currentSelections;
> > > > itemValue = curItem.getValue();
> > > > }
> > > >
> > > > RequestStateManager.set(context,
> > > >
> > > > RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> > > > component);
> > > >
> > > > boolean isSelected = isSelected(context, component, itemValue,
> > > > valuesArray, converter);
> > > > if (optionInfo.isHideNoSelection() &&
> > > > curItem.isNoSelectionOption() &&
> > > > currentSelections != null &&
> > > > !isSelected)
> > > > {
> > > > return;
> > > > }
> > > >
> > > > ResponseWriter writer = context.getResponseWriter();
> > > > assert (writer != null);
> > > >
> > > > if (alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.startElement(TR, component);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > writer.startElement(TD, component);
> > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > writer.writeText(NEWLINE, component, null);
> > > >
> > > > writer.startElement("input", component);
> > > > writer.writeAttribute("name", component.getClientId(context),
> > > > "clientId");
> > > > String idString = component.getClientId(context) +
> > > > UINamingContainer.getSeparatorChar(context) +
> > > > Integer.toString(itemNumber);
> > > > writer.writeAttribute("id", idString, "id");
> > > >
> > > > writer.writeAttribute("value", valueString, "value");
> > > > writer.writeAttribute("type", "checkbox", null);
> > > >
> > > > if (isSelected)
> > > > {
> > > > writer.writeAttribute(getSelectedTextString(),
> > Boolean.TRUE,
> > > > null);
> > > > }
> > > >
> > > > // Don't render the disabled attribute twice if the 'parent'
> > > > // component is already marked disabled.
> > > > if (!optionInfo.isDisabled())
> > > > {
> > > > if (curItem.isDisabled())
> > > > {
> > > > writer.writeAttribute("disabled", true, "disabled");
> > > > }
> > > > }
> > > >
> > > > // Apply HTML 4.x attributes specified on UISelectMany
> > component
> > > > to all
> > > > // items in the list except styleClass and style which are
> > > > rendered as
> > > > // attributes of outer most table.
> > > > RenderKitUtils.renderPassThruAttributes(context,
> > > > writer,
> > > > component,
> > > > ATTRIBUTES,
> > > >
> > > > getNonOnClickSelectBehaviors(component));
> > > >
> > > > RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> > > > component);
> > > >
> > > > RenderKitUtils.renderSelectOnclick(context, component, true);
> > > >
> > > > writer.endElement("input");
> > > >
> > > > //--------------------------------------------------------
> > > > // New stuff for event selecting
> > > > //--------------------------------------------------------
> > > >
> > > > writer.endElement(TD);
> > > >
> > > > // starting the label td
> > > > writer.startElement(TD, component);
> > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > writer.writeAttribute("width", "80px", "width");
> > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > >
> > > > String itemLabel = curItem.getLabel();
> > > > if (itemLabel == null)
> > > > {
> > > > itemLabel = valueString;
> > > > }
> > > >
> > > > writer.writeText(" ", component, null);
> > > > writer.startElement(LABEL, component);
> > > > writer.writeAttribute("for", component.getClientId() + ":" +
> > > > itemNumber, "for");
> > > > if (!curItem.isEscape())
> > > > {
> > > > // It seems the ResponseWriter API should
> > > > // have a writeText() with a boolean property
> > > > // to determine if it content written should
> > > > // be escaped or not.
> > > > writer.write(itemLabel);
> > > > }
> > > > else
> > > > {
> > > > writer.writeText(itemLabel, component, null);
> > > > }
> > > > writer.endElement(LABEL);
> > > >
> > > > isSelected(context, component, itemValue, valuesArray,
> > > converter);
> > > > // if (isSelected(context, component, itemValue,
> > valuesArray,
> > > > converter))
> > > > // {
> > > > // // selected
> > > > // }
> > > > // else
> > > > // {
> > > > // // not selected
> > > > // }
> > > > writer.endElement(TD);
> > > >
> > > > // starting the description td
> > > > writer.startElement(TD, component);
> > > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > > >
> > > > String itemLabelDesc = curItem.getDescription();
> > > > if (itemLabelDesc == null)
> > > > {
> > > > itemLabelDesc = "";
> > > > }
> > > > writer.writeText(" ", component, null);
> > > > if (!curItem.isEscape())
> > > > {
> > > > // It seems the ResponseWriter API should
> > > > // have a writeText() with a boolean property
> > > > // to determine if it content written should
> > > > // be escaped or not.
> > > > writer.write(itemLabelDesc);
> > > > }
> > > > else
> > > > {
> > > > writer.writeText(itemLabelDesc, component, null);
> > > > }
> > > >
> > > > writer.endElement(TD);
> > > >
> > > > //--------------------------------------------------------
> > > > // New stuff for event selecting end
> > > > //--------------------------------------------------------
> > > >
> > > > writer.writeText(NEWLINE, component, null);
> > > > if (alignVertical)
> > > > {
> > > > writer.writeText(TAB, component, null);
> > > > writer.endElement(TR);
> > > > writer.writeText(NEWLINE, component, null);
> > > > }
> > > > }
> > > >
> > > >
> > > > // ------------------------------------------------- Package
> > Private
> > > > Methods
> > > >
> > > > /**
> > > > * {@inheritDoc}
> > > > */
> > > > String getSelectedTextString()
> > > > {
> > > > return "checked";
> > > > }
> > > > }
> > > >
> > > >
> > > > Any help is appreciated!
> > > > Thanks!
> > > >
> > > > René
> > > >
> > >
> >
>
Aw: Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Rene Perschon <Ch...@gmx.net>.
I don't think a TagHandler or a custom component can do what that code does. It's used to display a Select in a very specific way.
Gesendet: Donnerstag, 13. Februar 2014 um 14:29 Uhr
Von: "Karl Kildén" <ka...@gmail.com>
An: "MyFaces Discussion" <us...@myfaces.apache.org>
Betreff: Re: Problems with a custom component when migrating from Glassfish(mojarra) to TomEE
Have you considered a custom tagHandler / composite component instead?
I took a quick look but I don't recognize much sorry.
On 13 February 2014 14:09, Howard W. Smith, Jr. <sm...@gmail.com>wrote:
> I think Leonardo, Gerhard, or one of the other committers may provide her
> some good help, just to get another MyFaces user, especially when one is
> migrating from Mojarra to MyFaces.
>
> @Renee, +1 your goal/request.
>
> I migrated from Mojarra to MyFaces, first, and then 2 months later, I
> migrated from Glassfish to tomee (and JSF managed beans to CDI managed
> beans at same time). Thomas, Romain, Mark Struberg, and others provided
> great help and motivation. Apache tomee, MyFaces, tomcat user mail lists
> are definitely the place to be.
>
> But I didn't have code dependent on the Mojarra library like you do. Still,
> it took me about a week to migrate from Mojarra to MyFaces. Thomas and
> Leonardo motivated me to start the migration after reading about the
> performance comparison between Mojarra and MyFaces. Mark Struberg blog, why
> is OpenWebBeans so fast, motivated me to migrate to CDI and tomee. :-)
>
> I love high performance, that's why I opted to use MyFaces, tomee,
> OpenWebBeans, and JUEL.
>
> Wishing you much success.
> On Feb 13, 2014 7:23 AM, "Thomas Andraschko" <an...@gmail.com>
> wrote:
>
> > I don't think that anyone will port your complete code and give you a
> > complete solution ;)
> >
> > The biggest problem is AFAIR that the renderer implementations are not in
> > the API packages. So you have to rebuild all this functionality without
> > dependencies to the Impl.
> >
> > e.g.
> > Attribute,AttributeManager -> String[] with attribute namens
> > Move all the utils functions to your own code (Util.componentIsDisabled,
> > RenderKitUtils.getSelectItems. etc.)
> >
> > The most code doesn't really depent on the IMPL code.
> >
> >
> > 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> >
> > > Hi everyone!
> > >
> > > I'm currently migrating an application from Glassfish 3.1.1 to TomEE.
> Now
> > > the problem is that this application contains a custom component which
> > was
> > > unfortunately coded with hard dependencies on com.sun.faces classes
> > (maven
> > > dependency jsf-impl).
> > >
> > > Now my question is how can i port this component in such a way that it
> is
> > > independent from any concrete JSF implementation (or at least in such a
> > way
> > > that it works with MyFaces).
> > >
> > > Here's the component:
> > >
> > > import java.io.IOException;
> > > import java.util.Iterator;
> > > import java.util.Map;
> > >
> > > import javax.faces.component.UIComponent;
> > > import javax.faces.component.UINamingContainer;
> > > import javax.faces.component.ValueHolder;
> > > import javax.faces.context.FacesContext;
> > > import javax.faces.context.ResponseWriter;
> > > import javax.faces.convert.Converter;
> > > import javax.faces.model.SelectItem;
> > > import javax.faces.model.SelectItemGroup;
> > >
> > > import com.sun.faces.renderkit.Attribute;
> > > import com.sun.faces.renderkit.AttributeManager;
> > > import com.sun.faces.renderkit.RenderKitUtils;
> > > import com.sun.faces.renderkit.html_basic.MenuRenderer;
> > > import com.sun.faces.util.RequestStateManager;
> > > import com.sun.faces.util.Util;
> > >
> > > /**
> > > * {@inheritDoc}.
> > > */
> > > public class CustomSelectManyCheckboxListRenderer extends MenuRenderer
> > > {
> > > /** {@inheritDoc}. */
> > > private static final Attribute[] ATTRIBUTES =
> > >
> AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> > > /** Representing the border string. */
> > > private static final String BORDER = "border";
> > > /** Representing the tr string. */
> > > private static final String TR = "tr";
> > > /** Representing the td string. */
> > > private static final String TD = "td";
> > > /** Representing the label string. */
> > > private static final String LABEL = "label";
> > > /** Representing the newline string. */
> > > private static final String NEWLINE = "\n";
> > > /** Representing the tab string. */
> > > private static final String TAB = "\t";
> > > /** Representing the class string. */
> > > private static final String CLASS = "class";
> > > /** Representing the style string. */
> > > private static final String STYLE = "style";
> > > /** Representing the valign string. */
> > > private static final String VALIGN = "valign";
> > >
> > >
> > > // ----------------------------------------------------------
> Public
> > > Methods
> > >
> > >
> > > @Override
> > > public void encodeEnd(FacesContext context, UIComponent component)
> > > throws IOException
> > > {
> > >
> > > rendererParamsNotNull(context, component);
> > >
> > > if (!shouldEncode(component))
> > > {
> > > return;
> > > }
> > >
> > > ResponseWriter writer = context.getResponseWriter();
> > > assert (writer != null);
> > >
> > > String alignStr;
> > > Object borderObj;
> > > boolean alignVertical = false;
> > > int border = 0;
> > >
> > >
> > >
> > > if (null != component.getAttributes().get("layout"))
> > > {
> > > alignStr = (String)
> component.getAttributes().get("layout");
> > > alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> > > }
> > >
> > > if (null != component.getAttributes().get(BORDER))
> > > {
> > > borderObj = component.getAttributes().get(BORDER);
> > > border = (Integer) borderObj;
> > > }
> > >
> > > Converter converter = null;
> > > if (component instanceof ValueHolder)
> > > {
> > > converter = ((ValueHolder)component).getConverter();
> > > }
> > >
> > > renderBeginText(component, border, alignVertical, context,
> true);
> > >
> > > Iterator<SelectItem> items =
> > > RenderKitUtils.getSelectItems(context, component);
> > >
> > > Object currentSelections = getCurrentSelectedValues(component);
> > > Object[] submittedValues =
> getSubmittedSelectedValues(component);
> > > Map<String, Object> attributes = component.getAttributes();
> > > OptionComponentInfo optionInfo =
> > > new OptionComponentInfo((String)
> > > attributes.get("disabledClass"),
> > > (String)
> > > attributes.get("enabledClass"),
> > > (String)
> > > attributes.get("unselectedClass"),
> > > (String)
> > > attributes.get("selectedClass"),
> > >
> > Util.componentIsDisabled(component),
> > > isHideNoSelection(component));
> > > int idx = -1;
> > > while (items.hasNext())
> > > {
> > > SelectItem curItem = items.next();
> > > idx++;
> > > // If we come across a group of options, render them as a
> > > nested
> > > // table.
> > > if (curItem instanceof SelectItemGroup)
> > > {
> > > // write out the label for the group.
> > > if (curItem.getLabel() != null)
> > > {
> > > if (alignVertical)
> > > {
> > > writer.startElement(TR, component);
> > > }
> > > writer.startElement(TD, component);
> > > writer.writeText(curItem.getLabel(), component,
> > LABEL);
> > > writer.endElement(TD);
> > > if (alignVertical)
> > > {
> > > writer.endElement(TR);
> > > }
> > >
> > > }
> > > if (alignVertical)
> > > {
> > > writer.startElement(TR, component);
> > > }
> > > writer.startElement(TD, component);
> > > writer.writeText(NEWLINE, component, null);
> > > renderBeginText(component, 0, alignVertical,
> > > context, false);
> > > // render options of this group.
> > > SelectItem[] itemsArray =
> > > ((SelectItemGroup) curItem).getSelectItems();
> > > for (int i = 0; i < itemsArray.length; ++i)
> > > {
> > > renderOption(context,
> > > component,
> > > converter,
> > > itemsArray[i],
> > > currentSelections,
> > > submittedValues,
> > > alignVertical,
> > > i,
> > > optionInfo);
> > > }
> > > renderEndText(component, alignVertical, context);
> > > writer.endElement(TD);
> > > if (alignVertical)
> > > {
> > > writer.endElement(TR);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > > }
> > > else
> > > {
> > > renderOption(context,
> > > component,
> > > converter,
> > > curItem,
> > > currentSelections,
> > > submittedValues,
> > > alignVertical,
> > > idx,
> > > optionInfo);
> > > }
> > > }
> > >
> > > renderEndText(component, alignVertical, context);
> > >
> > > }
> > >
> > > // -------------------------------------------------------
> Protected
> > > Methods
> > >
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > @Override
> > > protected boolean isBehaviorSource(FacesContext ctx,
> > > String behaviorSourceId,
> > > String componentClientId)
> > > {
> > >
> > > if (behaviorSourceId == null)
> > > {
> > > return false;
> > > }
> > > char sepChar = UINamingContainer.getSeparatorChar(ctx);
> > > String actualBehaviorId =
> > > behaviorSourceId.substring(0,
> > > behaviorSourceId.lastIndexOf(sepChar));
> > > return (actualBehaviorId.equals(componentClientId));
> > >
> > > }
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > protected void renderBeginText(UIComponent component, int border,
> > > boolean alignVertical, FacesContext
> > > context,
> > > boolean outerTable) throws
> IOException
> > > {
> > > ResponseWriter writer = context.getResponseWriter();
> > > assert (writer != null);
> > >
> > > writer.startElement("table", component);
> > > if (border != Integer.MIN_VALUE)
> > > {
> > > writer.writeAttribute(BORDER, border, BORDER);
> > > }
> > >
> > > // render style and styleclass attribute on the outer table
> > > instead of
> > > // rendering it as pass through attribute on every option in
> the
> > > list.
> > > if (outerTable)
> > > {
> > > // render "id" only for outerTable.
> > > if (shouldWriteIdAttribute(component))
> > > {
> > > writeIdAttributeIfNecessary(context, writer,
> component);
> > > }
> > > String styleClass = (String) component.getAttributes().get(
> > > "styleClass");
> > > String style = (String)
> component.getAttributes().get(STYLE);
> > > if (styleClass != null)
> > > {
> > > writer.writeAttribute(CLASS, styleClass, CLASS);
> > > }
> > > if (style != null)
> > > {
> > > writer.writeAttribute(STYLE, style, STYLE);
> > > }
> > > }
> > > writer.writeText(NEWLINE, component, null);
> > >
> > > if (!alignVertical)
> > > {
> > > writer.writeText(TAB, component, null);
> > > writer.startElement(TR, component);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > >
> > > }
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > protected void renderEndText(UIComponent component,
> > > boolean alignVertical,
> > > FacesContext context) throws
> IOException
> > > {
> > >
> > > ResponseWriter writer = context.getResponseWriter();
> > > assert (writer != null);
> > >
> > > if (!alignVertical)
> > > {
> > > writer.writeText(TAB, component, null);
> > > writer.endElement(TR);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > > writer.endElement("table");
> > >
> > > }
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > protected void renderOption(FacesContext context,
> > > UIComponent component,
> > > Converter converter,
> > > SelectItem curItem,
> > > Object currentSelections,
> > > Object[] submittedValues,
> > > boolean alignVertical,
> > > int itemNumber,
> > > OptionComponentInfo optionInfo) throws
> > > IOException
> > > {
> > >
> > > String valueString = getFormattedValue(context, component,
> > > curItem.getValue(),
> > > converter);
> > >
> > > Object valuesArray;
> > > Object itemValue;
> > > if (submittedValues != null)
> > > {
> > > valuesArray = submittedValues;
> > > itemValue = valueString;
> > > }
> > > else
> > > {
> > > valuesArray = currentSelections;
> > > itemValue = curItem.getValue();
> > > }
> > >
> > > RequestStateManager.set(context,
> > >
> > > RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> > > component);
> > >
> > > boolean isSelected = isSelected(context, component, itemValue,
> > > valuesArray, converter);
> > > if (optionInfo.isHideNoSelection() &&
> > > curItem.isNoSelectionOption() &&
> > > currentSelections != null &&
> > > !isSelected)
> > > {
> > > return;
> > > }
> > >
> > > ResponseWriter writer = context.getResponseWriter();
> > > assert (writer != null);
> > >
> > > if (alignVertical)
> > > {
> > > writer.writeText(TAB, component, null);
> > > writer.startElement(TR, component);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > > writer.startElement(TD, component);
> > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > writer.writeText(NEWLINE, component, null);
> > >
> > > writer.startElement("input", component);
> > > writer.writeAttribute("name", component.getClientId(context),
> > > "clientId");
> > > String idString = component.getClientId(context) +
> > > UINamingContainer.getSeparatorChar(context) +
> > > Integer.toString(itemNumber);
> > > writer.writeAttribute("id", idString, "id");
> > >
> > > writer.writeAttribute("value", valueString, "value");
> > > writer.writeAttribute("type", "checkbox", null);
> > >
> > > if (isSelected)
> > > {
> > > writer.writeAttribute(getSelectedTextString(),
> Boolean.TRUE,
> > > null);
> > > }
> > >
> > > // Don't render the disabled attribute twice if the 'parent'
> > > // component is already marked disabled.
> > > if (!optionInfo.isDisabled())
> > > {
> > > if (curItem.isDisabled())
> > > {
> > > writer.writeAttribute("disabled", true, "disabled");
> > > }
> > > }
> > >
> > > // Apply HTML 4.x attributes specified on UISelectMany
> component
> > > to all
> > > // items in the list except styleClass and style which are
> > > rendered as
> > > // attributes of outer most table.
> > > RenderKitUtils.renderPassThruAttributes(context,
> > > writer,
> > > component,
> > > ATTRIBUTES,
> > >
> > > getNonOnClickSelectBehaviors(component));
> > >
> > > RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> > > component);
> > >
> > > RenderKitUtils.renderSelectOnclick(context, component, true);
> > >
> > > writer.endElement("input");
> > >
> > > //--------------------------------------------------------
> > > // New stuff for event selecting
> > > //--------------------------------------------------------
> > >
> > > writer.endElement(TD);
> > >
> > > // starting the label td
> > > writer.startElement(TD, component);
> > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > writer.writeAttribute("width", "80px", "width");
> > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > >
> > > String itemLabel = curItem.getLabel();
> > > if (itemLabel == null)
> > > {
> > > itemLabel = valueString;
> > > }
> > >
> > > writer.writeText(" ", component, null);
> > > writer.startElement(LABEL, component);
> > > writer.writeAttribute("for", component.getClientId() + ":" +
> > > itemNumber, "for");
> > > if (!curItem.isEscape())
> > > {
> > > // It seems the ResponseWriter API should
> > > // have a writeText() with a boolean property
> > > // to determine if it content written should
> > > // be escaped or not.
> > > writer.write(itemLabel);
> > > }
> > > else
> > > {
> > > writer.writeText(itemLabel, component, null);
> > > }
> > > writer.endElement(LABEL);
> > >
> > > isSelected(context, component, itemValue, valuesArray,
> > converter);
> > > // if (isSelected(context, component, itemValue,
> valuesArray,
> > > converter))
> > > // {
> > > // // selected
> > > // }
> > > // else
> > > // {
> > > // // not selected
> > > // }
> > > writer.endElement(TD);
> > >
> > > // starting the description td
> > > writer.startElement(TD, component);
> > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > >
> > > String itemLabelDesc = curItem.getDescription();
> > > if (itemLabelDesc == null)
> > > {
> > > itemLabelDesc = "";
> > > }
> > > writer.writeText(" ", component, null);
> > > if (!curItem.isEscape())
> > > {
> > > // It seems the ResponseWriter API should
> > > // have a writeText() with a boolean property
> > > // to determine if it content written should
> > > // be escaped or not.
> > > writer.write(itemLabelDesc);
> > > }
> > > else
> > > {
> > > writer.writeText(itemLabelDesc, component, null);
> > > }
> > >
> > > writer.endElement(TD);
> > >
> > > //--------------------------------------------------------
> > > // New stuff for event selecting end
> > > //--------------------------------------------------------
> > >
> > > writer.writeText(NEWLINE, component, null);
> > > if (alignVertical)
> > > {
> > > writer.writeText(TAB, component, null);
> > > writer.endElement(TR);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > > }
> > >
> > >
> > > // ------------------------------------------------- Package
> Private
> > > Methods
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > String getSelectedTextString()
> > > {
> > > return "checked";
> > > }
> > > }
> > >
> > >
> > > Any help is appreciated!
> > > Thanks!
> > >
> > > René
> > >
> >
>
Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Karl Kildén <ka...@gmail.com>.
Have you considered a custom tagHandler / composite component instead?
I took a quick look but I don't recognize much sorry.
On 13 February 2014 14:09, Howard W. Smith, Jr. <sm...@gmail.com>wrote:
> I think Leonardo, Gerhard, or one of the other committers may provide her
> some good help, just to get another MyFaces user, especially when one is
> migrating from Mojarra to MyFaces.
>
> @Renee, +1 your goal/request.
>
> I migrated from Mojarra to MyFaces, first, and then 2 months later, I
> migrated from Glassfish to tomee (and JSF managed beans to CDI managed
> beans at same time). Thomas, Romain, Mark Struberg, and others provided
> great help and motivation. Apache tomee, MyFaces, tomcat user mail lists
> are definitely the place to be.
>
> But I didn't have code dependent on the Mojarra library like you do. Still,
> it took me about a week to migrate from Mojarra to MyFaces. Thomas and
> Leonardo motivated me to start the migration after reading about the
> performance comparison between Mojarra and MyFaces. Mark Struberg blog, why
> is OpenWebBeans so fast, motivated me to migrate to CDI and tomee. :-)
>
> I love high performance, that's why I opted to use MyFaces, tomee,
> OpenWebBeans, and JUEL.
>
> Wishing you much success.
> On Feb 13, 2014 7:23 AM, "Thomas Andraschko" <an...@gmail.com>
> wrote:
>
> > I don't think that anyone will port your complete code and give you a
> > complete solution ;)
> >
> > The biggest problem is AFAIR that the renderer implementations are not in
> > the API packages. So you have to rebuild all this functionality without
> > dependencies to the Impl.
> >
> > e.g.
> > Attribute,AttributeManager -> String[] with attribute namens
> > Move all the utils functions to your own code (Util.componentIsDisabled,
> > RenderKitUtils.getSelectItems. etc.)
> >
> > The most code doesn't really depent on the IMPL code.
> >
> >
> > 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> >
> > > Hi everyone!
> > >
> > > I'm currently migrating an application from Glassfish 3.1.1 to TomEE.
> Now
> > > the problem is that this application contains a custom component which
> > was
> > > unfortunately coded with hard dependencies on com.sun.faces classes
> > (maven
> > > dependency jsf-impl).
> > >
> > > Now my question is how can i port this component in such a way that it
> is
> > > independent from any concrete JSF implementation (or at least in such a
> > way
> > > that it works with MyFaces).
> > >
> > > Here's the component:
> > >
> > > import java.io.IOException;
> > > import java.util.Iterator;
> > > import java.util.Map;
> > >
> > > import javax.faces.component.UIComponent;
> > > import javax.faces.component.UINamingContainer;
> > > import javax.faces.component.ValueHolder;
> > > import javax.faces.context.FacesContext;
> > > import javax.faces.context.ResponseWriter;
> > > import javax.faces.convert.Converter;
> > > import javax.faces.model.SelectItem;
> > > import javax.faces.model.SelectItemGroup;
> > >
> > > import com.sun.faces.renderkit.Attribute;
> > > import com.sun.faces.renderkit.AttributeManager;
> > > import com.sun.faces.renderkit.RenderKitUtils;
> > > import com.sun.faces.renderkit.html_basic.MenuRenderer;
> > > import com.sun.faces.util.RequestStateManager;
> > > import com.sun.faces.util.Util;
> > >
> > > /**
> > > * {@inheritDoc}.
> > > */
> > > public class CustomSelectManyCheckboxListRenderer extends MenuRenderer
> > > {
> > > /** {@inheritDoc}. */
> > > private static final Attribute[] ATTRIBUTES =
> > >
> AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> > > /** Representing the border string. */
> > > private static final String BORDER = "border";
> > > /** Representing the tr string. */
> > > private static final String TR = "tr";
> > > /** Representing the td string. */
> > > private static final String TD = "td";
> > > /** Representing the label string. */
> > > private static final String LABEL = "label";
> > > /** Representing the newline string. */
> > > private static final String NEWLINE = "\n";
> > > /** Representing the tab string. */
> > > private static final String TAB = "\t";
> > > /** Representing the class string. */
> > > private static final String CLASS = "class";
> > > /** Representing the style string. */
> > > private static final String STYLE = "style";
> > > /** Representing the valign string. */
> > > private static final String VALIGN = "valign";
> > >
> > >
> > > // ----------------------------------------------------------
> Public
> > > Methods
> > >
> > >
> > > @Override
> > > public void encodeEnd(FacesContext context, UIComponent component)
> > > throws IOException
> > > {
> > >
> > > rendererParamsNotNull(context, component);
> > >
> > > if (!shouldEncode(component))
> > > {
> > > return;
> > > }
> > >
> > > ResponseWriter writer = context.getResponseWriter();
> > > assert (writer != null);
> > >
> > > String alignStr;
> > > Object borderObj;
> > > boolean alignVertical = false;
> > > int border = 0;
> > >
> > >
> > >
> > > if (null != component.getAttributes().get("layout"))
> > > {
> > > alignStr = (String)
> component.getAttributes().get("layout");
> > > alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> > > }
> > >
> > > if (null != component.getAttributes().get(BORDER))
> > > {
> > > borderObj = component.getAttributes().get(BORDER);
> > > border = (Integer) borderObj;
> > > }
> > >
> > > Converter converter = null;
> > > if (component instanceof ValueHolder)
> > > {
> > > converter = ((ValueHolder)component).getConverter();
> > > }
> > >
> > > renderBeginText(component, border, alignVertical, context,
> true);
> > >
> > > Iterator<SelectItem> items =
> > > RenderKitUtils.getSelectItems(context, component);
> > >
> > > Object currentSelections = getCurrentSelectedValues(component);
> > > Object[] submittedValues =
> getSubmittedSelectedValues(component);
> > > Map<String, Object> attributes = component.getAttributes();
> > > OptionComponentInfo optionInfo =
> > > new OptionComponentInfo((String)
> > > attributes.get("disabledClass"),
> > > (String)
> > > attributes.get("enabledClass"),
> > > (String)
> > > attributes.get("unselectedClass"),
> > > (String)
> > > attributes.get("selectedClass"),
> > >
> > Util.componentIsDisabled(component),
> > > isHideNoSelection(component));
> > > int idx = -1;
> > > while (items.hasNext())
> > > {
> > > SelectItem curItem = items.next();
> > > idx++;
> > > // If we come across a group of options, render them as a
> > > nested
> > > // table.
> > > if (curItem instanceof SelectItemGroup)
> > > {
> > > // write out the label for the group.
> > > if (curItem.getLabel() != null)
> > > {
> > > if (alignVertical)
> > > {
> > > writer.startElement(TR, component);
> > > }
> > > writer.startElement(TD, component);
> > > writer.writeText(curItem.getLabel(), component,
> > LABEL);
> > > writer.endElement(TD);
> > > if (alignVertical)
> > > {
> > > writer.endElement(TR);
> > > }
> > >
> > > }
> > > if (alignVertical)
> > > {
> > > writer.startElement(TR, component);
> > > }
> > > writer.startElement(TD, component);
> > > writer.writeText(NEWLINE, component, null);
> > > renderBeginText(component, 0, alignVertical,
> > > context, false);
> > > // render options of this group.
> > > SelectItem[] itemsArray =
> > > ((SelectItemGroup) curItem).getSelectItems();
> > > for (int i = 0; i < itemsArray.length; ++i)
> > > {
> > > renderOption(context,
> > > component,
> > > converter,
> > > itemsArray[i],
> > > currentSelections,
> > > submittedValues,
> > > alignVertical,
> > > i,
> > > optionInfo);
> > > }
> > > renderEndText(component, alignVertical, context);
> > > writer.endElement(TD);
> > > if (alignVertical)
> > > {
> > > writer.endElement(TR);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > > }
> > > else
> > > {
> > > renderOption(context,
> > > component,
> > > converter,
> > > curItem,
> > > currentSelections,
> > > submittedValues,
> > > alignVertical,
> > > idx,
> > > optionInfo);
> > > }
> > > }
> > >
> > > renderEndText(component, alignVertical, context);
> > >
> > > }
> > >
> > > // -------------------------------------------------------
> Protected
> > > Methods
> > >
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > @Override
> > > protected boolean isBehaviorSource(FacesContext ctx,
> > > String behaviorSourceId,
> > > String componentClientId)
> > > {
> > >
> > > if (behaviorSourceId == null)
> > > {
> > > return false;
> > > }
> > > char sepChar = UINamingContainer.getSeparatorChar(ctx);
> > > String actualBehaviorId =
> > > behaviorSourceId.substring(0,
> > > behaviorSourceId.lastIndexOf(sepChar));
> > > return (actualBehaviorId.equals(componentClientId));
> > >
> > > }
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > protected void renderBeginText(UIComponent component, int border,
> > > boolean alignVertical, FacesContext
> > > context,
> > > boolean outerTable) throws
> IOException
> > > {
> > > ResponseWriter writer = context.getResponseWriter();
> > > assert (writer != null);
> > >
> > > writer.startElement("table", component);
> > > if (border != Integer.MIN_VALUE)
> > > {
> > > writer.writeAttribute(BORDER, border, BORDER);
> > > }
> > >
> > > // render style and styleclass attribute on the outer table
> > > instead of
> > > // rendering it as pass through attribute on every option in
> the
> > > list.
> > > if (outerTable)
> > > {
> > > // render "id" only for outerTable.
> > > if (shouldWriteIdAttribute(component))
> > > {
> > > writeIdAttributeIfNecessary(context, writer,
> component);
> > > }
> > > String styleClass = (String) component.getAttributes().get(
> > > "styleClass");
> > > String style = (String)
> component.getAttributes().get(STYLE);
> > > if (styleClass != null)
> > > {
> > > writer.writeAttribute(CLASS, styleClass, CLASS);
> > > }
> > > if (style != null)
> > > {
> > > writer.writeAttribute(STYLE, style, STYLE);
> > > }
> > > }
> > > writer.writeText(NEWLINE, component, null);
> > >
> > > if (!alignVertical)
> > > {
> > > writer.writeText(TAB, component, null);
> > > writer.startElement(TR, component);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > >
> > > }
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > protected void renderEndText(UIComponent component,
> > > boolean alignVertical,
> > > FacesContext context) throws
> IOException
> > > {
> > >
> > > ResponseWriter writer = context.getResponseWriter();
> > > assert (writer != null);
> > >
> > > if (!alignVertical)
> > > {
> > > writer.writeText(TAB, component, null);
> > > writer.endElement(TR);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > > writer.endElement("table");
> > >
> > > }
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > protected void renderOption(FacesContext context,
> > > UIComponent component,
> > > Converter converter,
> > > SelectItem curItem,
> > > Object currentSelections,
> > > Object[] submittedValues,
> > > boolean alignVertical,
> > > int itemNumber,
> > > OptionComponentInfo optionInfo) throws
> > > IOException
> > > {
> > >
> > > String valueString = getFormattedValue(context, component,
> > > curItem.getValue(),
> > > converter);
> > >
> > > Object valuesArray;
> > > Object itemValue;
> > > if (submittedValues != null)
> > > {
> > > valuesArray = submittedValues;
> > > itemValue = valueString;
> > > }
> > > else
> > > {
> > > valuesArray = currentSelections;
> > > itemValue = curItem.getValue();
> > > }
> > >
> > > RequestStateManager.set(context,
> > >
> > > RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> > > component);
> > >
> > > boolean isSelected = isSelected(context, component, itemValue,
> > > valuesArray, converter);
> > > if (optionInfo.isHideNoSelection() &&
> > > curItem.isNoSelectionOption() &&
> > > currentSelections != null &&
> > > !isSelected)
> > > {
> > > return;
> > > }
> > >
> > > ResponseWriter writer = context.getResponseWriter();
> > > assert (writer != null);
> > >
> > > if (alignVertical)
> > > {
> > > writer.writeText(TAB, component, null);
> > > writer.startElement(TR, component);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > > writer.startElement(TD, component);
> > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > writer.writeText(NEWLINE, component, null);
> > >
> > > writer.startElement("input", component);
> > > writer.writeAttribute("name", component.getClientId(context),
> > > "clientId");
> > > String idString = component.getClientId(context) +
> > > UINamingContainer.getSeparatorChar(context) +
> > > Integer.toString(itemNumber);
> > > writer.writeAttribute("id", idString, "id");
> > >
> > > writer.writeAttribute("value", valueString, "value");
> > > writer.writeAttribute("type", "checkbox", null);
> > >
> > > if (isSelected)
> > > {
> > > writer.writeAttribute(getSelectedTextString(),
> Boolean.TRUE,
> > > null);
> > > }
> > >
> > > // Don't render the disabled attribute twice if the 'parent'
> > > // component is already marked disabled.
> > > if (!optionInfo.isDisabled())
> > > {
> > > if (curItem.isDisabled())
> > > {
> > > writer.writeAttribute("disabled", true, "disabled");
> > > }
> > > }
> > >
> > > // Apply HTML 4.x attributes specified on UISelectMany
> component
> > > to all
> > > // items in the list except styleClass and style which are
> > > rendered as
> > > // attributes of outer most table.
> > > RenderKitUtils.renderPassThruAttributes(context,
> > > writer,
> > > component,
> > > ATTRIBUTES,
> > >
> > > getNonOnClickSelectBehaviors(component));
> > >
> > > RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> > > component);
> > >
> > > RenderKitUtils.renderSelectOnclick(context, component, true);
> > >
> > > writer.endElement("input");
> > >
> > > //--------------------------------------------------------
> > > // New stuff for event selecting
> > > //--------------------------------------------------------
> > >
> > > writer.endElement(TD);
> > >
> > > // starting the label td
> > > writer.startElement(TD, component);
> > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > writer.writeAttribute("width", "80px", "width");
> > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > >
> > > String itemLabel = curItem.getLabel();
> > > if (itemLabel == null)
> > > {
> > > itemLabel = valueString;
> > > }
> > >
> > > writer.writeText(" ", component, null);
> > > writer.startElement(LABEL, component);
> > > writer.writeAttribute("for", component.getClientId() + ":" +
> > > itemNumber, "for");
> > > if (!curItem.isEscape())
> > > {
> > > // It seems the ResponseWriter API should
> > > // have a writeText() with a boolean property
> > > // to determine if it content written should
> > > // be escaped or not.
> > > writer.write(itemLabel);
> > > }
> > > else
> > > {
> > > writer.writeText(itemLabel, component, null);
> > > }
> > > writer.endElement(LABEL);
> > >
> > > isSelected(context, component, itemValue, valuesArray,
> > converter);
> > > // if (isSelected(context, component, itemValue,
> valuesArray,
> > > converter))
> > > // {
> > > // // selected
> > > // }
> > > // else
> > > // {
> > > // // not selected
> > > // }
> > > writer.endElement(TD);
> > >
> > > // starting the description td
> > > writer.startElement(TD, component);
> > > writer.writeAttribute(VALIGN, "top", VALIGN);
> > > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> > >
> > > String itemLabelDesc = curItem.getDescription();
> > > if (itemLabelDesc == null)
> > > {
> > > itemLabelDesc = "";
> > > }
> > > writer.writeText(" ", component, null);
> > > if (!curItem.isEscape())
> > > {
> > > // It seems the ResponseWriter API should
> > > // have a writeText() with a boolean property
> > > // to determine if it content written should
> > > // be escaped or not.
> > > writer.write(itemLabelDesc);
> > > }
> > > else
> > > {
> > > writer.writeText(itemLabelDesc, component, null);
> > > }
> > >
> > > writer.endElement(TD);
> > >
> > > //--------------------------------------------------------
> > > // New stuff for event selecting end
> > > //--------------------------------------------------------
> > >
> > > writer.writeText(NEWLINE, component, null);
> > > if (alignVertical)
> > > {
> > > writer.writeText(TAB, component, null);
> > > writer.endElement(TR);
> > > writer.writeText(NEWLINE, component, null);
> > > }
> > > }
> > >
> > >
> > > // ------------------------------------------------- Package
> Private
> > > Methods
> > >
> > > /**
> > > * {@inheritDoc}
> > > */
> > > String getSelectedTextString()
> > > {
> > > return "checked";
> > > }
> > > }
> > >
> > >
> > > Any help is appreciated!
> > > Thanks!
> > >
> > > René
> > >
> >
>
Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
I think Leonardo, Gerhard, or one of the other committers may provide her
some good help, just to get another MyFaces user, especially when one is
migrating from Mojarra to MyFaces.
@Renee, +1 your goal/request.
I migrated from Mojarra to MyFaces, first, and then 2 months later, I
migrated from Glassfish to tomee (and JSF managed beans to CDI managed
beans at same time). Thomas, Romain, Mark Struberg, and others provided
great help and motivation. Apache tomee, MyFaces, tomcat user mail lists
are definitely the place to be.
But I didn't have code dependent on the Mojarra library like you do. Still,
it took me about a week to migrate from Mojarra to MyFaces. Thomas and
Leonardo motivated me to start the migration after reading about the
performance comparison between Mojarra and MyFaces. Mark Struberg blog, why
is OpenWebBeans so fast, motivated me to migrate to CDI and tomee. :-)
I love high performance, that's why I opted to use MyFaces, tomee,
OpenWebBeans, and JUEL.
Wishing you much success.
On Feb 13, 2014 7:23 AM, "Thomas Andraschko" <an...@gmail.com>
wrote:
> I don't think that anyone will port your complete code and give you a
> complete solution ;)
>
> The biggest problem is AFAIR that the renderer implementations are not in
> the API packages. So you have to rebuild all this functionality without
> dependencies to the Impl.
>
> e.g.
> Attribute,AttributeManager -> String[] with attribute namens
> Move all the utils functions to your own code (Util.componentIsDisabled,
> RenderKitUtils.getSelectItems. etc.)
>
> The most code doesn't really depent on the IMPL code.
>
>
> 2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
>
> > Hi everyone!
> >
> > I'm currently migrating an application from Glassfish 3.1.1 to TomEE. Now
> > the problem is that this application contains a custom component which
> was
> > unfortunately coded with hard dependencies on com.sun.faces classes
> (maven
> > dependency jsf-impl).
> >
> > Now my question is how can i port this component in such a way that it is
> > independent from any concrete JSF implementation (or at least in such a
> way
> > that it works with MyFaces).
> >
> > Here's the component:
> >
> > import java.io.IOException;
> > import java.util.Iterator;
> > import java.util.Map;
> >
> > import javax.faces.component.UIComponent;
> > import javax.faces.component.UINamingContainer;
> > import javax.faces.component.ValueHolder;
> > import javax.faces.context.FacesContext;
> > import javax.faces.context.ResponseWriter;
> > import javax.faces.convert.Converter;
> > import javax.faces.model.SelectItem;
> > import javax.faces.model.SelectItemGroup;
> >
> > import com.sun.faces.renderkit.Attribute;
> > import com.sun.faces.renderkit.AttributeManager;
> > import com.sun.faces.renderkit.RenderKitUtils;
> > import com.sun.faces.renderkit.html_basic.MenuRenderer;
> > import com.sun.faces.util.RequestStateManager;
> > import com.sun.faces.util.Util;
> >
> > /**
> > * {@inheritDoc}.
> > */
> > public class CustomSelectManyCheckboxListRenderer extends MenuRenderer
> > {
> > /** {@inheritDoc}. */
> > private static final Attribute[] ATTRIBUTES =
> > AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> > /** Representing the border string. */
> > private static final String BORDER = "border";
> > /** Representing the tr string. */
> > private static final String TR = "tr";
> > /** Representing the td string. */
> > private static final String TD = "td";
> > /** Representing the label string. */
> > private static final String LABEL = "label";
> > /** Representing the newline string. */
> > private static final String NEWLINE = "\n";
> > /** Representing the tab string. */
> > private static final String TAB = "\t";
> > /** Representing the class string. */
> > private static final String CLASS = "class";
> > /** Representing the style string. */
> > private static final String STYLE = "style";
> > /** Representing the valign string. */
> > private static final String VALIGN = "valign";
> >
> >
> > // ---------------------------------------------------------- Public
> > Methods
> >
> >
> > @Override
> > public void encodeEnd(FacesContext context, UIComponent component)
> > throws IOException
> > {
> >
> > rendererParamsNotNull(context, component);
> >
> > if (!shouldEncode(component))
> > {
> > return;
> > }
> >
> > ResponseWriter writer = context.getResponseWriter();
> > assert (writer != null);
> >
> > String alignStr;
> > Object borderObj;
> > boolean alignVertical = false;
> > int border = 0;
> >
> >
> >
> > if (null != component.getAttributes().get("layout"))
> > {
> > alignStr = (String) component.getAttributes().get("layout");
> > alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> > }
> >
> > if (null != component.getAttributes().get(BORDER))
> > {
> > borderObj = component.getAttributes().get(BORDER);
> > border = (Integer) borderObj;
> > }
> >
> > Converter converter = null;
> > if (component instanceof ValueHolder)
> > {
> > converter = ((ValueHolder)component).getConverter();
> > }
> >
> > renderBeginText(component, border, alignVertical, context, true);
> >
> > Iterator<SelectItem> items =
> > RenderKitUtils.getSelectItems(context, component);
> >
> > Object currentSelections = getCurrentSelectedValues(component);
> > Object[] submittedValues = getSubmittedSelectedValues(component);
> > Map<String, Object> attributes = component.getAttributes();
> > OptionComponentInfo optionInfo =
> > new OptionComponentInfo((String)
> > attributes.get("disabledClass"),
> > (String)
> > attributes.get("enabledClass"),
> > (String)
> > attributes.get("unselectedClass"),
> > (String)
> > attributes.get("selectedClass"),
> >
> Util.componentIsDisabled(component),
> > isHideNoSelection(component));
> > int idx = -1;
> > while (items.hasNext())
> > {
> > SelectItem curItem = items.next();
> > idx++;
> > // If we come across a group of options, render them as a
> > nested
> > // table.
> > if (curItem instanceof SelectItemGroup)
> > {
> > // write out the label for the group.
> > if (curItem.getLabel() != null)
> > {
> > if (alignVertical)
> > {
> > writer.startElement(TR, component);
> > }
> > writer.startElement(TD, component);
> > writer.writeText(curItem.getLabel(), component,
> LABEL);
> > writer.endElement(TD);
> > if (alignVertical)
> > {
> > writer.endElement(TR);
> > }
> >
> > }
> > if (alignVertical)
> > {
> > writer.startElement(TR, component);
> > }
> > writer.startElement(TD, component);
> > writer.writeText(NEWLINE, component, null);
> > renderBeginText(component, 0, alignVertical,
> > context, false);
> > // render options of this group.
> > SelectItem[] itemsArray =
> > ((SelectItemGroup) curItem).getSelectItems();
> > for (int i = 0; i < itemsArray.length; ++i)
> > {
> > renderOption(context,
> > component,
> > converter,
> > itemsArray[i],
> > currentSelections,
> > submittedValues,
> > alignVertical,
> > i,
> > optionInfo);
> > }
> > renderEndText(component, alignVertical, context);
> > writer.endElement(TD);
> > if (alignVertical)
> > {
> > writer.endElement(TR);
> > writer.writeText(NEWLINE, component, null);
> > }
> > }
> > else
> > {
> > renderOption(context,
> > component,
> > converter,
> > curItem,
> > currentSelections,
> > submittedValues,
> > alignVertical,
> > idx,
> > optionInfo);
> > }
> > }
> >
> > renderEndText(component, alignVertical, context);
> >
> > }
> >
> > // ------------------------------------------------------- Protected
> > Methods
> >
> >
> > /**
> > * {@inheritDoc}
> > */
> > @Override
> > protected boolean isBehaviorSource(FacesContext ctx,
> > String behaviorSourceId,
> > String componentClientId)
> > {
> >
> > if (behaviorSourceId == null)
> > {
> > return false;
> > }
> > char sepChar = UINamingContainer.getSeparatorChar(ctx);
> > String actualBehaviorId =
> > behaviorSourceId.substring(0,
> > behaviorSourceId.lastIndexOf(sepChar));
> > return (actualBehaviorId.equals(componentClientId));
> >
> > }
> >
> > /**
> > * {@inheritDoc}
> > */
> > protected void renderBeginText(UIComponent component, int border,
> > boolean alignVertical, FacesContext
> > context,
> > boolean outerTable) throws IOException
> > {
> > ResponseWriter writer = context.getResponseWriter();
> > assert (writer != null);
> >
> > writer.startElement("table", component);
> > if (border != Integer.MIN_VALUE)
> > {
> > writer.writeAttribute(BORDER, border, BORDER);
> > }
> >
> > // render style and styleclass attribute on the outer table
> > instead of
> > // rendering it as pass through attribute on every option in the
> > list.
> > if (outerTable)
> > {
> > // render "id" only for outerTable.
> > if (shouldWriteIdAttribute(component))
> > {
> > writeIdAttributeIfNecessary(context, writer, component);
> > }
> > String styleClass = (String) component.getAttributes().get(
> > "styleClass");
> > String style = (String) component.getAttributes().get(STYLE);
> > if (styleClass != null)
> > {
> > writer.writeAttribute(CLASS, styleClass, CLASS);
> > }
> > if (style != null)
> > {
> > writer.writeAttribute(STYLE, style, STYLE);
> > }
> > }
> > writer.writeText(NEWLINE, component, null);
> >
> > if (!alignVertical)
> > {
> > writer.writeText(TAB, component, null);
> > writer.startElement(TR, component);
> > writer.writeText(NEWLINE, component, null);
> > }
> >
> > }
> >
> > /**
> > * {@inheritDoc}
> > */
> > protected void renderEndText(UIComponent component,
> > boolean alignVertical,
> > FacesContext context) throws IOException
> > {
> >
> > ResponseWriter writer = context.getResponseWriter();
> > assert (writer != null);
> >
> > if (!alignVertical)
> > {
> > writer.writeText(TAB, component, null);
> > writer.endElement(TR);
> > writer.writeText(NEWLINE, component, null);
> > }
> > writer.endElement("table");
> >
> > }
> >
> > /**
> > * {@inheritDoc}
> > */
> > protected void renderOption(FacesContext context,
> > UIComponent component,
> > Converter converter,
> > SelectItem curItem,
> > Object currentSelections,
> > Object[] submittedValues,
> > boolean alignVertical,
> > int itemNumber,
> > OptionComponentInfo optionInfo) throws
> > IOException
> > {
> >
> > String valueString = getFormattedValue(context, component,
> > curItem.getValue(),
> > converter);
> >
> > Object valuesArray;
> > Object itemValue;
> > if (submittedValues != null)
> > {
> > valuesArray = submittedValues;
> > itemValue = valueString;
> > }
> > else
> > {
> > valuesArray = currentSelections;
> > itemValue = curItem.getValue();
> > }
> >
> > RequestStateManager.set(context,
> >
> > RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> > component);
> >
> > boolean isSelected = isSelected(context, component, itemValue,
> > valuesArray, converter);
> > if (optionInfo.isHideNoSelection() &&
> > curItem.isNoSelectionOption() &&
> > currentSelections != null &&
> > !isSelected)
> > {
> > return;
> > }
> >
> > ResponseWriter writer = context.getResponseWriter();
> > assert (writer != null);
> >
> > if (alignVertical)
> > {
> > writer.writeText(TAB, component, null);
> > writer.startElement(TR, component);
> > writer.writeText(NEWLINE, component, null);
> > }
> > writer.startElement(TD, component);
> > writer.writeAttribute(VALIGN, "top", VALIGN);
> > writer.writeText(NEWLINE, component, null);
> >
> > writer.startElement("input", component);
> > writer.writeAttribute("name", component.getClientId(context),
> > "clientId");
> > String idString = component.getClientId(context) +
> > UINamingContainer.getSeparatorChar(context) +
> > Integer.toString(itemNumber);
> > writer.writeAttribute("id", idString, "id");
> >
> > writer.writeAttribute("value", valueString, "value");
> > writer.writeAttribute("type", "checkbox", null);
> >
> > if (isSelected)
> > {
> > writer.writeAttribute(getSelectedTextString(), Boolean.TRUE,
> > null);
> > }
> >
> > // Don't render the disabled attribute twice if the 'parent'
> > // component is already marked disabled.
> > if (!optionInfo.isDisabled())
> > {
> > if (curItem.isDisabled())
> > {
> > writer.writeAttribute("disabled", true, "disabled");
> > }
> > }
> >
> > // Apply HTML 4.x attributes specified on UISelectMany component
> > to all
> > // items in the list except styleClass and style which are
> > rendered as
> > // attributes of outer most table.
> > RenderKitUtils.renderPassThruAttributes(context,
> > writer,
> > component,
> > ATTRIBUTES,
> >
> > getNonOnClickSelectBehaviors(component));
> >
> > RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> > component);
> >
> > RenderKitUtils.renderSelectOnclick(context, component, true);
> >
> > writer.endElement("input");
> >
> > //--------------------------------------------------------
> > // New stuff for event selecting
> > //--------------------------------------------------------
> >
> > writer.endElement(TD);
> >
> > // starting the label td
> > writer.startElement(TD, component);
> > writer.writeAttribute(VALIGN, "top", VALIGN);
> > writer.writeAttribute("width", "80px", "width");
> > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> >
> > String itemLabel = curItem.getLabel();
> > if (itemLabel == null)
> > {
> > itemLabel = valueString;
> > }
> >
> > writer.writeText(" ", component, null);
> > writer.startElement(LABEL, component);
> > writer.writeAttribute("for", component.getClientId() + ":" +
> > itemNumber, "for");
> > if (!curItem.isEscape())
> > {
> > // It seems the ResponseWriter API should
> > // have a writeText() with a boolean property
> > // to determine if it content written should
> > // be escaped or not.
> > writer.write(itemLabel);
> > }
> > else
> > {
> > writer.writeText(itemLabel, component, null);
> > }
> > writer.endElement(LABEL);
> >
> > isSelected(context, component, itemValue, valuesArray,
> converter);
> > // if (isSelected(context, component, itemValue, valuesArray,
> > converter))
> > // {
> > // // selected
> > // }
> > // else
> > // {
> > // // not selected
> > // }
> > writer.endElement(TD);
> >
> > // starting the description td
> > writer.startElement(TD, component);
> > writer.writeAttribute(VALIGN, "top", VALIGN);
> > writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
> >
> > String itemLabelDesc = curItem.getDescription();
> > if (itemLabelDesc == null)
> > {
> > itemLabelDesc = "";
> > }
> > writer.writeText(" ", component, null);
> > if (!curItem.isEscape())
> > {
> > // It seems the ResponseWriter API should
> > // have a writeText() with a boolean property
> > // to determine if it content written should
> > // be escaped or not.
> > writer.write(itemLabelDesc);
> > }
> > else
> > {
> > writer.writeText(itemLabelDesc, component, null);
> > }
> >
> > writer.endElement(TD);
> >
> > //--------------------------------------------------------
> > // New stuff for event selecting end
> > //--------------------------------------------------------
> >
> > writer.writeText(NEWLINE, component, null);
> > if (alignVertical)
> > {
> > writer.writeText(TAB, component, null);
> > writer.endElement(TR);
> > writer.writeText(NEWLINE, component, null);
> > }
> > }
> >
> >
> > // ------------------------------------------------- Package Private
> > Methods
> >
> > /**
> > * {@inheritDoc}
> > */
> > String getSelectedTextString()
> > {
> > return "checked";
> > }
> > }
> >
> >
> > Any help is appreciated!
> > Thanks!
> >
> > René
> >
>
Re: Problems with a custom component when migrating from
Glassfish(mojarra) to TomEE
Posted by Thomas Andraschko <an...@gmail.com>.
I don't think that anyone will port your complete code and give you a
complete solution ;)
The biggest problem is AFAIR that the renderer implementations are not in
the API packages. So you have to rebuild all this functionality without
dependencies to the Impl.
e.g.
Attribute,AttributeManager -> String[] with attribute namens
Move all the utils functions to your own code (Util.componentIsDisabled,
RenderKitUtils.getSelectItems. etc.)
The most code doesn't really depent on the IMPL code.
2014-02-13 12:44 GMT+01:00 Rene Perschon <Ch...@gmx.net>:
> Hi everyone!
>
> I'm currently migrating an application from Glassfish 3.1.1 to TomEE. Now
> the problem is that this application contains a custom component which was
> unfortunately coded with hard dependencies on com.sun.faces classes (maven
> dependency jsf-impl).
>
> Now my question is how can i port this component in such a way that it is
> independent from any concrete JSF implementation (or at least in such a way
> that it works with MyFaces).
>
> Here's the component:
>
> import java.io.IOException;
> import java.util.Iterator;
> import java.util.Map;
>
> import javax.faces.component.UIComponent;
> import javax.faces.component.UINamingContainer;
> import javax.faces.component.ValueHolder;
> import javax.faces.context.FacesContext;
> import javax.faces.context.ResponseWriter;
> import javax.faces.convert.Converter;
> import javax.faces.model.SelectItem;
> import javax.faces.model.SelectItemGroup;
>
> import com.sun.faces.renderkit.Attribute;
> import com.sun.faces.renderkit.AttributeManager;
> import com.sun.faces.renderkit.RenderKitUtils;
> import com.sun.faces.renderkit.html_basic.MenuRenderer;
> import com.sun.faces.util.RequestStateManager;
> import com.sun.faces.util.Util;
>
> /**
> * {@inheritDoc}.
> */
> public class CustomSelectManyCheckboxListRenderer extends MenuRenderer
> {
> /** {@inheritDoc}. */
> private static final Attribute[] ATTRIBUTES =
> AttributeManager.getAttributes(AttributeManager.Key.SELECTMANYCHECKBOX);
> /** Representing the border string. */
> private static final String BORDER = "border";
> /** Representing the tr string. */
> private static final String TR = "tr";
> /** Representing the td string. */
> private static final String TD = "td";
> /** Representing the label string. */
> private static final String LABEL = "label";
> /** Representing the newline string. */
> private static final String NEWLINE = "\n";
> /** Representing the tab string. */
> private static final String TAB = "\t";
> /** Representing the class string. */
> private static final String CLASS = "class";
> /** Representing the style string. */
> private static final String STYLE = "style";
> /** Representing the valign string. */
> private static final String VALIGN = "valign";
>
>
> // ---------------------------------------------------------- Public
> Methods
>
>
> @Override
> public void encodeEnd(FacesContext context, UIComponent component)
> throws IOException
> {
>
> rendererParamsNotNull(context, component);
>
> if (!shouldEncode(component))
> {
> return;
> }
>
> ResponseWriter writer = context.getResponseWriter();
> assert (writer != null);
>
> String alignStr;
> Object borderObj;
> boolean alignVertical = false;
> int border = 0;
>
>
>
> if (null != component.getAttributes().get("layout"))
> {
> alignStr = (String) component.getAttributes().get("layout");
> alignVertical = alignStr.equalsIgnoreCase("pageDirection");
> }
>
> if (null != component.getAttributes().get(BORDER))
> {
> borderObj = component.getAttributes().get(BORDER);
> border = (Integer) borderObj;
> }
>
> Converter converter = null;
> if (component instanceof ValueHolder)
> {
> converter = ((ValueHolder)component).getConverter();
> }
>
> renderBeginText(component, border, alignVertical, context, true);
>
> Iterator<SelectItem> items =
> RenderKitUtils.getSelectItems(context, component);
>
> Object currentSelections = getCurrentSelectedValues(component);
> Object[] submittedValues = getSubmittedSelectedValues(component);
> Map<String, Object> attributes = component.getAttributes();
> OptionComponentInfo optionInfo =
> new OptionComponentInfo((String)
> attributes.get("disabledClass"),
> (String)
> attributes.get("enabledClass"),
> (String)
> attributes.get("unselectedClass"),
> (String)
> attributes.get("selectedClass"),
> Util.componentIsDisabled(component),
> isHideNoSelection(component));
> int idx = -1;
> while (items.hasNext())
> {
> SelectItem curItem = items.next();
> idx++;
> // If we come across a group of options, render them as a
> nested
> // table.
> if (curItem instanceof SelectItemGroup)
> {
> // write out the label for the group.
> if (curItem.getLabel() != null)
> {
> if (alignVertical)
> {
> writer.startElement(TR, component);
> }
> writer.startElement(TD, component);
> writer.writeText(curItem.getLabel(), component, LABEL);
> writer.endElement(TD);
> if (alignVertical)
> {
> writer.endElement(TR);
> }
>
> }
> if (alignVertical)
> {
> writer.startElement(TR, component);
> }
> writer.startElement(TD, component);
> writer.writeText(NEWLINE, component, null);
> renderBeginText(component, 0, alignVertical,
> context, false);
> // render options of this group.
> SelectItem[] itemsArray =
> ((SelectItemGroup) curItem).getSelectItems();
> for (int i = 0; i < itemsArray.length; ++i)
> {
> renderOption(context,
> component,
> converter,
> itemsArray[i],
> currentSelections,
> submittedValues,
> alignVertical,
> i,
> optionInfo);
> }
> renderEndText(component, alignVertical, context);
> writer.endElement(TD);
> if (alignVertical)
> {
> writer.endElement(TR);
> writer.writeText(NEWLINE, component, null);
> }
> }
> else
> {
> renderOption(context,
> component,
> converter,
> curItem,
> currentSelections,
> submittedValues,
> alignVertical,
> idx,
> optionInfo);
> }
> }
>
> renderEndText(component, alignVertical, context);
>
> }
>
> // ------------------------------------------------------- Protected
> Methods
>
>
> /**
> * {@inheritDoc}
> */
> @Override
> protected boolean isBehaviorSource(FacesContext ctx,
> String behaviorSourceId,
> String componentClientId)
> {
>
> if (behaviorSourceId == null)
> {
> return false;
> }
> char sepChar = UINamingContainer.getSeparatorChar(ctx);
> String actualBehaviorId =
> behaviorSourceId.substring(0,
> behaviorSourceId.lastIndexOf(sepChar));
> return (actualBehaviorId.equals(componentClientId));
>
> }
>
> /**
> * {@inheritDoc}
> */
> protected void renderBeginText(UIComponent component, int border,
> boolean alignVertical, FacesContext
> context,
> boolean outerTable) throws IOException
> {
> ResponseWriter writer = context.getResponseWriter();
> assert (writer != null);
>
> writer.startElement("table", component);
> if (border != Integer.MIN_VALUE)
> {
> writer.writeAttribute(BORDER, border, BORDER);
> }
>
> // render style and styleclass attribute on the outer table
> instead of
> // rendering it as pass through attribute on every option in the
> list.
> if (outerTable)
> {
> // render "id" only for outerTable.
> if (shouldWriteIdAttribute(component))
> {
> writeIdAttributeIfNecessary(context, writer, component);
> }
> String styleClass = (String) component.getAttributes().get(
> "styleClass");
> String style = (String) component.getAttributes().get(STYLE);
> if (styleClass != null)
> {
> writer.writeAttribute(CLASS, styleClass, CLASS);
> }
> if (style != null)
> {
> writer.writeAttribute(STYLE, style, STYLE);
> }
> }
> writer.writeText(NEWLINE, component, null);
>
> if (!alignVertical)
> {
> writer.writeText(TAB, component, null);
> writer.startElement(TR, component);
> writer.writeText(NEWLINE, component, null);
> }
>
> }
>
> /**
> * {@inheritDoc}
> */
> protected void renderEndText(UIComponent component,
> boolean alignVertical,
> FacesContext context) throws IOException
> {
>
> ResponseWriter writer = context.getResponseWriter();
> assert (writer != null);
>
> if (!alignVertical)
> {
> writer.writeText(TAB, component, null);
> writer.endElement(TR);
> writer.writeText(NEWLINE, component, null);
> }
> writer.endElement("table");
>
> }
>
> /**
> * {@inheritDoc}
> */
> protected void renderOption(FacesContext context,
> UIComponent component,
> Converter converter,
> SelectItem curItem,
> Object currentSelections,
> Object[] submittedValues,
> boolean alignVertical,
> int itemNumber,
> OptionComponentInfo optionInfo) throws
> IOException
> {
>
> String valueString = getFormattedValue(context, component,
> curItem.getValue(),
> converter);
>
> Object valuesArray;
> Object itemValue;
> if (submittedValues != null)
> {
> valuesArray = submittedValues;
> itemValue = valueString;
> }
> else
> {
> valuesArray = currentSelections;
> itemValue = curItem.getValue();
> }
>
> RequestStateManager.set(context,
>
> RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME,
> component);
>
> boolean isSelected = isSelected(context, component, itemValue,
> valuesArray, converter);
> if (optionInfo.isHideNoSelection() &&
> curItem.isNoSelectionOption() &&
> currentSelections != null &&
> !isSelected)
> {
> return;
> }
>
> ResponseWriter writer = context.getResponseWriter();
> assert (writer != null);
>
> if (alignVertical)
> {
> writer.writeText(TAB, component, null);
> writer.startElement(TR, component);
> writer.writeText(NEWLINE, component, null);
> }
> writer.startElement(TD, component);
> writer.writeAttribute(VALIGN, "top", VALIGN);
> writer.writeText(NEWLINE, component, null);
>
> writer.startElement("input", component);
> writer.writeAttribute("name", component.getClientId(context),
> "clientId");
> String idString = component.getClientId(context) +
> UINamingContainer.getSeparatorChar(context) +
> Integer.toString(itemNumber);
> writer.writeAttribute("id", idString, "id");
>
> writer.writeAttribute("value", valueString, "value");
> writer.writeAttribute("type", "checkbox", null);
>
> if (isSelected)
> {
> writer.writeAttribute(getSelectedTextString(), Boolean.TRUE,
> null);
> }
>
> // Don't render the disabled attribute twice if the 'parent'
> // component is already marked disabled.
> if (!optionInfo.isDisabled())
> {
> if (curItem.isDisabled())
> {
> writer.writeAttribute("disabled", true, "disabled");
> }
> }
>
> // Apply HTML 4.x attributes specified on UISelectMany component
> to all
> // items in the list except styleClass and style which are
> rendered as
> // attributes of outer most table.
> RenderKitUtils.renderPassThruAttributes(context,
> writer,
> component,
> ATTRIBUTES,
>
> getNonOnClickSelectBehaviors(component));
>
> RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer,
> component);
>
> RenderKitUtils.renderSelectOnclick(context, component, true);
>
> writer.endElement("input");
>
> //--------------------------------------------------------
> // New stuff for event selecting
> //--------------------------------------------------------
>
> writer.endElement(TD);
>
> // starting the label td
> writer.startElement(TD, component);
> writer.writeAttribute(VALIGN, "top", VALIGN);
> writer.writeAttribute("width", "80px", "width");
> writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
>
> String itemLabel = curItem.getLabel();
> if (itemLabel == null)
> {
> itemLabel = valueString;
> }
>
> writer.writeText(" ", component, null);
> writer.startElement(LABEL, component);
> writer.writeAttribute("for", component.getClientId() + ":" +
> itemNumber, "for");
> if (!curItem.isEscape())
> {
> // It seems the ResponseWriter API should
> // have a writeText() with a boolean property
> // to determine if it content written should
> // be escaped or not.
> writer.write(itemLabel);
> }
> else
> {
> writer.writeText(itemLabel, component, null);
> }
> writer.endElement(LABEL);
>
> isSelected(context, component, itemValue, valuesArray, converter);
> // if (isSelected(context, component, itemValue, valuesArray,
> converter))
> // {
> // // selected
> // }
> // else
> // {
> // // not selected
> // }
> writer.endElement(TD);
>
> // starting the description td
> writer.startElement(TD, component);
> writer.writeAttribute(VALIGN, "top", VALIGN);
> writer.writeAttribute(STYLE, "padding-top:4px", STYLE);
>
> String itemLabelDesc = curItem.getDescription();
> if (itemLabelDesc == null)
> {
> itemLabelDesc = "";
> }
> writer.writeText(" ", component, null);
> if (!curItem.isEscape())
> {
> // It seems the ResponseWriter API should
> // have a writeText() with a boolean property
> // to determine if it content written should
> // be escaped or not.
> writer.write(itemLabelDesc);
> }
> else
> {
> writer.writeText(itemLabelDesc, component, null);
> }
>
> writer.endElement(TD);
>
> //--------------------------------------------------------
> // New stuff for event selecting end
> //--------------------------------------------------------
>
> writer.writeText(NEWLINE, component, null);
> if (alignVertical)
> {
> writer.writeText(TAB, component, null);
> writer.endElement(TR);
> writer.writeText(NEWLINE, component, null);
> }
> }
>
>
> // ------------------------------------------------- Package Private
> Methods
>
> /**
> * {@inheritDoc}
> */
> String getSelectedTextString()
> {
> return "checked";
> }
> }
>
>
> Any help is appreciated!
> Thanks!
>
> René
>