jsf 2 passing of value to dialog not working

那年仲夏 提交于 2019-12-14 04:06:16

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/17988038/jsf-2-passing-of-value-to-dialog-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!