Target p:remoteCommand with cc:attribute inside of ui:composition

UI Components for JSF
Post Reply
FP93
Posts: 2
Joined: 07 Jul 2017, 16:58

22 Aug 2017, 15:40

I try to build my own JSF-component with ui:composition. When I use an action-attribute that targets a remoteCommand (Primefaces), I came accross some problems: As long as I use the action attribute for all elements of that component inside of h:form, my code seems to work. However, when I use the action attribute only for some elements, the method of my bean is never called for any element.

This is my code:

1,

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html   xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:cc="http://java.sun.com/jsf/composite"
        xmlns:p="http://primefaces.org/ui">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
    <ui:composition>
        <cc:interface>
            <cc:attribute name="id" />
            <cc:attribute name="action" targets="remote" />
        </cc:interface>
        <cc:implementation>
            <p:remoteCommand id="remote" name="remoteCommand" />
            <input onclick="remoteCommand();" />
        </cc:implementation>
    </ui:composition>
</h:body>
</html>
2,

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html   xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:mycomponent="http://java.sun.com/jsf/composite/composites">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <h:outputStylesheet library="styles" name="ownContainers.css"  />
</h:head>
<h:body>
    <h:form> 
        <mycomponent:input action="#{testBean.test()}" />
        <mycomponent:input />
    </h:form>
</h:body>
</html>

The previous code does not work! When I click on the first input field, my bean method is not executed.

However, when I include the action attribute also in the second input field, my bean method is executed:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html   xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:mycomponent="http://java.sun.com/jsf/composite/composites">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <h:outputStylesheet library="styles" name="ownContainers.css"  />
</h:head>
<h:body>
    <h:form> 
        <mycomponent:input action="#{testBean.test()}" />
        <mycomponent:input action="#{testBean.test()}" />
    </h:form>
</h:body>
</html>
What can I do when I just need the action attribute for some elements and not for others? Why is the first example not working?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 39 guests