1

If I pass an expression to a composite component like

<My:myButton action="#{bean.myaction()" value="#{bean.buttText()}"

and try to use it in

<cc:implementation>
 <h:commandButton actionListener="#{cc.attrs.action} value="#{cc.attrs.value}...

I get the exception "Target Unreachable, identifier 'bean' resolved to null".

But only if bean is a <ui:param name="bean" value="#{myRealBean}"/> inside a template. The error only occours with actionListener. The button text, resolved from the same bean in the same way will be shown.

This old question seems to have the same problem but no answer.

If I split the parameter to

<My:myButton bean="#{bean}" method="myaction" value="#{bean.buttText()}"

and use

<cc:implementation>
<h:commandButton actionListener="#{cc.attrs.bean[cc.attrs.method]()} ...

no error occours and everything works fine.

How can I use a function-expression in an actionListener inside a composite component, where the bean is a <ui:param?

Glassfish 4.1.1, Mojarra 2.2.12

And now, the MCVE

a bean:

package beans;

import java.io.Serializable;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named
@ViewScoped
public class Testbean implements Serializable {
    public String getButtText() { return "Submit"; }
    public void doAction() { System.out.println("Ajax was here."); }
}

a page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html    xmlns="http://www.w3.org/1999/xhtml"  xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html"
         xmlns:ST="http://java.sun.com/jsf/composite/softeam" >
<h:head>
</h:head>
<h:body>
    <h:form id="testform">
        <h:panelGrid columns="1">
            <ui:include src="testtemplate.xhtml">
                <ui:param name="bean" value="#{testbean}"/>
            </ui:include>
            <ST:testButt text="#{testbean.buttText}" action="#{testbean.doAction()}"/>
            <h:commandButton value="#{testbean.buttText}" actionListener="#{testbean.doAction()}"/>
        </h:panelGrid>
    </h:form>
</h:body>
</html>

and a template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:ST="http://java.sun.com/jsf/composite/softeam">

        <ST:testButt text="#{bean.buttText}" action="#{bean.doAction()}"/>
        <h:commandButton value="#{bean.buttText}" action="#{bean.doAction()}" />
</ui:composition>

and the component

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:S="http://xmlns.jcp.org/jsf/composite" >
    <S:interface>
        <S:attribute name="action" method-signature="void action()"/>
        <S:attribute name="text"   type="java.lang.String"/>
    </S:interface>

    <S:implementation>
        <h:commandButton style="display:inline-block"
                         value="#{cc.attrs.text}"
                         actionListener="#{cc.attrs.action}"
        />
    </S:implementation>
</html>

All buttons will be shown (with the bean.buttText()) but only the second, third and fourth will call the action. The first button throws an exception when clicked.

Edit: Example reduced to JSF, no PrimeFaces components.

Holger
  • 899
  • 2
  • 7
  • 12
  • The other question is not identical imo since it is about a property not found exception. But it might be related if you are using the same old Mojarra 2.1.7. Tried a newer version? Oh and please make an [mcve] to so others can see you don't have any other mistakes. – Kukeltje Jan 15 '19 at 13:05
  • Great [mcve] Some questions still: Does it fail too when not using ajax on the buttons or the partial submits? Does it also fail with a plain `h:commandButton`? Can you try adding a `type="java.lang.Object"` to the ` – Kukeltje Jan 15 '19 at 14:24
  • I've changed all buttons to `` in the main page. All but the first button are ok. With `type="java.lang.Object"` the page doesn't appear. NullPointerException in `com.sun.faces.application.view.FaceletViewHandlingStrategy$MethodRetargetHandlerManager$ArbitraryMethodRegargetHandler.retarget` – Holger Jan 15 '19 at 15:46
  • Can you please add/change the `h:`/`p:` things and the additional button in the Q too? So if I try to reproduce I know I have the same source. And sure the NPE is caused by the `type="java.lang.Object"`? Not by adding a `targets` or did you add both? – Kukeltje Jan 15 '19 at 15:53
  • No, I only replaced `method-signature` with `type`. I've edited the question. – Holger Jan 16 '19 at 07:51
  • 1
    I'll try tonight if I can reproduce on wildfly 13 – Kukeltje Jan 16 '19 at 14:55

0 Answers0