0

I have to write a composite component that shows a login form and can be used with the following code snippet:

<login:loginForm username="#{loginBean.username}" 
                 password="#{loginBean.password}" 
                 action="#{loginBean.login}"/>

My loginBean is just a simple serializable @ViewScoped @ManagedBean with getters, setters and a public String login() method.

This is my composite component:

<body>
    <cc:interface>
        <cc:attribute name="username" required="true" type="java.lang.String" />
        <cc:attribute name="password" required="true" type="java.lang.String" />
        <cc:attribute name="action" targets="submit" required="true" method-signature="java.lang.String f()"/>
    </cc:interface>

    <cc:implementation>
        <h3><span xml:lang="en">Login</span> Daten </h3>
        <h:form>
            <div class="formblock">
                <fieldset>
                    <div>
                        <h:outputLabel value="Username" for="username"/>
                        <h:inputText id="username" value="#{cc.attrs.username}"/>
                    </div>

                    <div>
                        <h:outputLabel value="Passwort" for="password"/>
                        <h:inputSecret id="password" value="#{cc.attrs.password}"/>
                    </div>
                </fieldset>
            </div>
            <div class="buttons">
                <h:commandButton id="submit" value="Anmelden" accesskey="r" />
            </div>
        </h:form>
    </cc:implementation>
</body>

But, when I open the login.xhtml page (which contains the login:loginForm-snippet) in the browser, I can see the following Error in the jetty log:

Apr 29, 2012 11:59:49 PM org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage retargetMethodExpressions
SEVERE: Inner component submit not found when retargetMethodExpress

But what does that mean? Where is the mistake in my code? I already tried some other solutions for implementing the action attribute, but without success.

Ethan Leroy
  • 15,804
  • 9
  • 41
  • 63
  • Just saw that I used myfaces version 2.0.4 instead of the current 2.1.7 release. So, upgraded and now the error is gone. But the action still is not executed when clicking the command button. – Ethan Leroy Apr 29 '12 at 23:06

2 Answers2

1

Ok. After upgrading to myfaces version 2.1.7 the straigt-forward solution without the target-stuff works:

<body>
    <cc:interface>
        <cc:attribute name="username" required="true" type="java.lang.String" />
        <cc:attribute name="password" required="true" type="java.lang.String" />
        <cc:attribute name="action" required="true" method-signature="java.lang.String f()"/>
    </cc:interface>

    <cc:implementation>
        <h3><span xml:lang="en">Login</span> Daten </h3>
        <h:form>
            <div class="formblock">
                <fieldset>
                    <div>
                        <h:outputLabel value="Username" for="username"/>
                        <h:inputText id="username" value="#{cc.attrs.username}"/>
                    </div>

                    <div>
                        <h:outputLabel value="Passwort" for="password"/>
                        <h:inputSecret id="password" value="#{cc.attrs.password}"/>
                    </div>
                </fieldset>
            </div>
            <div class="buttons">
                <h:commandButton action="#{cc.attrs.action}" value="Anmelden" accesskey="r" />
            </div>
        </h:form>
    </cc:implementation>
</body>
Ethan Leroy
  • 15,804
  • 9
  • 41
  • 63
0

The target="submit" is incorrect, because h:form is NamingContainer, so you need to assign and id to that component and change target to "myForm:submit" or something like that.

lu4242
  • 2,318
  • 1
  • 15
  • 15
  • You mean I should replace `targets="submit"` with `targets="myForm:submit"` and `` with `` and then it should work? – Ethan Leroy May 04 '12 at 10:48