Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Frequently Asked Questions

NOTE: THE DOCUMENTATION HAS BEEN MOVED TO http://myfaces.apache.org/wiki/core/faq.html

Note that in addition to this FAQ, there are a number of "how-to" guides on the MyFaces wiki home page that address common issues.

Table of Contents
maxLevel4
minLevel2

What is MyFaces?

MyFaces is a family of projects related to the JavaServer Faces (JSF) specification published as part of the Java Community Process. The "core" project is an implementation of that specification. Other MyFaces projects implement related specifications (eg the Portlet Bridge), or add features to any JSF implementation (not just the Myfaces Core).

...

Code Block
titleSomeManagedBean.java
borderStylesolid

public class SomeManagedBean implements Serializable {
  private List myData;

  private transient DataModel myDataModel;

  public DataModel getDataModel() {
    if (myDataModel == null) {
      myDataModel = new ListDataModel(myData);
    }
    return myDataModel;
  }
}

...

You can control the timezone used by the conversion by attaching an explicit converter:

Code Block
xml
xml

    <f:convertDateTime timeZone="Antarctica/South_Pole"  .../>

or

Code Block
xml
xml

    <f:convertDateTime timeZone="#{bean.timeZone}"  .../>

...

The MyFaces commons converters project contains a custom converter tag which is like f:convertDateTime, but defaults to using the timezone of the server:

Code Block
xml
xml

    <mcc:convertDateTime/>

Alternatively you register your own converter to override the standard converter, causing your custom code to be applied by default to all date->string conversions.

...

In some cases, a component in a JSP page needs to reference another component by id. One common example is the tomahawk t:dataScroller component. This is fine when the referencing component is later in the page than the one it refers to. But when the components are in the wrong order, an error is reported.

Code Block
xml
xml


  <t:dataScroller for="someTable" .../>

  <t:dataTable id="someTable" .../>

...

This can be resolved by wrapping the components in a parent component that "renders its children". Such components cause their nested components to be processed in two passes (create then render):

Code Block
xml
xml

  <h:panelGroup>
    <t:dataScroller for="someTable" .../>
    <t:dataTable id="someTable" .../>
  </h:panelGroup>

...

  • defining a setter method on the bean, eg "public void setInitialized(boolean state)"
  • defining this as the last managed property for the bean:
Code Block
xml
xml

  <managed-bean>
    ....
    <managed-property>
      <property-name>initialized</property-name>
      <value>true</value>
    </managed-property>
  </managed-bean>

...

The JSF specification requires any JSF implementation to automatically load /WEB-INF/faces-config.xml at startup. There is consequently no need for the following context parameter:

Code Block
xml
xml

<context-param>
   <param-name>javax.faces.CONFIG_FILES</param-name>
   <param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

...

Action listeners and actions are not invoked when the action source ( h:commandLink, h:commandButton ) is not rendered. When our action sources are on a dataTable, and the value attribute of the dataTable points to a request scoped data source, the action source just isn't rendered on a subsequent request.

Code Block
xml
xml

<h:dataTable value="#{requestScopedBean.dataModel.wrappedData}" />
	<h:column>
		<h:commandLink value="click here" action="#{backingBean.willNotFire}" />
	</h:column>
</h:dataTable>

...

To solve this problem, use t:saveState or put the request scoped backing bean in session scope.

Code Block
xml
xml

<t:saveState value="#{myRequestScopedBean.dataModel.wrappedData}" />

...

NullPointerException in adf faces at the start of the render phase OR rendering warnings

Code Block

