0

In my current project I have a construct, where you have an entity where you can change the values through a approval workflow. If you want to save a new version of an entity, you click on a button and a dialog pops up. There you can set the one to approve your change and an additional, optional comment.

My problem is, that the values from this dialog are not submitted.

The dialog is included in my main template, but outside of the main form. The dialog is appended to the Body, like this:

<p:dialog id="idEntityCommentDialog"
        header="#{msgs['label.approval.dialogHeader.'.concat(bean.targetStatus)]}"
        width="350" widgetVar="entityCommentDlg" modal="true"
        maximizable="false" resizable="false" appendTo="@(Body)">

Both fields set their value to an object inside the sessionScoped backing bean:

<p:selectOneMenu id="selUsers"
    value="#{bean.state.releasedBy}" style="width: 100%">
    <f:selectItems value="#{bean.fetchUserList()}" var="user"
        itemValue="#{user.id}"
        itemLabel="#{user.name}" />
</p:selectOneMenu>

<p:inputTextarea id="changeComment"
    value="#{bean.state.newComment.eventDescription}"
    style="width: 98%; height: 100px">
    <f:converter converterId="xssConverter" />
</p:inputTextarea>

Before, I had standard jsf controls, h:sekectOneMenu and h:inputTextArea. I have switched to the respective primefaces controls, and now at least the value from the selectOneMenu is submitted, but still, the value from the inputTextarea is not submitted. I have set breakpoints in the used converter, and I receive an empty string in my converter, which works in different other places where I use it.

I tried various combinations of update parameters and I also tried to set the value in an ajax request via

<p:ajax event="change" update="@this">

When I use the p:ajax tag, I can see, that when I change the value, after the ajax request, the value is immediately reset to the original value before the change. This applies for both fields (when using the standard controls) Like I said, I fixed it with the primefaces control (I don't understand why, but it seems to work) but it doesn't work for the inputTextArea.

My button is inserted with a toolbar facet from primefaces.

<p:commandButton actionListener="#{bean.saveEntity}"
    styleClass="toolbarButton" update="dialogForm2 :blocker:contentWrapper"
    onstart="PF('waitDialog').show();"
    oncomplete="PF('waitdialog').hide();PF('entityCommentDlg').hide();"
    value="#{msgs['label.approval.button.'.concat(bean.targetStatus)]}">
</p:commandButton>

The form is defined inside the dialog with just an id:

<h:form id="dialogForm2">

I am mostly confused, that if I use the p:ajax control, that my value is reset immediately, so there must be something very wrong here.

I also checked that I have no failed validations that I maybe don't see for some reason (via a phaseListener) but that's not the case, no facesMessages occur.

Please respect that I can't show you complete chunks of code from the project, my customer wouldn't want that, but if you need further information about other code or architecture, I will try to provide it. I also changed some ids and names, but I made sure that they are correct and referenced properly in the original code.

Do you have any idea what could be the reason for this kind of behaviour? I know there are various articles about form values not submitted, I have seen them and tried the solution, but nothing seems to work for me here. A colleague of mine also has no idea why it shouldn't work. I use nearly the same construct (with a different backing bean and objects) in another part of the application, there, everything works fine, with the standard jsf controls.

  • Is this helpful? http://stackoverflow.com/q/2118656 As to posting "complete chunks", you should never do that in first place. Generally they contain a lot of irrelevant noise not contributing to the problem (markup, styling, i18n, etc). Just recreate the problem in a sandbox project and boil down into a copy'n'paste'n'runnable MCVE. See also http://stackoverflow.com/tags/jsf/info – BalusC Apr 19 '16 at 13:11
  • Unfortunately not, I have checked all the points in the list and nothing applies. But I am not entirely sure on point 9. Yes, the dialog is updated before. I have a button which sets a parameter (bean.targetStatus), updates the dialog and then in the onComplete event, opens the dialog. But my commandButton works fine so far. The method in the actionListener works fine and all the values from the other form (the original entity I want to update) are submitted, so I assume this point isn't a problem here? – Matthias Nicklisch Apr 19 '16 at 13:24

1 Answers1

0

Ok, I finally found the problem. The solution was to remove appendTo="@(Body)"

I had very strange behaviour before I found the solution.

You see, in the onStart and onComplete events of the submit button, I display a loading overlay. The bug occured as I fixed this loadingOverlay. Before I had a copy&paste error, where I referenced the wrong loading overlay, which was not present in the current page. But the bug only occured when I used the correct overlay or I even deleted the reference to this overlay completely. When I put in the wrong id of the overlay again, it worked...

Now, when I removed the appendTo attribute, everything seems to work fine, even the correct loading overlay. I don't even know anymore why I used the appendTo attribute. I assume the dialog was in another place before and I had to use it, but meanwhile the dialog is placed directly in the body of the document, outside of any layout or form, so I understand that I don't need it.

Does someone has a more educated idea why this error happened like it did? I understand that appendTo can have side effects when you don't need to use it, but the general behaviour I could observe here is beyond any reason to me.