Announcement Announcement Module
Collapse
No announcement yet.
JSF & <h:selectOneMenu/> & SelectItem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSF & <h:selectOneMenu/> & SelectItem

    Hi!

    I have Domainmodel Objects for Deliverer and Product
    So I have a Flow to list and add new Deliverer's and a Flow to list and add new Product's.

    For the Form where I want to create a new Product I want to have a Dropdown box with all Deliverers to choose from. And here is where all things get complicate ;-)

    For a <h:selectOneMenu/> I have an inner
    PHP Code:
    <f:selectItems value="#{flowScope.deliverers}" /> 
    And in the products.xml Flow Definition at NewProduct-View-State I'm getting all Deliverers from Service-Layer as follows:
    PHP Code:
    <on-entry>
                <
    evaluate expression="productService.getDeliverers()" result="flowScope.deliverers" result-type="selectItems"/>
    </
    on-entry
    Because the <f:selectItems need a List of SelectItem
    I have to write a custom SelectItemsConverter:
    PHP Code:
    public class SelectItemsConverter implements Converter {

        public Class[] 
    getSourceClasses() {
            return new Class[] { 
    Object[].class, List.class, Object.class };
        }

        public Class[] 
    getTargetClasses() {
            return new Class[] { 
    SelectItem.class };
        }

        public 
    Object convert(Object source, Class targetClassObject contextthrows Exception {
            if (
    source instanceof List){
                List<
    SelectItemresult = new ArrayList<SelectItem>();
                List 
    sourceList = (List) source;
                for (
    Object next sourceList){
                    if (
    next != null) {
                        
    result.add(new SelectItem(next,next.toString()));
                    }
                }
                return 
    result;
            }else{
                return 
    null;
            }
        }

    So this converter convertes a List of Deliverers to a List of SelectItem's.
    Why isn't there something generic from Spring already - Isn't this a problem which others also have?

    And what I don't know:
    The Constructor for SelectItem takes an Object value and a String label. Can I put the whole Deliverer Object as value, or do I have to put i.e. the PrimaryKey ID as value and create a javax.faces.convert.Converter to convert from the ID to the concrete Deliverer Object from DB?

    Thanks for your answers :-)

    wolfman

  • #2
    put the whole object as a value and write a jsf converter
    this is the official way
    joe

    Comment


    • #3
      look at
      http://jira.springframework.org/browse/SWF-548
      and vote for it if u like it to b added quickly
      joe

      Comment


      • #4
        Thanks!
        I voted now - probably all my problems would be solved with this issue
        thx!

        Comment


        • #5
          Originally posted by wolfman22 View Post
          Thanks!
          I voted now - probably all my problems would be solved with this issue
          thx!
          +1 on this one. This has been in Seam a long time, so I'm surprised it not here. I've voted as well. Waiting ...

          Comment


          • #6
            Hey guys,

            I was having the same issue you guys were. I was able to get around it using OGNL.

            Here is my example:

            Code:
            <evaluate expression="serviceRefData.getAllDepartments().{
            			#deptname=#this.getDepartmentNumber() + ' - ' + #this.getDepartmentName(), 
            			#deptid=#this.getDomainID(), 
            			new javax.faces.model.SelectItem(#deptid, #deptname)}" 
            			result="departments"/>

            Comment

            Working...
            X