This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 77518 - [55cat] Converter classes can't deal with composed primary keys
Summary: [55cat] Converter classes can't deal with composed primary keys
Status: VERIFIED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: JSF (show other bugs)
Version: 5.x
Hardware: PC Windows XP
: P2 blocker (vote)
Assignee: Pavel Buzek
URL:
Keywords:
: 77732 (view as bug list)
Depends on:
Blocks: 77705
  Show dependency tree
 
Reported: 2006-06-07 13:04 UTC by brviking
Modified: 2006-10-04 14:47 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description brviking 2006-06-07 13:04:56 UTC
NB 200606050200 daily build.
JDK 1.5.0_06.
WinXP.

Wrong code is generated for Converter class when entity has composed primary
key, leading to not compilable code. Sample (wrong) code:

  public Object getAsObject(FacesContext facesContext, UIComponent uIComponent,
String string) {
    SomeEntityController controller = (SomeEntityController)
facesContext.getApplication().getELResolver().getValue(
      facesContext.getELContext(), null, "somenEntityPredicativo");
    br.com.brinfo.entity.SomeEntityPK id =
(br.com.brinfo.entity.SomeEntityPK)string;
    return controller.findSomenEntity(id);
  }

Compile error when trying to cast String to SomeEntityPK.
Comment 1 Pavel Buzek 2006-06-08 16:20:06 UTC
You are right, of course.

I have a prototype of app for composed keys which I want to turn into the
generator. For the Converter I have a simple solution like id.getA() + ":" +
id.getB() - and then tokenize the String by ":" going back from String to
object. But this will only work for IDs that do not have ":" in them. I could
also add escaping for ":" (first replace : by ::), but this would add complexity
to the generated code. Maybe if I add it only if the keys are String values it
will be OK.

Any opinion on this? What would you do if you wrote it? Thanks.
Comment 2 brviking 2006-06-08 18:28:32 UTC
Well, your suggestion is almost what I've done actually
Just I used "|/" (pipe and a bar) as separator, since it's a very odd
combination. Could still cause problems (what could not in computer science?),
but is less probable. 
Anyway, there is no easy solution. Another one is convert keys into a piece of
XML, something like:
<pkcol><[CDATA[Value1]]></pkcol><pkcol<[CDATA[Value2]]></pkcol

and let XML libs deal with complexity encoding/decoding data...
XML solution may not be faster as spliting strings, but will certain give no
encoding errors, neither will add much complexity...
Comment 3 Petr Blaha 2006-06-12 10:26:24 UTC
*** Issue 77703 has been marked as a duplicate of this issue. ***
Comment 4 Petr Blaha 2006-06-12 10:28:03 UTC
I mark issue as fix-in-55 since we have a duplicate of this issue. This status
whiteboard means issue shall be fixed in NetBeans 5.5.
Comment 5 Petr Blaha 2006-06-12 16:28:13 UTC

*** This issue has been marked as a duplicate of 77732 ***
Comment 6 Petr Blaha 2006-06-13 17:02:45 UTC
My mistake, this issue should be opened. The issue #77703 tracks a different bug.
Comment 7 Petr Blaha 2006-06-13 17:06:36 UTC
*** Issue 77732 has been marked as a duplicate of this issue. ***
Comment 8 Petr Blaha 2006-06-21 12:49:58 UTC
Many internal users reported this issue directly to me. It shows that many users
face this bug in his project. Therefore, I'm changing priority to P2.
Comment 9 Pavel Buzek 2006-06-30 08:22:45 UTC
/cvs/web/jsf/src/org/netbeans/modules/web/jsf/palette/items/Attic/JsfForm.java,v
 new revision: 1.1.2.4.2.19; previous revision: 1.1.2.4.2.18
/cvs/web/jsf/src/org/netbeans/modules/web/jsf/palette/items/Attic/JsfTable.java,v
 new revision: 1.1.2.5.2.9; previous revision: 1.1.2.5.2.8
/cvs/web/jsf/src/org/netbeans/modules/web/jsf/wizards/Attic/JSFClinetGenerator.java,v
 new revision: 1.1.2.28; previous revision: 1.1.2.27

I've implemented the simple of converers (using ; as the delimiter) and some
related changes needed to make one entity with complex PKs work. I removed the
use of <f:param> for passing parameters between pages bcs converters are not
used for f:param and replaced this mechanism w/JSF DataModel. I will test more
scenarios with complex PKs as reported in issue 75688 and issue 76460.
Comment 10 Jaroslav Pospisil 2006-10-04 14:47:09 UTC
VERIFIED