Menu

Minor error in Edit.xhtml for many to many relationships

schifazl
2013-11-04
2013-11-06
  • schifazl

    schifazl - 2013-11-04

    I have a Customer table (id, name, surname, email etc.) in a many to many relationship with a Characteristic table (just an id an a name). When I click on the Edit button in the Customer page, sometimes the result is an empty window.

    Glassfish throws this error:

    javax.el.PropertyNotFoundException: /WEB-INF/include/entity/customer/Edit.xhtml @30,95 > value="#{customerController.selected.id.name}": The class 'java.lang.Long' does not have the property 'name'.

    So i have to change this:

    <h:outputLabel value="#{bundle.EditCustomerLabel_id}" for="id" />
    <h:outputText id="id" value="#{customerController.selected.id.name}"/>
    

    to this:

    <h:outputLabel value="#{bundle.EditCustomerLabel_id}" for="id" />
    <h:outputText id="id" value="#{customerController.selected.id}"/>
    

    Apparently PF CRUD appends the ".name" randomly and apparently not in the Create.xhtml pages.

    Thanks :)

     

    Last edit: schifazl 2013-11-05
  • Kay Wrobel

    Kay Wrobel - 2013-11-04

    Hm. Can you provide me with the actual schema for this example so I can generate the pages? And some sample data would be good too.

     
  • Kay Wrobel

    Kay Wrobel - 2013-11-04

    I just created two tables with information from what I read in your post, and the generator did not create such an EL expression in the Edit.xhtml of the Customer entity. Does this happen randomly?

     
  • schifazl

    schifazl - 2013-11-05

    Yes, it seems that this happens randomly. Today I'll prepare the schema you've asked yesterday.

     
  • schifazl

    schifazl - 2013-11-05

    I've attached a zip file with three classes: Customer2, which extends the abstract class EndUser2, and Characteristic, which is in a Many-To-Many relationship with Customer2.

    So I generate the PrimeFaces CRUD pages and test them. First I add some Characteristics in the Characterstic2 page and then I add one or more Customers in the Customer2 page.

    Then, if I select a customer and click on edit, an empty edit window will appear. in Customer2's Edit.xhtml, on line 30, I have this:

    <h:outputText id="id" value="#{customer2Controller.selected.id.name}"/>
    

    ... which is obviously wrong and should be:

    <h:outputText id="id" value="#{customer2Controller.selected.id}"/>
    

    After making this correction the Edit window works.

    I've found another minor aesthetic annoyance in View.xhtml: the h:selectManyMenu shows a single line. p:selectManyMenu is better, because it adapt it's height to the number of the contained relationship elements. It's possible to customize which elements will be generated?

    Thanks for your time!

     
  • Kay Wrobel

    Kay Wrobel - 2013-11-05

    Ok, I see it now. That's strange. I have to do some debugging. This tool relies a lot on internal APIs from NetBeans. I hope this doesn't happen on their end. I'll report back once I know more.

     
  • Kay Wrobel

    Kay Wrobel - 2013-11-05

    Alright, so I removed the @GeneratedValue annotation from EndUser2 and regenerated the pages. I wanted to compare Create.xhtml with Edit.xhtml. If a field has auto-generated values, the generator will skip such a field in Create.xhtml. To my surprise, Create.xhtml has the correct line:

    <p:outputLabel value="#{myBundle.CreateCustomer2Label_id}" for="id" />
    <p:inputText id="id" value="#{customer2Controller.selected.id}" title="#{myBundle.CreateCustomer2Title_id}" />
    

    So it seems as if the template file for Edit.xhtml has something bad in it. That said, I'm comparing both templates and they seem identical in how they refer to the field name. I'm baffled!

     
  • Kay Wrobel

    Kay Wrobel - 2013-11-05

    Ahhh wait, I had a brain fart there. They are not the same. The other one is a <p:outputText>. And I think I know where this is coming from. This has something to do with the function that checks for those artifact words. I'm debugging...

     
  • Kay Wrobel

    Kay Wrobel - 2013-11-05

    Ok, Schifazl:
    I know why it behaves the way it does. There are a few lines in Edit.xhtml that I'm not sure why I had put them in there, especially on the primary key field. I am removing them in the next release. If you don't want to wait for the next release, you can edit the template yourself. The lines affected are lines 88-92. Change this:

        <#if entityDescriptor.primaryKey || entityDescriptor.embeddedKey>
            <#if relationLabelName?? && relationLabelName != "">
                        <h:outputText id="${entityDescriptor.id?replace(".","_")}" value="${r"#{"}${entityDescriptor.name}.${relationLabelName}${r"}"}"/>
            <#else>
                        <h:outputText id="${entityDescriptor.id?replace(".","_")}" value="${r"#{"}${entityDescriptor.name}${r"}"}" />
            </#if>
        <#elseif entityDescriptor.dateTimeFormat?? && entityDescriptor.dateTimeFormat != "">
    

    to this:

        <#if entityDescriptor.primaryKey || entityDescriptor.embeddedKey>
                        <h:outputText id="${entityDescriptor.id?replace(".","_")}" value="${r"#{"}${entityDescriptor.name}${r"}"}" />
        <#elseif entityDescriptor.dateTimeFormat?? && entityDescriptor.dateTimeFormat != "">
    

    The point of relationLabelName is to find a display field for a related entity when there is one-to-many relationship. This is particularly useful on the List.xhtml and on the View.xhtml. Why I had added this particular logic on the Edit.xhtml and especially on the primary key field, I don't remember. I may have simply copied the code because the primary key field is an output field, but didn't think it through.

    If you make these changes to your template, make sure to remove the template file from your home directory once the new release is installed. Ok?

    Please give me some feedback if it worked for you.

     
  • schifazl

    schifazl - 2013-11-05

    Thank you for your help, tomorrow I'll try! Sorry for the stupid question, but how can I modify the template? In the "New PrimeFaces Pages and Classes" wizard there is a "Customize Template" text that seems a link, but nothing happens when I click it. Or should I modify the CRUD Generator's sources?

     
  • Kay Wrobel

    Kay Wrobel - 2013-11-05

    I am actually removing that link because it seems redundant and, as you mentioned, doesn't work. Instead, go to Tools->Templates and find PrimeFaces CRUD Generator in the list. The templates are another level below that.

     
  • schifazl

    schifazl - 2013-11-05

    Awesome! Tomorrow I'll let you know :)

     
  • Kay Wrobel

    Kay Wrobel - 2013-11-05

    Hey Schifazl, you may want to hold off with the edit and simply download the new version I just uploaded. It's version 0.19 and takes care of your problem.

     
  • schifazl

    schifazl - 2013-11-06

    Well done, everything works as expected now!

     

Anonymous
Anonymous

Add attachments
Cancel