0

I have JSF facelet like this:

<h:form id="input-f">
    <div>
        <h:outputLabel for="coord-x" value="Choose X:"/>
        <p:panelGrid columns="2">
            <h:selectOneRadio id="coord-x" required="true" value="#{resultBean.newResult.r}">
                <f:selectItem class="xGroup" itemValue="-2" itemLabel="-2"/>
                <f:selectItem class="xGroup" itemValue="-1.5" itemLabel="-1.5"/>
                <f:selectItem class="xGroup" itemValue="-1" itemLabel="-1"/>
                <f:selectItem class="xGroup" itemValue="-0.5" itemLabel="-0.5"/>
                <f:selectItem class="xGroup" itemValue="0" itemLabel="0"/>
                <f:selectItem class="xGroup" itemValue="0.5" itemLabel="0.5"/>
                <f:selectItem class="xGroup" itemValue="1" itemLabel="1"/>
                <f:selectItem class="xGroup" itemValue="1.5" itemLabel="1.5"/>
                <f:validateRequired/>
            </h:selectOneRadio >
        </p:panelGrid>
    </div>
    <div>
        <h:outputLabel>Available Y values: (-5 ... 5)</h:outputLabel>
        <p:panelGrid columns="2">
            <p:inputText maxlength="17" name="y" id="coord-y"
                                         placeholder="(-5..5)" value="#{resultBean.newResult.y}">
            </p:inputText>
        </p:panelGrid>
    </div>
</h:form>

And I try use JS script for getting values of this form after form submitting:

x = $("#input-f\\:coord-x input[type='selectOneRadio']:checked").val();
y = document.getElementById("input-f:coord-y").value;

I can correctly get "y" value, but can't get "x" value. Logging says, that "x" is undefined. I tried use .getElementById() method, but it hasn't be successfull too. How can I use JS for getting checked "x" value?

Zach Jensz
  • 3,650
  • 5
  • 15
  • 30
  • FWIW: x is using JQuery vs. y using Javascript. My guess, if y has a legitimate value then JSF is massaging the input to `getElementByID`, and maybe doesn't know how to recognize/massage a jquery call. Consider `document.querySelector();` – fnostro May 10 '22 at 20:45
  • Why do you need to get it in JavaScript? After submitting it is simply available through EL by the way: `#{resultBean.newResult.r}`. – Jasper de Vries May 11 '22 at 07:48

0 Answers0