Question

I want to pass a value to a dialog but it wont work. I have tried this approach but no luck

Here is my page:

<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title></title>
    </h:head>
    <h:body>
        <h:form>
            <p:inputText value="#{myManagedBean.input}"/>
            <p:commandButton value="edit" onclick="dlg.show()"/>

            <p:dialog widgetVar="dlg" modal="true">
                passed value:<p:inputText value="#{myManagedBean.input}"/>
            </p:dialog>
        </h:form>
    </h:body>
</html>

and my managedbean

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class MyManagedBean implements Serializable {

    private String input;

    public String getInput() {
        return input;
    }

    public void setInput(String input) {
        this.input = input;
    }
}

Am I missing something?

Was it helpful?

Solution

First you need to set value in "input" field. after you need to show your dialog box.

you can do it like. Change your code According to this code.

Please Notice "immediate" and "oncomplete" Attribute.

<h:body>
        <h:form>
            Input : <p:inputText value="#{myBean.input}" immediate="true"/>
            <p:commandButton value="Sumbit" oncomplete="dlg.show()" update=":form2"/>
        </h:form>
        <h:form id="form2">
            <p:dialog widgetVar="dlg" modal="true">
                passed value:<p:inputText value="#{myBean.input}"/>
            </p:dialog>
        </h:form>
    </h:body>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top