Mar 21, 2006 12:10:15 AM org.apache.myfaces.renderkit.html.HtmlRenderKitImpl getRenderer WARNING: Unsupported component-family/renderer-type: oracle.adf.Panel/oracle.adf.Group
Mar 21, 2006 12:10:15 AM oracle.adf.view.faces.component.UIXComponentBase _getRendererImpl WARNING: Could not find renderer for CorePanelGroup[UIXFacesBeanImpl, id=_id38], rendererType = oracle.adf.Group
Mar 21, 2006 12:10:15 AM org.apache.myfaces.renderkit.html.HtmlRenderKitImpl getRenderer WARNING: Unsupported component-family/renderer-type: oracle.adf.Command/oracle.adf.Link
Mar 21, 2006 12:10:15 AM oracle.adf.view.faces.component.UIXComponentBase _getRendererImpl WARNING: Could not find renderer for CoreCommandLink[CommandLinkFacesBean, id=_id41], rendererType = oracle.adf.Link
Mar 21, 2006 12:10:15 AM org.apache.myfaces.renderkit.html.HtmlRenderKitImpl getRenderer WARNING: Unsupported component-family/renderer-type: oracle.adf.Output/oracle.adf.Formatted
SEVERE: Error Rendering View[/main.xhtml] java.lang.NullPointerException at 
oracle.adfinternal.view.faces<WBR>.uinode.FacesRenderingContext<WBR>.setRenderingProperty(FacesRenderingContext.java:157) at 
oracle.adfinternal.view.faces<WBR>.ui.RenderedNodeRenderingContex<WBR>t.setProperty(RenderedNodeRenderingContext<WBR>.java:162) at 
oracle.adfinternal.view.faces<WBR>.ui.RootRenderingContext.init(RootRenderingContext.java:81) at oracle.adfinternal.view.faces<WBR>.uinode.FacesRenderingContext.
(FacesRenderingContext.java:106) at oracle.adfinternal.view.faces<WBR>.uinode.FacesRenderingContext<WBR>.createRenderingContext(FacesRenderingContext.java:79) 
at oracle.adfinternal.view.faces<WBR>.uinode.UINodeRendererBase<WBR>.getRenderingContext(UINodeRendererBase.java:89) at 
oracle.adfinternal.view.faces<WBR>.uinode.FacesRenderingContext<WBR>.getRenderingContext(FacesRenderingContext.java:66) at 
oracle.adfinternal.view.faces<WBR>.uinode.FacesRenderingContext<WBR>.getRenderingContext(FacesRenderingContext.java:52) at 
oracle.adfinternal.view.faces<WBR>.renderkit.htmlBasic.UINodeRend<WBR>erer.getRenderingContext(UINodeRenderer.java:79) at 
oracle.adfinternal.view.faces<WBR>.renderkit.htmlBasic.UINodeRend<WBR>erer.encodeBegin(UINodeRenderer.java:38) at 
javax.faces.component.UICompone<WBR>ntBase.encodeBegin(UIComponentBase.java:512) at 
com.sun.facelets.FaceletViewHan<WBR>dler.encodeRecursive(FaceletViewHandler.java:555) at 
com.sun.facelets.FaceletViewHan<WBR>dler.encodeRecursive(FaceletViewHandler.java:562) at 
com.sun.facelets.FaceletViewHan<WBR>dler.encodeRecursive(FaceletViewHandler.java:562) at 
com.sun.facelets.FaceletViewHan<WBR>dler.renderView(FaceletViewHandler.java:457) at 
org.apache.myfaces.lifecycle<WBR>.LifecycleImpl.render(LifecycleImpl.java:367) at 
javax.faces.webapp.FacesServlet<WBR>.service(FacesServlet.java:138) at 
org.apache.catalina.core<WBR>.ApplicationFilterChain<WBR>.internalDoFilter(ApplicationFilterChain.java:252) at 
org.apache.catalina.core<WBR>.ApplicationFilterChain<WBR>.doFilter(ApplicationFilterChain.java:173) at 
org.apache.myfaces.webapp<WBR>.filter.ExtensionsFilter<WBR>.doFilter(ExtensionsFilter.java:130) at 
org.apache.catalina.core<WBR>.ApplicationFilterChain<WBR>.internalDoFilter(ApplicationFilterChain.java:202) at 
org.apache.catalina.core<WBR>.ApplicationFilterChain<WBR>.doFilter(ApplicationFilterChain.java:173) at 
org.apache.catalina.core<WBR>.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at 
org.apache.catalina.core<WBR>.StandardContextValve.invoke(StandardContextValve.java:178) at 
org.apache.catalina.authenticat<WBR>or.AuthenticatorBase.invoke(AuthenticatorBase.java:432) at 
org.apache.catalina.core<WBR>.StandardHostValve.invoke(StandardHostValve.java:126) at 
org.apache.catalina.valves<WBR>.ErrorReportValve.invoke(ErrorReportValve.java:105) at 
org.apache.catalina.core<WBR>.StandardEngineValve.invoke(StandardEngineValve.java:107) at 
org.apache.catalina.connector<WBR>.CoyoteAdapter.service(CoyoteAdapter.java:148) at 
org.apache.coyote.http11<WBR>.Http11Processor.process(Http11Processor.java:869) at 
org.apache.coyote.http11<WBR>.Http11BaseProtocol$Http11Conne<WBR>ctionHandler.processConnection(Http11BaseProtocol.java:667) at 
org.apache.tomcat.util.net<WBR>.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at 
org.apache.tomcat.util.net<WBR>.LeaderFollowerWorkerThread<WBR>.runIt(LeaderFollowerWorkerThread.java:80) at 
org.apache.tomcat.util.threads<WBR>.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at 
java.lang.Thread.run(Thread.java:595)

