Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to trigger the change of a h:inputHidden by JavaScript
    primarykey
    data
    text
    <p>I have to implement a three state checkbox as a composite component with ajax features. This is what I have so far:</p> <pre><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:cc="http://java.sun.com/jsf/composite" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"&gt; &lt;cc:interface&gt; &lt;cc:attribute name="id" /&gt;&lt;!-- necessary? --&gt; &lt;cc:attribute name="value" required="false" /&gt; &lt;cc:clientBehavior name="change" event="change" targets="value" /&gt; &lt;/cc:interface&gt; &lt;cc:implementation&gt; &lt;div style="float: left;"&gt; &lt;h:outputStylesheet library="default" name="css/checkbox.css" target="head" /&gt; &lt;h:outputScript library="default" name="js/checkbox.js" target="head" /&gt; &lt;div id="#{cc.clientId}" class="cc-checkbox cc-checkbox-value#{cc.attrs.value}" style="width: 14px; height: 14px;" onclick="checkboxToggleControl('#{cc.clientId}')"&gt;&lt;/div&gt; &lt;h:inputHidden id="value" value="#{cc.attrs.value}" /&gt; &lt;/div&gt; &lt;/cc:implementation&gt; &lt;/ui:composition&gt; </code></pre> <p>As you see (or not, because I didn't include the JS as it's not the problem), a litte JavaScript replaces the classes which the user sees as a three state checkbox (<code>null</code>, <code>true</code>, <code>false</code>). The current value is stored in <code>&lt;h:inputHidden&gt;</code> by JavaScript.</p> <p>I would like to be able to register an ajax event when using the control in order to be able to store the value on the server. The component is located inside a <code>&lt;rich:extendedDataTable&gt;</code>. Every time the user clicks on it, the value should be stored "immediately" in the database. Using <code>clientBehaviour</code> with <code>inputHidden</code> doesn't work, as it doesn't support ajax.</p> <ol> <li><p>Is it possible to ajaxify <code>&lt;h:inputHidden&gt;</code> by using <code>&lt;h:inputText&gt;</code>? What are the drawbacks? (I would have to deal with validation, wouldn't I?)</p></li> <li><p>Is there another way to implement it as a composite component?</p></li> <li><p>Or, would it be "easier" to write a "real" component?</p></li> </ol> <p>I'm not using <code>&lt;h:selectBooleanCheckbox&gt;</code> because it cannot be styled by CSS in the desired way and also because it doesn't support a three-state.</p>
    singulars
    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.
 

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