[
http://issues.apache.org/jira/browse/MYFACES-856?page=comments#action_12358218
]
Mario Ivankovits commented on MYFACES-856:
------------------------------------------
Hi Simon,
I use the following HACK to create the alias right after the view is restored:
We also use <x:aliasBeansScope>, dont know if this make a difference for this
"solution"
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Locale;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import org.apache.commons.logging.Log;
import org.apache.myfaces.custom.aliasbean.AliasBean;
import com.ops.OPSJ.lib.Application;
import com.ops.OPSJ.lib.ApplicationObjectInterface;
import com.ops.OPSJ.lib.OLog;
public class ViewHandler extends javax.faces.application.ViewHandler
{
private final javax.faces.application.ViewHandler original;
public ViewHandler(javax.faces.application.ViewHandler original)
{
this.original = original;
}
public UIViewRoot restoreView(FacesContext facesContext, String viewId)
{
UIViewRoot root = original.restoreView(facesContext, viewId);
if (root != null)
{
processAliases(facesContext, root);
}
return root;
}
protected void processAliases(FacesContext context, UIComponent root)
{
if (root == null)
{
return;
}
for (Iterator it = root.getFacetsAndChildren(); it.hasNext(); )
{
UIComponent component = (UIComponent)it.next();
if (component instanceof AliasBean)
{
AliasBean alias = (AliasBean) component;
try
{
Method makeAliasMethod =
alias.getClass().getDeclaredMethod("makeAlias", FacesContext.class);
makeAliasMethod.setAccessible(true);
makeAliasMethod.invoke(alias, context);
}
catch (NoSuchMethodException e)
{
log.warn(e.getLocalizedMessage(), e);
}
catch (IllegalAccessException e)
{
log.warn(e.getLocalizedMessage(), e);
}
catch (InvocationTargetException e)
{
log.warn(e.getLocalizedMessage(), e);
}
}
processAliases(context, component);
}
}
@Override
public Locale calculateLocale(FacesContext context)
{
return original.calculateLocale(context);
}
@Override
public String calculateRenderKitId(FacesContext context)
{
return original.calculateRenderKitId(context);
}
@Override
public String getResourceURL(FacesContext context, String url)
{
return original.getResourceURL(context, url);
}
@Override
public void renderView(FacesContext context, UIViewRoot uiRoot) throws
IOException, FacesException
{
original.renderView(context, uiRoot);
}
@Override
public void writeState(FacesContext context) throws IOException
{
original.writeState(context);
}
}
> t:aliasBean + binding + panelGrid causes exception
> --------------------------------------------------
>
> Key: MYFACES-856
> URL: http://issues.apache.org/jira/browse/MYFACES-856
> Project: MyFaces
> Type: Bug
> Reporter: Simon Kitching
>
> The following use of t:aliasBean causes an exception:
> ==== including page
> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
> <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
> <f:view>
> <h:panelGrid>
> <t:aliasBean alias="#{target}" value="#{someBean}">
> <jsp:include page="included.jsp"/>
> </t:aliasBean>
> </h:panelGrid>
> </f:view>
> ==== included page
> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
> <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
> <f:subview id="foo">
> <h:inputText binding="#{target.input}"/>
> </f:subview>
> The thrown exception is:
> javax.faces.el.PropertyNotFoundException: Base is null: target
> at
> org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(ValueBindingImpl.java:457)
> at
> org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java:245)
> at
> org.apache.myfaces.application.ApplicationImpl.createComponent(ApplicationImpl.java:434)
> I believe the problem is that panelGrid renders its children. This means that
> the components are first created, then the panelGrid iterates over them to
> render them. However the alias bean hasn't set up the alias at the time the
> components are being created. And ApplicationImpl.createComponent(binding,
> context, componentType) is immediately evaluating the binding expression,
> resulting in the target bean for the binding not being found.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira