Page 1 of 1

Quick skim through the prime faces cookbook

Posted: 25 Feb 2019, 13:00
by Eduardo48
I have a quick skim through the primefaces cookbook but I still do not quite understand how to use p:component. Maybe, I am blind or stupid. Do you mind giving me a simple example how to use it.

Let use the case in the DynaForm example, and use the "basic usage" example which has "Author" and "ISBN" as input text field. Assume that when the form get generated these two fields will be rendered but they can appear in any order and in any row, i.e. you do not know where they are. And assume that I need to perform a javascript that need to access the content of both "Author" and "ISBN" for processing when the user presss the "Submit" button.

My question is how to I write a javascript to access the content of "Author" and "ISBN" since I do not know what their ids before build time since they can be anywhere and this will affect the ids being generated. Sorry, might be a simple question, I am weak in Javascripts.

Thanks

Re: Quick skim through the prime faces cookbook

Posted: 25 Feb 2019, 14:26
by Melloware
I will let @Rapster answer this one he is the DynaForm expert.

Re: Quick skim through the prime faces cookbook

Posted: 27 May 2019, 18:26
by Babas007
I'm working on a similar feature: https://stackoverflow.com/questions/563 ... components

Based on your use case scenario, I recommand to have a look at this: https://www.primefaces.org/showcase-ext ... ientId.jsf

The dirty workaround is to write something like:

Code: Select all

 <pe:dynaForm id="dynaForm" value="#{containerDynaFormController.model}" var="data" varContainerId="ccId">
    <pe:dynaFormControl type="INPUT">
         <p:inputText id="_input" value="#{bean.property}" 
         <p:button value="Click" onclick="callbackDynaButton(#{ccId}:_input)" />
    </pe:dynaFormControl>
</pe:dynaForm>
And in your page:

Code: Select all

<script>
    function callbackDynaButton(id) {
        alert(id);
    }
</script