You need to sign in to do that
Don't have an account?

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: <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
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?
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.
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:
And this is the class Month from which the object is generated: