function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hoomelhoomel 

Form not submitting, just refreshing

Hello,

 

i built a Visualforce page where the user can input search criteria. It looks like this:

 

<apex:page controller="calCon">
<apex:sectionHeader title="Search assistant" subtitle="Step 1 of 2"/>
	<apex:form >
		<apex:pageBlock title="Enter search criteria here" mode="detail">
			<apex:pageBlockButtons location="bottom">
				Select month to display: &nbsp; <apex:selectList value="{!monthSelection}" size="1">
        			<apex:selectOptions value="{!selectMonth}" />
        			<apex:actionSupport event="onchange" rerender="month" />
        		</apex:selectList>
				<apex:commandButton value="Next" action="{!page3}" />
				<apex:commandButton value="Clear Fields" action="{!clear}" />
				<apex:commandButton value="Show all systems" action="{!allCal}" />
			</apex:pageBlockButtons>
			<apex:pageBlockSection title="Search Fields">
				<apex:inputField value="{!rental.Rental_System__c}" />
				<apex:inputField value="{!rentsystem.Owner__c}" />
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
	<apex:form >
        <apex:outputPanel id="month" />
        <apex:messages />
	</apex:form>
</apex:page>

 

 

The controller methods are as follows:

 

    private Map<String,Integer> monthMap = new Map<String,Integer>{'January'=>1,'February'=>2,'March'=>3,'April'=>4,'May'=>5,'June'=>6,'July'=>7,'August'=>8,'September'=>9,'October'=>10,'November'=>11,'December'=>12};
    private List<Month> monthlist;
    public String monthSelection{get;}
    public void setMonthSelection(String smonth){
    	if(smonth == null){smonth = this.month.getMonthName()+' '+this.month.getYearName();}
    	Date d;
    	Integer year = Integer.valueOf(smonth.split(' ',2).get(1));
    	Integer day = 1;
    	Integer month = monthMap.get(smonth.split(' ',2).get(0));
    	d = date.newInstance(year,month,day);
    	setMonth(d);
    }
    public List<SelectOption> getSelectMonth(){
    	List<SelectOption> SelectMonth = new List<SelectOption>();
    	if(monthlist==null) {
			monthlist = new List<Month>();
    	for(Integer i=-18;i <= 18;i++){
    		addmonth(i);
    		monthlist.add(month);
    		addmonth(-i);
    	}
    	}
    	System.debug(monthlist.size());
    	SelectMonth.add(new SelectOption('Current',month.getMonthName()+' '+ month.getYearName()));
    	for(Integer i = 0; i < monthlist.size();i++)
    		{
    			SelectMonth.add(new SelectOption(monthlist.get(i).getMonthName() + ' ' + monthlist.get(i).getYearName(),monthlist.get(i).getMonthName() + ' ' + monthlist.get(i).getYearName()));
    		}
    	return SelectMonth;
    }
   public PageReference page3(){
   	getfoundSystems();
   	return Page.rental_cal;
   }

 

 

The following things happen:

When a month is selected in the SelectList the 'Next' button correctly navigates to the next page.

 

But as soon as no selection was made in the selectList, the page just refreshes instead of redirecting to the next page.

I tried setting the 'Next'-Button with immediate="true", but then any value entered in the other fields are not submitted to the class, so that i can not use them on the next page (which has the same controller).

 

<apex:messages /> generates the following output:

 

•j_id0:j_id2:j_id3:j_id4:j_id6: An error occurred when processing your submitted information. 

 

Could anyone give me some idea where this is coming from?

Can i maybe set a value for the selectList initially when no value is selected?

 

Regards,

hoomel

 

 

bob_buzzardbob_buzzard

You can't set a value for the initial selection as your code stands, as you have declared monthSelection as a read only property (it has an automatic get but no set).

 

Can you post the rest of the controller code - e.g. where this.month is declared and the setmonth method?  

Pradeep_NavatarPradeep_Navatar

you can set the values in drop down through schema.DescribeFieldResult and fetch the values in picklist from org.

 

j_id0:j_id2:j_id3:j_id4:j_id6: An error occurred when processing your submitted information.In general This error shows

 

when you missed the id somewhere in code.

 

Hope this helps.

hoomelhoomel

Thanks for the quick response.

Isn't setMonthSelection a proper setter for the variable? Because when i do public String monthSelection{get;set;} instead of the above, the variable is not set at all.

 

