-
1. Re: <s:selectItems> label and value
dhinojosa Jan 31, 2008 1:09 PM (in response to monkeyden)Well, if I understand you correctly, the value cannot be adjusted because Seam needs that to be able to convert that value into an entity. But I don't see why you can't use region.regionName in the label. The label is free for your use.
-
2. Re: <s:selectItems> label and value
monkeyden Jan 31, 2008 1:31 PM (in response to monkeyden)I'm likely misunderstanding it's usage. It now seems as though the value of the component becomes an instance of the Entity, for example:
<h:selectOneMenu id="regionSelect" value="#{contentAdmin.selectedRegion}" styleClass="formElement"> <s:selectItems var="region" value="#{regions.resultList}" label="#{region.regionCode}" noSelectionLabel="Please select a region..."/> <f:converter converterId="entityConverter" /> </h:selectOneMenu>
public Region getSelectedRegion() { return selectedRegion; } public void setSelectedRegion(Region selectedRegion) { this.selectedRegion = selectedRegion; }
Is this true? I was attempting to use the PK of the entity (a String).
Thanks -
3. Re: <s:selectItems> label and value
dhinojosa Jan 31, 2008 6:02 PM (in response to monkeyden)'instance of the Entity' is a weird term to me....
Seam, when it was in CR, created an arbitrary value to represent the entity and made that number the value of the selectitem when it was rendered. The convertEntity tags takes that choice, grabs it's corresponding entity and injects that into whatever value you set it to. -
4. Re: <s:selectItems> label and value
pmuir Feb 1, 2008 5:21 AM (in response to monkeyden)Dan is correct. However 2.0.1 allows you two options to customize the value. If you don't use the entity converter, use the itemValue attribute on s:selectItems. If you do, you need to implement a custom entity loading strategy. I'll blog about that soon.
-
5. Re: <s:selectItems> label and value
nickarls Feb 7, 2008 7:21 AM (in response to monkeyden)"pete.muir@jboss.org" wrote:
Dan is correct. However 2.0.1 allows you two options to customize the value. If you don't use the entity converter, use the itemValue attribute on s:selectItems. If you do, you need to implement a custom entity loading strategy. I'll blog about that soon.
What do you mean by the "If you don't use the entity converter, use the itemValue attribute on s:selectItems"?
I'm trying to do a case of an entity@Entity public class User { @Id @GeneratedValue private Integer id; private String code; private String name ... getters/setters/hashCode/equals
and would like to do something like<f:selectOneMenu value="#{userBean.user.code}" required="true"> <s:selectItems value=#{userBean.userList} var="user" label="#{user.name}" itemValue="#{user.code}" > <s:convertEntity/> </selectItems> </f:selectOneMenu>
where userBean.userList is a List
should this be doable (displaying name, selecting code) with convertEntity?
I keep getting "Value is required" on it despite of equals/hashcode... -
6. Re: <s:selectItems> label and value
nickarls Feb 7, 2008 7:39 AM (in response to monkeyden)The strange this is that equals() and hashCode() are not being accessed at all. Neither is the setter of the value. It just makes up that the value is null although the selectbox option value and label are correct...
-
7. Re: <s:selectItems> label and value
dhinojosa Feb 7, 2008 12:33 PM (in response to monkeyden)@nickarls
You have to choose either of these options.
Note:removed <s:convertEntity> because a java.lang.String is not an entity<f:selectOneMenu value="#{userBean.user.code}" required="true"> <s:selectItems value=#{userBean.userList} var="user" label="#{user.name}" itemValue="#{user.code}" > </selectItems> </f:selectOneMenu>
or
Note: I am using <s:convertEntity> because User is indeed an entity.<f:selectOneMenu value="#{userBean.user}" required="true"> <s:selectItems value=#{userBean.userList} var="user" label="#{user.name}" > <s:convertEntity/> </selectItems> </f:selectOneMenu>
-
8. Re: <s:selectItems> label and value
nickarls Feb 8, 2008 1:24 AM (in response to monkeyden)Thanks, that did it!
I was under the impression that I had to use the entityConverter since the backing data weren't SelectItems, but it seems that the entityConverter (and the SMPC to avoid LIE:s) are only required when actually inserting an entity?
That pretty much moves my SelectItem usage into the legacy-hierarchy, I won't miss it.