0

我想将一个值传递给一个对话框,但它不起作用。我已经尝试过这种方法但没有运气

这是我的页面:

<!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>

和我的托管豆

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;
    }
}

我错过了什么吗?

4

1 回答 1

1

首先,您需要在“输入”字段中设置值。在你需要显示你的对话框之后。

你可以这样做。根据此代码更改您的代码。

请注意“immediate”和“oncomplete”属性。

<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>
于 2013-08-01T11:17:51.997 回答