-
1. Re: Pre Select selectOneMenu
nickarls May 19, 2008 9:35 AM (in response to lcurros)The item is selected when it's value matches the one where it's headed (the selectOneMenu value).
The matching is done with equals() and hashCode() in your entities when convertEntity is used. Override them. Use a SMPC. Drop any extra parameters etc.
Wow. That sounded authoritative for a guy just guessing ;-)
-
2. Re: Pre Select selectOneMenu
lcurros May 19, 2008 12:58 PM (in response to lcurros)Thanks Nicklas!
I tried to redefine equals()
@Override public boolean equals(Object obj) { if (obj == null) return false; else if (!(obj instanceof BeanType)) return false; else if (((BeanType) obj).getBeanTypeId().equals( this.beanTypeId)) return true; else return false; }
and hashCode() as you said
@Override public int hashCode() { int result = 17; result = 37 * result + (int) this.getBeanTypeId().intValue(); return result; }
But is still not preselecting anything.
Is correct this declaration of param and converterId to use in combination with s:converEntity?<param name="type" value="#{myBean.myBeanType}" converterId="org.jboss.seam.ui.EntityConverter"/>
-
3. Re: Pre Select selectOneMenu
lcurros May 20, 2008 10:10 AM (in response to lcurros)I couldn't solve this problem, I'm not sure why. Its strange because I was not getting errors.
But I found a workaround, I add a new property to my Search Action so now I have two.
Both properties store the selectedBeantype
- BeanType searchBeanType
- Long selectedBeantTypeId
So my selectOneMenu is basically the same
............. ............. <h:selectOneMenu value="#{searchAction.searchBeanType}"> <s:selectItems value="#{beanTypes.resultList}" var="type" label="#{type.name}" noSelectionLabel="Please Select..."/> <s:convertEntity /> </h:selectOneMenu> ............. .............
But the page param is different to selectOneMenu value. This is the change. (maybe the converterId I was using didn't work as I want)
<param name="type" value="#{searchAction.selectedBeanTypeId}" />
The getter and setter for this property are the attached. For searcBeanType property are the standard.
public Long getSelectedBeanTypeId() { return searchBeanType != null ? searchBeanType.getBeanTypeId() : null; } public void setSelectedBeanTypeId(Long id) { this.busquedaArea = entityManager.find(BeanType.class, id); }
With this approach the preselection of combo works. Maybe is not the best solution but works. If anybody can help me with the previous approach please reply the post!!thanks