9 Replies Latest reply on May 28, 2007 2:29 PM by Gavin King

    Bind Map to h:inputText value

    Clinton Parham Newbie

      Hello,

      I'm trying to bind a map entry to h:inputText. The code below successfully extracts the value for the key when the page is loaded, but when I submit it, the page reloads with an error alongside the field: model validation failed:String index out of range: -1

      From the .xhtml

      <h:form id="dataEntryForm">
      ...
      <h:inputText id="asdf" required="true" value="#{biomarkers['waist']}" />
      ...
      </h:form>
      


      From the session bean:
      ...
      @Out
      Map<String, String> biomarkers = new HashMap<String, String>();
      ...
      // method code that preps the Map prior to being used
      biomarkers.put("waist", "33.3");
      ...
      


      What have I missed? Any help appreciated. Thanks.


        • 1. Re: Bind Map to h:inputText value
          Clinton Parham Newbie

          Could someone please make a suggestion... Thanks!

          • 2. Re: Bind Map to h:inputText value
            Clinton Parham Newbie

            Am I asking a dumb question that doesn't warrant a reply :) ? Or is the answer readily available in the docs/samples? I've looked but I haven't come across an answer.

            Thanks to anyone who can offer some assistance!

            • 3. Re: Bind Map to h:inputText value
              Matt Drees Master

              Are you using a s:validate or s:validateAll on that h:inputText? If so, I'm fairly certain you can't do that.

              • 4. Re: Bind Map to h:inputText value
                Clinton Parham Newbie

                 

                "matt.drees" wrote:
                Are you using a s:validate or s:validateAll on that h:inputText? If so, I'm fairly certain you can't do that.


                Nope. Not using either. I've posted the complete page code below. Any other ideas? Thanks.

                <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:s="http://jboss.com/products/seam/taglib"
                 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:rich="http://richfaces.ajax4jsf.org/rich"
                 xmlns:a="https://ajax4jsf.dev.java.net/ajax"
                 template="layout/template.xhtml">
                
                 <ui:define name="body">
                
                 <h:messages globalOnly="true" styleClass="message" />
                
                 <h:form id="dataEntryForm">
                
                 <rich:panel>
                 <f:facet name="header">dataEntry</f:facet>
                 <p>Welcome #{appUser.username}</p>
                
                 <s:decorate id="valueDecoration1" template="layout/edit.xhtml">
                 <ui:define name="label">Map Binding</ui:define>
                 <h:inputText id="asdf" required="true"
                 value="#{biomarkers['waist']}" />
                 </s:decorate>
                
                 <s:decorate id="eventdateDecoration" template="layout/edit.xhtml">
                 <ui:define name="label">eventdate</ui:define>
                 <h:inputText id="eventdate" maxlength="10" size="10"
                 required="true" value="#{record.eventdate}">
                 <s:convertDateTime type="date" dateStyle="short"
                 pattern="MM/dd/yyyy" />
                 <a:support event="onblur" reRender="eventdateDecoration" />
                 </h:inputText>
                 <s:selectDate for="eventdate">
                 <h:graphicImage url="img/dtpick.gif" style="margin-left:5px" />
                 </s:selectDate>
                 </s:decorate>
                
                 <div style="clear:both" />
                
                 <h:dataTable value="#{recordDatas}" var="recordData">
                 <h:column>
                 <f:facet name="header">Name</f:facet>
                 <h:selectOneMenu value="#{recordData.value}">
                 <f:selectItem itemLabel="-" itemValue="" />
                 <f:selectItem itemLabel="Yes" itemValue="1" />
                 <f:selectItem itemLabel="No" itemValue="0" />
                 </h:selectOneMenu>
                 </h:column>
                 </h:dataTable>
                
                 </rich:panel>
                
                 <div class="actionButtons"><h:commandButton id="dataEntry"
                 value="dataEntry" action="#{enroll.thankYou}" /></div>
                
                 </h:form>
                
                 </ui:define>
                
                </ui:composition>
                


                • 5. Re: Bind Map to h:inputText value
                  Matt Drees Master

                  What's layout/edit.xhtml look like?

                  • 6. Re: Bind Map to h:inputText value
                    Clinton Parham Newbie

                     

                    "matt.drees" wrote:
                    What's layout/edit.xhtml look like?


                    Ok. Looks like you're onto something. Below is the code from edit.xhtml where you'll see validateAll is being called. I don't understand why validateAll is problematic. Maybe you can point me somewhere so I can educate myself. Thanks!

                    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                     xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:h="http://java.sun.com/jsf/html"
                     xmlns:f="http://java.sun.com/jsf/core"
                     xmlns:s="http://jboss.com/products/seam/taglib">
                    
                     <div class="prop">
                    
                     <s:label styleClass="name #{invalid?'errors':''}">
                     <ui:insert name="label"/>
                     <s:span styleClass="required" rendered="#{required}">*</s:span>
                     </s:label>
                    
                     <span class="value #{invalid?'errors':''}">
                     <s:validateAll>
                     <ui:insert/>
                     </s:validateAll>
                     </span>
                    
                     <s:message styleClass="error errors"/>
                    
                     </div>
                    
                    </ui:composition>
                    


                    • 7. Re: Bind Map to h:inputText value
                      Clinton Parham Newbie

                      I've done some reading here:
                      http://docs.jboss.com/seam/1.2.1.GA/reference/en/html/validation.html

                      There's no mention of using Maps. I suppose that's why you suggested that using s:validate may not work. How would one validate the inputField?

                      Appreciate your help...

                      • 8. Re: Bind Map to h:inputText value
                        Matt Drees Master

                        You'd have to use standard JSF validation (not Seam's specialized model validation). I found this article helpful.

                        http://www.ibm.com/developerworks/java/library/j-jsf3/

                        • 9. Re: Bind Map to h:inputText value
                          Gavin King Master

                          Please report this in JIRA, thanks.