p:component question

UI Components for JSF
Post Reply
burferd
Posts: 234
Joined: 01 May 2010, 16:15

11 Jun 2010, 00:10

This is an offshoot of my last question.
I've put together a composite component that looks something like this:

Code: Select all

<cc:implementation>
    <h:form id="formId" ...>
        <h:inputText id="inputFieldId" .../>
        <h:graphicImage id="imageId" .../>
   <h:form/>
        <script type="text/javascript">
            SelectItem.setup(
            {
                inputField     :    "#{p:component('inputFieldId')}",
                image          :    "#{p:component('imageId')}"
            }
            );
        </script>
<cc:implementation/>
This works just fine if you have a single instance of this component on the page.
If you have more than one instance, the reference obtained by the p:component functions are are the same.
As a result, the ids passed into the setup() function for both components are the same.

I figured that to get around this, I would make the ids attributes, so I end up with something that looks like this:

Code: Select all

<cc:interface>
    <cc:attribute name="textField" required="true" />
    <cc:attribute name="image" required="true" />
</cc:interface>
<cc:implementation>
    <h:form id="formId" ...>
        <h:inputText id="#{cc.attrs.textField}" .../>
        <h:graphicImage id="#{cc.attrs.image" .../>
   <h:form/>
        <script type="text/javascript">
            SelectItem.setup(
            {
                inputField     :    "#{p:component(?????)}",
                image          :    "#{p:component(?????)}"
            }
            );
        </script>
<cc:implementation/>
I think this would work, since it would give inputField and image in the setup() function unique ids.
The problem is I don't know the correct syntax for the p:component functions in the following:
inputField : "#{p:component(?????)}",
image : "#{p:component(?????)}"

Any suggestions on how to pass an expression like ="#{cc.attrs.textField}" into a p:component() function in this context?

Thanks.
Using PrimeFaces 3.4, Mojarra 2.1.6, Glassfish 3.1.2, NetBerans 7.2, Hibernate 3.2.5 (sometimes)
Windows 7.

callahan
Posts: 768
Joined: 27 May 2010, 22:52

11 Jun 2010, 10:34

I haven't been using PrimeFaces for long, but I'd imagine that #{p:component('component-name')} has been around longer that JSF 2.0 and may not have been designed for usage in composite components. Use #{cc.clientId} inside composite components instead. Reread the answers to your last question for more information http://primefaces.prime.com.tr/forum/vi ... f=3&t=2704.

burferd
Posts: 234
Joined: 01 May 2010, 16:15

11 Jun 2010, 19:23

Thanks, that works.
Using PrimeFaces 3.4, Mojarra 2.1.6, Glassfish 3.1.2, NetBerans 7.2, Hibernate 3.2.5 (sometimes)
Windows 7.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 64 guests