Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 改变<;h:输出文本>;进入<;h:输入文本>;PrimeFaces中的ajax_Jsf_Primefaces - Fatal编程技术网

Jsf 改变<;h:输出文本>;进入<;h:输入文本>;PrimeFaces中的ajax

Jsf 改变<;h:输出文本>;进入<;h:输入文本>;PrimeFaces中的ajax,jsf,primefaces,Jsf,Primefaces,我试图在单击按钮或链接后将更改为。与此类似的东西:但我想使用PrimeFaces 我认为这是有用的: 但我想让编辑模式在点击编辑按钮或超链接后触发,而不是在点击我想要更改的文本后触发 当然,单击编辑按钮后,我希望更改为“接受”按钮,该按钮允许我保存更改并将inputText更改为outputText查看一下,它可以满足您的需要 TestBean.java package com.mycompany; import javax.faces.application.FacesMessage; im

我试图在单击按钮或链接后将
更改为
。与此类似的东西:但我想使用PrimeFaces

我认为这是有用的: 但我想让编辑模式在点击编辑按钮或超链接后触发,而不是在点击我想要更改的文本后触发

当然,单击编辑按钮后,我希望更改为“接受”按钮,该按钮允许我保存更改并将inputText更改为outputText查看一下,它可以满足您的需要

TestBean.java

package com.mycompany;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@ViewScoped
public class TestBean {

    /**
     * Controls if the input field is available or not
     */
    private boolean editable = false;

    /**
     * The String value you want to edit
     */
    private String value = "Default value";

    /**
     * Changes between the inputText and the outputText
     */
    public void changeEditable() {
        editable = !editable;
    }

    public String getValue() {
        return value;
    }

    public boolean isEditable() {
        return editable;
    }

    /**
     * Definitely saves the value
     */
    public void saveValue() {
        FacesMessage message = new FacesMessage("Value " + value + " saved!");
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

    public void setEditable(boolean editable) {
        this.editable = editable;
    }

    public void setValue(String value) {
        this.value = value;
    }

}
index.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">

<h:head>
    <title>JSF Demo</title>
</h:head>
<h:body>
    <p:messages />
    <h:form>
        <h:panelGroup rendered="#{!testBean.editable}">
            <h:outputText value="#{testBean.value}" />
        </h:panelGroup>
        <h:panelGroup rendered="#{testBean.editable}">
            <p:inputText value="#{testBean.value}" />
        </h:panelGroup>

        <p:commandButton
            value="#{testBean.editable ? 'Confirm value' : 'Change value'}"
            update="@form" actionListener="#{testBean.changeEditable}" />

        <p:commandButton value="Save value" ajax="false"
            action="#{testBean.saveValue}" />
    </h:form>

</h:body>
</html>

JSF演示

不太多,我不知道如何将内置按钮与外部按钮连接起来: