-
1. Re: display selected item on selectonelistbox using s:convertEntity
jseanjensen Dec 14, 2011 3:49 PM (in response to jseanjensen)I've come up with a solution to my problem. . . sort of. I set the noSelectionLabel to be the instance owner name which gives me the display output that I need but seems to be a hack. Then my problem turns into how to render the same page to create a new axe but not be forced to select an owner. I ended up creating two listboxes and conditionally rendering them so that I can render a selection when there is one but allow the user to create a new axe without picking an owner. This is how I did it.
<s:decorate id="ownerField" template="layout/edit.xhtml"> <ui:define name="label">Owner</ui:define> <h:selectOneListbox rendered="#{axeHome.instance.owner ne null}" id="editOwner" value="#{axeHome.instance.owner}" size="1"> <s:selectItems noSelectionLabel="#{axeHome.instance.owner.name}" hideNoSelectionLabel="false" var="axeOwner" value="#{axeOwnerList.resultList}" itemValue="#{axeOwner}" label="#{axeOwner.name}" /> <s:convertEntity/> </h:selectOneListbox> <h:selectOneListbox rendered="#{axeHome.instance.owner eq null}" id="addOwner" value="#{axeHome.instance.owner}" size="1"> <s:selectItems noSelectionLabel="Select Owner" hideNoSelectionLabel="false" var="axeOwner" value="#{axeOwnerList.resultList}" itemValue="#{axeOwner}" label="#{axeOwner.name}" /> <s:convertEntity/> </h:selectOneListbox> </s:decorate>
The axe and axeOwner classes are simple entities:
@Entity public class Axe implements Serializable { private Long id; private Integer version; private String name; private String history; private AxeOwner owner; ... getters and setters ... } @Entity public class AxeOwner implements Serializable { private Long id; private Integer version; private String name; ... getters and setters ... }
This solution may work in my application but it seems like a hack. It seems strange that the select attribute of the list items isn't triggered. I was hoping someone would explain this to me but I had to figure it out for myself. Is there anywhere that is more active for this sort of thing than this forum?
-
2. Re: display selected item on selectonelistbox using s:convertEntity
mikkus70 Dec 16, 2011 12:11 PM (in response to jseanjensen)Don't use the itemValue property of the s:selectItems tag, s:convertEntity should handle that for you (if you put #{axeOwner} there, it should evaluate it to the class toString() method, which is not what s:convertEntity expects.
See the documentation section 33.1.2.2 which gives an example of how s:convertEntity should be used. Note the usage example given:
<h:selectOneMenu value="#{person.continent}" required="true"> <s:selectItems value="#{continents.resultList}" var="continent" label="#{continent.name}" noSelectionLabel="Please Select..."/> <s:convertEntity /> </h:selectOneMenu>
-
3. Re: display selected item on selectonelistbox using s:convertEntity
ahmeric Dec 22, 2011 4:24 AM (in response to jseanjensen)Emir is right. but this is not the solution for this problem.
I have the same trouble. and I couldn't find any solution except Sean did.@Sean , have you found any new solution for this stituation.
thnx.
-
4. Re: display selected item on selectonelistbox using s:convertEntity
vata2999 Dec 23, 2011 3:58 AM (in response to jseanjensen)have u tried to begin conversation in order to set axOwner it perfectly works for me
AxOwnerList.java
@Override @Begin(join=true) public List getResultList(){ //whatever }