0

i am having some problems because i want to show in some inputText field the value store in selectedIncident attribute so the user could edit the current value. I saw in other question something similar and they used javascript, i try what it does not work for me.

I have an accordion pannel and when i click on a tab it opens and the data of that incident is stored in selectedIncident (this works fine), inside the tab i have a button to edit the data and when i click on it a dialog opens put the fields of title and description are empty.

<h:form id="idFormAllIncidents">
    <p:accordionPanel id="panelDetailIncident" value="#{incidentBean.allIncidents}" var="incident" dynamic="true" activeIndex="-"> 
        <p:ajax event="tabChange"  listener="#{incidentBean.onTabChange}" immediate="true"/>

        <p:tab title="#{incident.title}">
            <h:outputText value="#{incident.description}"/>

            <p:commandButton id ="editButton" value="Edit Incident" type="button" onclick="PF('dlg2').show();myFunction();"/>

            <p:messages id="message" showDetail="true" autoUpdate="true" closable="true" /> 
        </p:tab>
    </p:accordionPanel>

    <p:dialog id="editIncDialog" header="Edit Incident" widgetVar="dlg2" minHeight="40" >
        <p:ajax event="close" listener="#{incidentBean.handleClose}" /> 
        <h:form id="editInc">
            <p:outputLabel value="Title:"/>
            <h:inputText id="editTitle" value="#{incidentBean.title}" required="true" requiredMessage="Titulo necesarios"/>

            <p:outputLabel value="Description: "/>
            <p:inputTextarea id="editDescription" value="#{incidentBean.description}" rows="10" cols="50" counter="display" maxlength="200" counterTemplate="{0} caracteres restantes" autoResize="false" required="true" requiredMessage="Descripción necesaria"/>

            <p:outputLabel id="display"/>

            <p:commandButton value="Send Incident" action="#{incidentBean.editIncident()}" onclick="dlg1.hide()" />
                        <p:messages id="messages" for="title" showDetail="true" autoUpdate="true" closable="true" /> 
        </h:form>
    </p:dialog>  
</h:form>   

<script type="text/javascript">
    function myFunction() {
        document.getElementById("editTitle").defaultValue = "#{incidentBean.selectedIncident.title}";
        document.getElementById("editDescription").defaultValue = "#{incidentBean.selectedIncident.description}";
    }
</script>
Megan..
  • 25
  • 6
  • In the answer of the duplicate, just substitute `` with ``. – BalusC Apr 16 '16 at 19:25
  • @BalusC But even if i do that the data store in the title does not show. It is true that i would have to change that in the input text but i try and as i said it does not work either because the field shows empty – Megan.. Apr 16 '16 at 19:26
  • I indeed noticed other problems like this with your snippet. You aren't setting the selected item in bean and you are also not updating the dialog's content before opening. The answer in the duplicate shows the correct approach for this all. As hinted before, just substitute `` in the example with your ``. The rest is the same. – BalusC Apr 16 '16 at 19:27
  • @BalusC Thanks a lot, that worked because now the data is showing. But the button inside the dialog to save does not work, i try debugging but the method for saving is not being invoked and i dont now why, because i follow the answer and the commandButton is inside a form – Megan.. Apr 16 '16 at 21:51
  • @BalusC Okey i solved it, i had to put a `@PostConstruct` in my managed Bean :) Thank you! – Megan.. Apr 16 '16 at 23:15
  • The duplicate says that the bean has to be `@ViewScoped` (and thus not `@RequestScoped`) – BalusC Apr 17 '16 at 08:49

0 Answers0