5 Replies Latest reply on Jul 28, 2010 7:22 AM by delarue

    Default value for inputText and inputTextarea

    delarue

      Hello,


      This is maybe a newbie question, but I can't figure out how to deal with that.


      I've got this inputTextarea (home.xhtml)


      <h:inputTextarea required="true" id="xml" rows="10" cols="80"
                                   value="#{XPathExtractor.xml}" />
      


      The Seam component


      @Name("XPathExtractor")
      public class XPathExtractor
      {
          /** The xml string to parse */
          private String xml;
      ...
      



      I d like at first open of the file home.seam to get a default value for the xml field.
      I set the required default content in messages_fr.properties



      sample = <xml>sample</xml>



      If I code


          public XPathExtractor ()
          {
              setXml("#{messages.sample}");
          }
      



      A have the text #{messages.sample} in the text area instead of <xml>sample</xml>


      If I set


      <h:inputTextarea required="true" id="xml" rows="10" cols="80" 
                      value="#{not empty XPathExtractor.xml ? XPathExtractor.xml : messages.sample}" /> 
      




      This produces exception.


      IMO, the defaut value should be set outside of the java code (ie not in the contrusctor XPathExtractor ()), but I can't figure how.


      Thank's for help

        • 1. Re: Default value for inputText and inputTextarea
          cash1981

          Constructors won't work in Seam like that.


          Instead you should use the @Create method




          @Create
          public void startup() {
             setXml(Messages.instance().get("messages.sample"));
          }



          • 2. Re: Default value for inputText and inputTextarea
            cash1981

            Also to output something from the message file in the xhtml pages you should do like this:




            messages['messages.sample']



            • 3. Re: Default value for inputText and inputTextarea
              delarue

              Thank's for reply.


              I don't understand where to put the


              messages['messages.sample']


              in this xhtml snippet


               <s:decorate id="XmlDecorate" template="layout/edit.xhtml">
                          <ui:define name="label">Flux xml à parser</ui:define>
                          <h:inputTextarea required="true" id="xml" rows="10" cols="80"
                                           value="#{XPathExtractor.xml}" />
                        </s:decorate>
              



              Toward the @Create annotation, don't you agree that defaulting a value for sample purpose should be better at View side, thus JSF, xhtml rather that at the Model side in the java code ?


              regards

              • 4. Re: Default value for inputText and inputTextarea
                cash1981

                christophe delarue wrote on Jul 28, 2010 03:37:


                Thank's for reply.

                I don't understand where to put the

                messages['messages.sample']


                in this xhtml snippet



                You can put it anywhere.




                #{messages['foo.bar']}
                or in h:outputText
                h:outputText value="#{messages['foo.bar']}"
                






                christophe delarue wrote on Jul 28, 2010 03:37:


                 <s:decorate id="XmlDecorate" template="layout/edit.xhtml">
                            <ui:define name="label">Flux xml à parser</ui:define>
                            <h:inputTextarea required="true" id="xml" rows="10" cols="80"
                                             value="#{XPathExtractor.xml}" />
                          </s:decorate>
                



                Toward the @Create annotation, don't you agree that defaulting a value for sample purpose should be better at View side, thus JSF, xhtml rather that at the Model side in the java code ?

                regards


                No I always put default values on the server side (Java code)

                • 5. Re: Default value for inputText and inputTextarea
                  delarue

                  Ok thank's, I'll follow this convetion to default in the java code.


                  Btw the messages was to much. the correction version is :


                  @Create
                  public void startup() {
                     setXml(Messages.instance().get("sample"));
                  }