0

i have a dialog to create a survey. The dialog has an inputText for the question and a button two add inputext for the possible answers. So when the users clicks on the button that is inside the dialog to add an answer i want to update the open dialog. when i click the button Add nothing happens.

I try some of the answers of other people problems here, but it doesn't work for me. I am using Primefaces 5.3

I try outside the dialog the "add" button and it works fine because the inputTexts appears, but inside the dialog it doesn't do anything. So the problem is in the way i am updating the content of the dialog

This is the code of the dialog:

<p:dialog id="newSurveyDialogo2" header="New Survey" widgetVar="dlg2" minHeight="40" resizable="false" appendTo="@(body)">
    <p:ajax event="close" listener="#{surveyBean.handleClose}" update=":dialogOptions"/>

    <h:form id="dialogOptions">
        <p:outputLabel value="Question:"/> <br/>
        <p:inputTextarea id="question" value="#{surveyBean.sQuestion.question}" rows="2" cols="50" counter="displayP" maxlength="50" counterTemplate="{0} " autoResize="true" required="true" requiredMessage="Question necessary"/> <br/>
        <p:outputLabel id="displayP"/> <br/><br/>

        <p:outputLabel value="Answers:"/> <br/>
        <h:dataTable value="#{surveyBean.options}" var="item">
            <h:column><h:inputText value="#{item.opcion}" /></h:column>
            <h:column><h:commandButton value="remove" action="#{surveyBean.remove(item)}" /></h:column>
        </h:dataTable>
        <p:commandButton value="Add" action="#{surveyBean.add}" update=":dialogOptions"/> <br/><br/>

        <p:separator/>
        <p:commandButton value="Create new Survey" action="#{surveyBean.addSurvey()}" onclick="dlg2.hide()" update=":dialogOpciones"/>
    </h:form>
</p:dialog>  
Megan..
  • 25
  • 6
  • 1
    You can't nest forms – Jaqen H'ghar Jun 19 '16 at 17:11
  • @JaqenH'ghar I didn't know that, i try deleting the second form but know when i click in the inputText of the Question the dialog close – Megan.. Jun 19 '16 at 17:33
  • When you click in the h:inputText the dialog closes? I don't think those "oncomplete="dlg2.show()"" should be needed... could you update question with the new code please. You could try appendTo="@(body)" on the dialog – Jaqen H'ghar Jun 19 '16 at 17:47
  • @JaqenH'ghar I updated the code, i try what you said (is in the code), but know when i click inside the dialog it closes. I dont undestand why i have to put appendTo="@(body)", the dialog is inside the body of an xhtml but even if i dont put the appendTo the dialog closes when i click inside of it – Megan.. Jun 19 '16 at 18:12
  • [mcve], see also http://www.stackoverflow.com/tags/jsf/info... (e.g. version info etc) – Kukeltje Jun 19 '16 at 18:16
  • Does it close pressing the button or pressing anywhere in the dialog? IF it is the former, that is loggical, since you update the full dialog. Just update the contents in it – Kukeltje Jun 19 '16 at 18:36
  • @Kukeltje I am using Primefaces 5.3, Its true that i was updating the full dialog. Now i change the code (as you can see above) to update the content of the dialog but i doesn't do anything, it stays open and no error is thrown. I know it is because its inside the dialog because i try the "add" button outside the dialog and it appears inputText but inside the dialog it doesn't do anything. So the problem is in the way i have to update the dialog but nothing is working. Thanks in advance! – Megan.. Jun 19 '16 at 21:53
  • Are you indeed implying that when this form is placed outside the dialog, the form itself works fine? If not, then you'd better reframe the question to remove the irrelevant dialog nuisance to make the question better focused (and being more likely a candidate as duplicate of http://stackoverflow.com/q/2118656). – BalusC Jun 20 '16 at 08:06
  • @BalusC I find the problem. If i write something on the question before clicking the add button it works fine. So i remove the required="true" and requiredMessage="Question necessary" from the inputTextarea and now it works fine and i can click the add button before writen the question. But i dont exactly know why this happens – Megan.. Jun 20 '16 at 17:43

0 Answers0