Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Make use of the <code>rendered</code> attribute:</p> <pre class="lang-html prettyprint-override"><code>&lt;h:outputText value="#{bean.entity.property}" rendered="#{not bean.editmode}" /&gt; &lt;h:inputText value="#{bean.entity.property}" rendered="#{bean.editmode}" /&gt; ... &lt;h:commandButton value="Edit" action="#{bean.edit}" rendered="#{not bean.editmode}" /&gt; &lt;h:commandButton value="Save" action="#{bean.save}" rendered="#{bean.editmode}" /&gt; </code></pre> <p>With this in a view scoped bean:</p> <pre class="lang-java prettyprint-override"><code>private boolean editmode; public void edit() { editmode = true; } public void save() { entityService.save(entity); editmode = false; } public boolean isEditmode() { return editmode; } // ... </code></pre> <p>Note that the bean being view scoped is important for the reason mentioned in point 5 of this answer: <a href="https://stackoverflow.com/questions/2118656/commandlink-commandbutton-ajax-backing-bean-action-listener-method-not-invoked">commandButton/commandLink/ajax action/listener method not invoked or input value not updated</a>.</p> <hr> <p>Alternatively, you can use the <code>disabled</code> attribute on input component in combination with a shot of CSS which basically makes it look like an output component (by removing the border).</p> <pre class="lang-html prettyprint-override"><code>&lt;h:inputText value="#{bean.entity.property}" disabled="#{not bean.editmode}" /&gt; ... &lt;h:commandButton value="Edit" action="#{bean.edit}" rendered="#{not bean.editmode}" /&gt; &lt;h:commandButton value="Save" action="#{bean.save}" rendered="#{bean.editmode}" /&gt; </code></pre> <p>with e.g.</p> <pre><code>input[disabled] { border: 0; } </code></pre> <p>Also here, the bean must be view scoped. See also <a href="https://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope">How to choose the right bean scope?</a></p>
 

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