Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Take a look at this <a href="http://sscce.org/" rel="nofollow">SSCCE</a>, it does what you want.</p> <p><strong>TestBean.java</strong></p> <pre><code>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; } } </code></pre> <p><strong>index.xhtml</strong></p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;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"&gt; &lt;h:head&gt; &lt;title&gt;JSF Demo&lt;/title&gt; &lt;/h:head&gt; &lt;h:body&gt; &lt;p:messages /&gt; &lt;h:form&gt; &lt;h:panelGroup rendered="#{!testBean.editable}"&gt; &lt;h:outputText value="#{testBean.value}" /&gt; &lt;/h:panelGroup&gt; &lt;h:panelGroup rendered="#{testBean.editable}"&gt; &lt;p:inputText value="#{testBean.value}" /&gt; &lt;/h:panelGroup&gt; &lt;p:commandButton value="#{testBean.editable ? 'Confirm value' : 'Change value'}" update="@form" actionListener="#{testBean.changeEditable}" /&gt; &lt;p:commandButton value="Save value" ajax="false" action="#{testBean.saveValue}" /&gt; &lt;/h:form&gt; &lt;/h:body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload