Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF 2.1 Validation of two inputs at the same time using Ajax
    text
    copied!<p>I have a problem with validation of two inputs at the same time.</p> <p>In my validator I need data from both:</p> <ol> <li><code>&lt;h:selectOneListbox&gt;</code></li> <li><code>&lt;h:inputText&gt;</code></li> </ol> <p>The idea is to check if an address is reachable for delivery personnel. During validation I make a request to DB. And look for a combination of streetName + houseNumber.</p> <h3>Here is a part of my JSF page.</h3> <pre><code> &lt;h:form&gt; &lt;p&gt; &lt;h:outputLabel for="streetsList" value="Street"/&gt; &lt;h:selectOneListbox id="streetsList" binding="#{theStreetsList}" size="1" value="#{makeOrder.streetName}" required="true"&gt; &lt;f:selectItems value="#{locationView.streetNames}" var="streetName" itemLabel="#{streetName}" itemValue="#{streetName}"/&gt; &lt;/h:selectOneListbox&gt; &lt;/p&gt; &lt;p class="address_details"&gt; &lt;h:outputLabel for="houseInput" value="#{msgs.house}"/&gt; &lt;h:inputText id="houseInput" class="tab_input house_input" value="#{makeOrder.house}" required="true"&gt; &lt;f:validator validatorId="AddressValidator" /&gt; &lt;f:attribute name="street" value="#{theStreetsList}" /&gt; &lt;f:ajax event="blur" execute="streetsList houseInput" render="m_houseInput" /&gt; &lt;/h:inputText&gt; &lt;h:message id="m_houseInput" for="houseInput" style="color:red" /&gt; &lt;h:outputLabel for="flatInput" class="flat_label" value="#{msgs.flat}"/&gt; &lt;h:inputText class="tab_input flat_input" value="#{makeOrder.flat}"/&gt; &lt;/p&gt; &lt;/h:form&gt; </code></pre> <h3>Here is validate method of my class:</h3> <pre><code>@Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String house = (String) value; UIInput streetsComponent = (UIInput) component.getAttributes().get("street"); String streetName = (String) streetsComponent.getSubmittedValue(); Street orderStreet = this.findStreetInDB(streetName, house); if (orderStreet.getName().equals("dummyStreet")) { // Show error FacesMessage msg = new FacesMessage( "Unfortunately we do not deliver to this address, yet."); msg.setSeverity(FacesMessage.SEVERITY_ERROR); throw new ValidatorException(msg); } } </code></pre> <p>My problem is that <code>String streetName</code> is <code>null</code>. </p> <p><strong>P.S.</strong> Values of this element are rendered fine. And I even can submit a form if I don't use validation.</p> <ul> <li>What am I doing wrong?</li> <li>What is the right way of doing this?</li> </ul> <p>Thanks!</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