1

I have a p:inputTextarea and I need the value of it while processing the form. It turned out that every time I submit the form I get all the values except the one from the textarea. #{xyzUI.description} is a String object with regular getters and setters.

<ui:composition>
    <h:form id="form1">
        <p:panel rendered="...">
            <p:panel id="formPanel">
                <p:panelGrid columns="2" cellpadding="5">
                    <!-- other form elements -->
                    <p:outputLabel>Description:</p:outputLabel>
                    <p:inputTextarea value="#{xyzUI.description}" style="width: 350px;" counter="display" counterTemplate="{0} characters remaining" maxlength="2000" autoResize="true" rows="4" />
                    <h:panelGroup />
                    <h:outputText id="display" />
                </p:panelGrid>
                <p:commandButton rendered="#{not xyzUI.noChange}" action="#{xyzUI.submitForm}" update="formPanel" ajax="true" value="Apply" >
                    <p:ajax update="formPanel"></p:ajax>
                </p:commandButton>
            </p:panel>
        </p:panel>
    </h:form>
<ui:composition>

In my backing bean the value is always "". I don't know what's wrong.

public void submitForm()
{
    ...
    tmp.setDescription(description); // String is always "" while debugging
    myList.add(tmp);
    RequestContext.getCurrentInstance().update("content");
}
baumlol
  • 85
  • 1
  • 7
  • It seems to me the source of the problem is not in the shown code. Where's your button? Whats the bean scope? Show the getter/setter. Do you have nested forms? Show some more.. – Jaqen H'ghar May 13 '16 at 08:23
  • The bean scope is @ViewScoped. I have only one form surrounding the whole view. I've added the button to the code. Sorry I trimmed the code for readability and forgot the commandButton. – baumlol May 13 '16 at 08:40
  • Can we see your entire backing bean? As @JaqenH'ghar mentioned it could be that you are missing a setter on that bean propety – Tony Scialo May 13 '16 at 14:53

1 Answers1

1

I ran your code locally and discovered the issue. In the command button, remove the p:ajax call.

PrimeFaces command buttons are ajax enabled by default.

So change this:

<p:commandButton rendered="#{not xyzUI.noChange}" action="#{xyzUI.submitForm}" update="formPanel" ajax="true" value="Apply" >
  <p:ajax update="formPanel"></p:ajax>
</p:commandButton>

To this:

 <p:commandButton rendered="#{not xyzUI.noChange}" action="#{xyzUI.submitForm}" update="formPanel" value="Apply" />

My backing bean for reference

@ManagedBean
@ViewScoped
public class xyzUI implements Serializable{

    private static final long serialVersionUID = 6259024062406526022L;

    private String description;
    private boolean noChange = false;

    public xyzUI(){

    }

    public void submitForm(){
        System.out.println(description);
    }

    public boolean isNoChange() {
        return noChange;
    }

    public void setNoChange(boolean noChange) {
        this.noChange = noChange;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}
Tony Scialo
  • 3,942
  • 7
  • 31
  • 44
  • Basically, OP incorrectly used `process="@this"` instead of `process="@form"`. See also http://stackoverflow.com/q/25339056 – BalusC May 13 '16 at 15:13