...

MyFaces 1.1.4 and earlier did not correctly implement the select components. Although the behavior was nice, the components were not supposed to convert the values from the UISelectItems. For example, in 1.1.4 this would have worked:

Code Block
xml
xml

<f:selectOneMenu value="#{bean.intValue}"><f:selectItem itemValue="1" /></selectOneMenu>

...

Code Block
titleUISelectItem.java
borderStylesolid

public class UISelectItem
  extends javax.faces.component.UISelectItem
{
  public final static String COMPONENT_TYPE = "org.apache.myfaces.wiki.SelectItem";
  private Boolean convertValue;

  /**
   * @return the convertValue
   */
  public boolean getConvertValue()
  {
    if (this.convertValue != null) return this.convertValue;
    ValueBinding vb = getValueBinding("convertValue");
    return (vb == null) ? true : (Boolean) vb.getValue(getFacesContext());
  }

  /**
   * @param convertValue the convertValue to set
   */
  public void setConvertValue(boolean convertValue)
  {
    this.convertValue = convertValue;
  }

  /**
   * @see javax.faces.component.UISelectItem#getItemValue()
   */
  @Override
  public Object getItemValue()
  {
    Object value = super.getItemValue();
    
    if (getConvertValue())
    {
      UIInput parent = null;
      for (UIComponent comp = getParent(); comp != null; comp = comp.getParent())
      {
        if (comp instanceof UIInput)
        {
          parent = (UIInput)comp;
          break;
        }
      }
      if (parent != null)
        value = getConvertedValue(getFacesContext(), parent, value);
    }
    return value;
  }

  /**
   * @see javax.faces.component.UISelectItem#saveState(javax.faces.context.FacesContext)
   */
  @Override
  public Object saveState(FacesContext context)
  {
    return new Object[] {
      super.saveState(context), convertValue, };
  }

  /**
   * @see javax.faces.component.UISelectItem#restoreState(javax.faces.context.FacesContext, java.lang.Object)
   */
  @Override
  public void restoreState(FacesContext context, Object state)
  {
    Object[] arr = (Object[]) state;
    int index = -1;
    super.restoreState(context, arr[++index]);
    this.convertValue = (Boolean) arr[++index];
  }

  private Object getConvertedValue(FacesContext context, UIInput input, Object value)
    throws ConverterException
  {
    Renderer renderer = getRenderer(context);
    if (renderer != null)
      return renderer.getConvertedValue(context, this, value);
    else if (value instanceof String)
    {
      Converter converter = RendererUtils.findUIOutputConverter(
        context, input);
      if (converter != null)
        return converter.getAsObject(context, this, (String)value);
    }
    return value;
  }
}

...