I tested some little things now and i realised that when i put the selectList in a second apex:form tag, everything is working correctly but that is only a workaround, therefor i would really like that button integrated in the pageBlock.

 

Here are the methods you asked for:

 

 

private Month month;

public Month getMonth() { return month; } 
    private void setMonth(Date d) { 
    month = new Month(d);  
    system.assert(month != null); 
  }

private void addMonth(Integer val) { 
    Date d = month.getFirstDate();
    d = d.addMonths(val);
    setMonth(d);
  }

 

And this is the class Month from which the object is generated:

 

public class Month {
	private List<Week> weeks; 
	public Date firstDate; // always the first of the month
	private Date upperLeft; 
	
	public List<Date> getValidDateRange() { 
		// return one date from the upper left, and one from the lower right
		List<Date> ret = new List<Date>();
		ret.add(upperLeft);
		ret.add(upperLeft.addDays(5*7) );
		return ret;
	}
	public String getMonthName() { 
		return DateTime.newInstance(firstDate.year(),firstdate.month(),firstdate.day()).format('MMMM');
	} 
	
	public String getYearName() { 
		return DateTime.newInstance(
		firstDate.year(),firstdate.month(),firstdate.day()).format('yyyy');
	} 
	
	public String[] getWeekdayNames() { 
		Date today = system.today().toStartOfWeek();
		DateTime dt = DateTime.newInstanceGmt(today.year(),today.month(),today.day());		
		list<String> ret = new list<String>();
		for(Integer i = 0; i < 7;i++) { 
			ret.add( dt.formatgmt('EEEE') );
			dt= dt.addDays(1);
		} 
		return ret;
	}
	
	public Date getfirstDate() { return firstDate; } 
	


	public Month( Date value ) {
		weeks = new List<Week>();
		firstDate = value.toStartOfMonth();
		upperLeft = firstDate.toStartOfWeek();
		Date tmp = upperLeft;
		for (Integer i = 0; i <= 4; i++) {
			Week w = new Week(i+1,tmp,value.month());	
			system.assert(w!=null); 
			this.weeks.add( w );
			tmp = tmp.addDays(7);
		}


	}
	
	public List<Week> getWeeks() { 
		system.assert(weeks!=null,'could not create weeks list');
		return this.weeks; 
	}

	/* 
	 * helper classes to define a month in terms of week and day
	 */
	public class Week {
	 public List<Day> days;
	 public Integer weekNumber; 
	 public Date startingDate; // the date that the first of this week is on
	 // so sunday of this week
	 
	 public List<Day> getDays() { return this.days; }
	 
	 public Week () { 
	 	days = new List<Day>(); 	
	 }
	 public Week(Integer value,Date sunday,Integer month) { 
	 	this();
	 	weekNumber = value;
	 	startingDate = sunday;
	 	Date tmp = startingDate;
	 	for (Integer i = 0; i < 7; i++) {
	 		Day d = new Day( tmp,month ); 
	 		tmp = tmp.addDays(1);
	 		d.dayOfWeek = i+1;  		
	 	//	system.debug(d);
	 		days.add(d);
	 	} 
	 	
	 }
	 public Integer getWeekNumber() { return this.weekNumber;}
	 public Date getStartingDate() { return this.startingDate;}
	 
	}
	
	public class Day {
		 
		public Date 		theDate;
		public Integer 		month, dayOfWeek;
		public String 		formatedDate; // for the formated time 	
		private String 		cssclass = 'calActive';
		 
		public Date 		getDate() { return theDate; }
		public Integer 		getDayOfMonth() { return theDate.day(); }
		public String 		getDayOfMonth2() { 
			if ( theDate.day() <= 9 ) 
				return '0'+theDate.day(); 
			return String.valueof( theDate.day()); 
		}
		public Integer getDayOfYear() { return theDate.dayOfYear(); }
		public String 		getFormatedDate() { return formatedDate; }
		public Integer 		getDayNumber() { return dayOfWeek; }
		public String 		getCSSName() { 	return cssclass; }
		
		public Day(Date value,Integer vmonth) { 
			theDate=value; month=vmonth; 		
			formatedDate = '12 21 08';// time range..
			//9:00 AM - 1:00 PM
			// three possible Inactive,Today,Active	 
			if ( theDate.daysBetween(System.today()) == 0 ) cssclass ='calToday';
			// define inactive, is the date in the month?
			if ( theDate.month() != month) cssclass = 'calInactive';
		}
			
	}
}