【问题标题】:jsf 2 passing of value to dialog not workingjsf 2将值传递给对话框不起作用
【发布时间】:2013-08-01 07:47:32
【问题描述】:

我想向对话框传递一个值,但它不起作用。我尝试过this 方法,但没有运气

这是我的页面:

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

我错过了什么吗?

【问题讨论】:

    标签: jsf-2 primefaces view-scope


    【解决方案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>
    

    【讨论】:

    • 我的错,我忘了更改 bean 名称,对不起,它现在可以工作了,tnx ^^
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    相关资源
    最近更新 更多