6 Replies Latest reply on Oct 26, 2010 6:25 PM by Mustafa Şahin AYDIN

    how to set value in input text on page load

    Senthil kumar Newbie
      Hi All,

            how can i set value in input text on page load ? that's i have to retrieved data from database and set into bean class. I've tried in different ways but no progress.
      In that i configured action tag in page.xml.

      page.xml
      --------

          <page view-id="/today-statistics.xhtml"
                login-required="true" action="#{todaystatistics.getDate}">
                      
              .....
          </page>

      the method is executed and values are set in bean property. but in page its not displaying.

      And i tried seam web remoting component. i called "todaystatistics.getDate" in page onload method. but method is executed but its not displaying


      I'm suffering with past two days. Please anyone help me...

      Regards & Thanks
      Senthil Kumar
        • 1. Re: how to set value in input text on page load
          shashidhar b Newbie

          Click HELP for text formatting instructions. Then edit this text and check the preview.
          send today-statistics.xhtml page and todaystatistics.getDate method

          • 2. Re: how to set value in input text on page load
            shashidhar b Newbie

            send today-statistics.xhtml page and todaystatistics.getDate method

            • 3. Re: how to set value in input text on page load
              Senthil kumar Newbie
              Hi,

                   Thanks for your quick reply..

              today-statistics.xhtml
              ----------------------
              <!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: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"
                                              xmlns:ice="http://www.icesoft.com/icefaces/component"
                                  template="||||""template.xhtml">


                     
              <s:remote include="todaystatistics"/>  

              <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"
                              xmlns:ice="http://www.icesoft.com/icefaces/component"
                                  template="template.xhtml">

              <ui:define name="sidebar">
                  <h:form id="formStatistics">           
                              <s:decorate id="fromDateDecorate_today" template="edit.xhtml">                            
                                  <ui:define name="label">Form:</ui:define>
                                  <span class="calendar">
                                      <ice:selectInputDate id="fromDate_today" value="#{statistics.fromDateTo}" required="true"
                                      renderAsPopup="true" partialSubmit="true" onkeydown="javascript:return false;">
                                      <f:convertDateTime pattern="yyyy-MM-dd"/>
                                      </ice:selectInputDate>
                                  </span>
                              </s:decorate>           
                                    
                                  <s:decorate id="toDateDecorate_today" template="edit.xhtml">
                                            <ui:define name="label">To:</ui:define>
                                            <span class="calendar">
                                                 <ice:selectInputDate id="toDate_today" value="#{statistics.toDateTo}" required="true"
                                                 renderAsPopup="true" partialSubmit="true" onkeydown="javascript:return false;">
                                                 <f:convertDateTime pattern="yyyy-MM-dd"/>
                                                 </ice:selectInputDate>
                                            </span>                              
                                  </s:decorate>
                         
                         </h:form>          
                        
              </ui:define>

              </ui:composition>



              todaystatistics.getDate
              -----------------------

              @In(required=false)   @Out(required=false)
              public StatisticsForm statistics = new StatisticsForm();


              public String getDate(int reportType) {            
                      SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
                      SimpleDateFormat df3 = new SimpleDateFormat("dd-MM-yyyy");
                      SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");     
                      StringBuffer msgSmppStr = new StringBuffer();
                      try {          
                          List result = db1.createQuery("select back from BackupTime back").getResultList();                  
                          for (int i=0;i<result.size();i++) { 
                              BackupConsTime report = (BackupConsTime)result.get(i);
                              BackupConsTimeId reportId = report.getId();                                  
                                  Date tempDate = reportId.getTimeStamp();
                                  statistics.setBackupTime(df1.format(tempDate));                    
                                  statistics.setFromDateTo(tempDate);                  
                             }
                      } catch(Exception e) {
                          e.printStackTrace();
                      }
                      return msgSmppStr.toString();
                 }
              • 4. Re: how to set value in input text on page load
                Ambrish Singh Newbie

                Hi,


                Here is a simple example for setting values on page load.


                My SEAM component is onPageload.


                import java.util.Date;
                import org.jboss.seam.ScopeType;
                import org.jboss.seam.annotations.Name;
                import org.jboss.seam.annotations.Scope;
                import org.jboss.seam.annotations.security.Restrict;
                
                @Name("onPageload")
                @Scope(ScopeType.CONVERSATION)
                @Restrict("#{identity.loggedIn}")
                public class OnpageloadAction  {
                     
                     Date today;
                
                     public Date getToday() {
                          return today;
                     }
                
                     public void setToday(Date today) {
                          this.today = today;
                     }
                     
                     public void initialize(){
                          today = new java.util.Date();
                     }     
                }



                Here is your XHTML page.




                <!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.org/rich" template="layout/template.xhtml">
                
                     <ui:define name="body">
                
                          <h:messages styleClass="message" />
                
                          <h:form id="login">
                          
                          <rich:calendar value="#{onPageload.today}" showInput="true" datePattern="MM/dd/yyyy"/>
                          
                          </h:form>
                          
                     </ui:define>
                     
                </ui:composition>
                



                and finally your page.xml file.




                <?xml version="1.0" encoding="UTF-8"?>
                <page xmlns="http://jboss.com/products/seam/pages"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd">
                
                     <action execute="#{onPageload.initialize}"/>
                     
                </page>




                Ambrish





                • 5. Re: how to set value in input text on page load
                  Senthil kumar Newbie
                  Hi Ambrish,

                            Thanks a lot for your reply, I placed <action execute=""> tag in my page.xml. its working fine but problem is if i do any other action on the page its getting executed. Finally i solved this using seam remote component.

                  Regrads,
                  Senthil
                  • 6. Re: how to set value in input text on page load
                    Mustafa Şahin AYDIN Newbie


                    <action execute="#{onPageload.initialize}" on-postback="false"/>



                    if you write on postback false this works only one times when loading page. It does not work any other actions. if you want to use this for list initilition you will like this.