dropdownmenu to backing bean save state
codecoaster Feb 26, 2008 10:01 AMI have an advanced search form and have set up a dropdownmenu to take the operation to be performed on the search date. eg. On-Before-After etc.
Here is the code which seems to work as intended and the dateOp value is being changed in the backing bean.
here is the code for the menu:
<h:column id="ddcol"> <h:form id="ddform"> <!--plan:when a date operation is selected it stores the value in dateOperation--> <!--The value in dOp should be rendered with value of dateOperation--> <!--When the search button is clicked dateOperation etc will be passed to a method in backing bean--> <rich:dropDownMenu id="ddmenu" submitMode="ajax" binding="#{«asInstanceVar()»CrudBacking.dateOp}" onitemselect="render='form.dOp'" immediate="true" > <f:facet name="label"> <h:panelGrid id="pg" cellpadding="0" cellspacing="0" columns="2" style="vertical-align:middle"> <h:graphicImage value="/images/icons/date_go.png" style="border: 0px"/> <h:outputText id="t" value="Date" /> </h:panelGrid> </f:facet> <rich:menuItem value="On" reRender="form.dOp" icon="/images/icons/flag_blue.png" > <f:param id="On" name="id" value="On" /> </rich:menuItem> <rich:menuItem value="Before" icon="/images/icons/resultset_previous.png" > <f:param id="Before" name="id" value="Before" /> </rich:menuItem> <rich:menuItem value="After" icon="/images/icons/resultset_next.png" > <f:param id="After" name="id" value="After" /> </rich:menuItem> <rich:menuItem value="Between" immediate="true" icon="/images/icons/tag.png"> <f:param id="Between" name="id" value="Between" /> </rich:menuItem> <rich:menuItem value="Any" > <f:param id="Any" name="id" value="Any" /> </rich:menuItem> </rich:dropDownMenu> </h:form> </h:column> <h:column id="outCol" styleClass="header"> <h:outputText id="dOp" render="true" ajaxRendered="true" name="dateOp" style="font-weight:bold" immediate="true" value="#{«asInstanceVar()»CrudBacking.dateOp}" /> </h:column>
This is the code in the backing bean:
public void setDateOp(String s){ FacesContext ctx = FacesContext.getCurrentInstance(); this.dateOp = (String)ctx.getExternalContext().getRequestParameterMap().get("id"); System.out.println("setting date op from string: "+dateOp); }
The code to get the dateOp string from the bean is:
public String getDateOp(){ if(dateOp==null){dateOp="Any";} System.out.println("getting date op: "+dateOp); return dateOp; }
I have the dateOp variable initialised as:
public String dateOp="On";
The problem is the value returned from the bean is always 'Any'
Any help with this would be great as i have been stuck on this for over a week!
Thanks in advance
Codecoaster