diff --git a/scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/metawidget/inspector/ForgeInspectionResultConstants.java b/scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/metawidget/inspector/ForgeInspectionResultConstants.java
index f6d0e897e0..2a23de1533 100644
--- a/scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/metawidget/inspector/ForgeInspectionResultConstants.java
+++ b/scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/metawidget/inspector/ForgeInspectionResultConstants.java
@@ -35,11 +35,13 @@ public final class ForgeInspectionResultConstants
/**
* Whether the field is an Id.
*/
+
public static final String PRIMARY_KEY = "primary-key";
/**
- * The reverse primary key of a JPA relationship.
+ * The reverse primary key of a ManyToOne relationship.
*/
+
public static final String REVERSE_PRIMARY_KEY = "reverse-primary-key";
/**
@@ -56,7 +58,7 @@ public final class ForgeInspectionResultConstants
* The inverse field of a bi-directional relationship
*/
public static final String INVERSE_FIELD = "inverse-field";
-
+
//
// Private constructor
//
diff --git a/scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/metawidget/widgetbuilder/EntityWidgetBuilder.java b/scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/metawidget/widgetbuilder/EntityWidgetBuilder.java
index 3ecd7afb1c..0f12ee2fe1 100644
--- a/scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/metawidget/widgetbuilder/EntityWidgetBuilder.java
+++ b/scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/metawidget/widgetbuilder/EntityWidgetBuilder.java
@@ -49,8 +49,6 @@
import org.metawidget.statically.faces.component.html.widgetbuilder.HtmlSelectOneMenu;
import org.metawidget.statically.faces.component.html.widgetbuilder.HtmlWidgetBuilder;
import org.metawidget.statically.faces.component.html.widgetbuilder.Param;
-import org.metawidget.statically.faces.component.html.widgetbuilder.SelectItem;
-import org.metawidget.statically.faces.component.html.widgetbuilder.SelectItems;
import org.metawidget.statically.faces.component.widgetprocessor.ReadableIdProcessor;
import org.metawidget.statically.faces.component.widgetprocessor.RequiredAttributeProcessor;
import org.metawidget.statically.faces.component.widgetprocessor.StandardBindingProcessor;
@@ -91,8 +89,6 @@ public class EntityWidgetBuilder
*/
private static final String PARAMETERIZED_TYPE_PATH = "parameterized-type-path";
-
- private static final String SELECT_ITEM = "_item";
/**
* Current Forge Configuration. Useful to retrieve targetDir
.
@@ -149,26 +145,27 @@ public StaticXmlWidget buildWidget(String elementName, Map attri
HtmlOutcomeTargetLink link = new HtmlOutcomeTargetLink();
link.putAttribute("outcome", getTargetDir() + "/" + controllerName + "/view");
- String valueExpression = StaticFacesUtils.unwrapExpression(((ValueHolder) metawidget).getValue());
- valueExpression += StringUtils.SEPARATOR_DOT_CHAR + StringUtils.decapitalize(attributes.get(NAME));
- String reverseKey = "id";
- if (attributes.containsKey(REVERSE_PRIMARY_KEY))
+
+ StandardBindingProcessor bindingProcessor = metawidget.getWidgetProcessor(StandardBindingProcessor.class);
+
+ if (bindingProcessor != null)
{
- reverseKey = attributes.get(REVERSE_PRIMARY_KEY);
+ bindingProcessor.processWidget(link, elementName, attributes,
+ (StaticUIMetawidget) metawidget);
}
+
+ String reverseKey = "id";
if (attributes.containsKey(REVERSE_PRIMARY_KEY))
{
- valueExpression += StringUtils.SEPARATOR_DOT_CHAR + StringUtils.decapitalize(reverseKey);
+ reverseKey = attributes.get(REVERSE_PRIMARY_KEY);
}
- String parameterizedType = attributes.get(PARAMETERIZED_TYPE);
- link.putAttribute("value", ClassUtils.getSimpleName(parameterizedType == null ? attributes.get(TYPE)
- : parameterizedType) + " "
- + reverseKey
- + " : " + StaticFacesUtils.wrapExpression(valueExpression));
Param param = new Param();
param.putAttribute("name", "id");
- param.putAttribute("value", StaticFacesUtils.wrapExpression(valueExpression));
+ param.putAttribute(
+ "value",
+ StaticFacesUtils.wrapExpression(StaticFacesUtils.unwrapExpression(link.getValue()) + StringUtils.SEPARATOR_DOT_CHAR
+ + reverseKey));
link.getChildren().add(param);
return link;
@@ -198,18 +195,8 @@ public StaticXmlWidget buildWidget(String elementName, Map attri
return outputText;
}
-
}
}
-
- // Change the labels of the f:selectItems in the h:select widget (when FACES_LOOKUP is present)
- String facesLookup = attributes.get( FACES_LOOKUP );
-
- if ( facesLookup != null && !"".equals( facesLookup ) ) {
- HtmlSelectOneMenu select = new HtmlSelectOneMenu();
- addSelectItems( select, facesLookup, attributes );
- return select;
- }
// Render collection tables with links
@@ -381,7 +368,8 @@ protected StaticXmlWidget createDataTableComponent(String elementName, Map emptyAttributes = CollectionUtils.newHashMap();
+ addSelectItems(select, StaticFacesUtils.wrapExpression(controllerName + "Bean.all"), emptyAttributes);
panelGrid.getChildren().add(select);
// Create 'Add' button
@@ -585,20 +573,6 @@ protected void addColumnComponent(HtmlDataTable dataTable, Map t
+ primaryKeyName));
link.getChildren().add(param);
link.getChildren().add(column.getChildren().remove(1));
- if(columnAttributes.containsKey(FACES_LOOKUP) && columnAttributes.containsKey(REVERSE_PRIMARY_KEY))
- {
- String reversePrimaryKey = columnAttributes.get(REVERSE_PRIMARY_KEY);
- String parameterizedType = columnAttributes.get(PARAMETERIZED_TYPE);
- String valueExpression = dataTable.getAttribute("var") + StringUtils.SEPARATOR_DOT_CHAR
- + StringUtils.decapitalize(columnAttributes.get(NAME)) + StringUtils.SEPARATOR_DOT_CHAR
- + StringUtils.decapitalize(reversePrimaryKey);
-
- StaticHtmlMetawidget output = (StaticHtmlMetawidget) link.getChildren().get(1);
- output.setValue(ClassUtils.getSimpleName(parameterizedType == null ? columnAttributes.get(TYPE)
- : parameterizedType) + " "
- + reversePrimaryKey
- + " : " + StaticFacesUtils.wrapExpression(valueExpression));
- }
if (tableAttributes.get(PARAMETERIZED_TYPE_PATH) != null)
{
// Recreate the EL expression. This is done to ensure that correctly nested EL expressions are created for
@@ -654,47 +628,6 @@ protected void addColumnComponent(HtmlDataTable dataTable, Map t
}
}
}
-
- /**
- * Overrriden to enhance the default f:selectItem widget with more suitable item labels
- */
- @Override
- protected void addSelectItems( HtmlSelectOneMenu select, String valueExpression, Map attributes ) {
-
- // Empty option
- //
- // Note: a 'null' value (rather than an empty String') renders an rather
- // than an . This works out better if the HtmlSelectOneMenu has
- // a converter, because the empty String may not be a compatible value
-
- if ( WidgetBuilderUtils.needsEmptyLookupItem( attributes ) ) {
- addSelectItem( select, null, null );
- }
-
- // Add the select items
-
- SelectItems selectItems = new SelectItems();
- selectItems.putAttribute("value", valueExpression);
-
- // For each item to be displayed, set the label to the reverse primary key value
- if (attributes.containsKey(REVERSE_PRIMARY_KEY))
- {
- selectItems.putAttribute("var", SELECT_ITEM);
- selectItems.putAttribute("itemValue", StaticFacesUtils.wrapExpression(SELECT_ITEM));
- String reversePrimaryKey = attributes.get(REVERSE_PRIMARY_KEY);
- String parameterizedType = attributes.get(PARAMETERIZED_TYPE);
- selectItems.putAttribute(
- "itemLabel",
- ClassUtils.getSimpleName(parameterizedType == null ? attributes.get(TYPE) : parameterizedType)
- + " "
- + reversePrimaryKey
- + " : "
- + StaticFacesUtils.wrapExpression(SELECT_ITEM + StringUtils.SEPARATOR_DOT
- + StringUtils.decapitalize(reversePrimaryKey)));
- }
-
- select.getChildren().add( selectItems );
- }
//
// Private methods
@@ -717,13 +650,4 @@ private String getTargetDir()
return target;
}
-
- private void addSelectItem( HtmlSelectOneMenu select, String value, String label ) {
-
- SelectItem selectItem = new SelectItem();
- selectItem.putAttribute( "itemLabel", label );
- selectItem.putAttribute( "itemValue", value );
-
- select.getChildren().add( selectItem );
- }
}
diff --git a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/FacesScaffoldTest.java b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/FacesScaffoldTest.java
index d3cabe8cff..4ed3b42a2b 100644
--- a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/FacesScaffoldTest.java
+++ b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/FacesScaffoldTest.java
@@ -8,7 +8,6 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import static org.junit.matchers.JUnitMatchers.containsString;
import java.util.Arrays;
import java.util.List;
@@ -722,11 +721,11 @@ public void testGenerateManyToOneEntity() throws Exception
.append("")
.append(CRLF);
metawidget.append("\t\t\t").append("").append(CRLF);
- metawidget.append("\t\t\t").append("")
+ metawidget.append("\t\t\t").append("")
.append(CRLF);
metawidget
.append("\t\t\t")
- .append("")
+ .append("")
.append(CRLF);
metawidget.append("\t\t\t\t").append("")
.append(CRLF);
@@ -734,7 +733,7 @@ public void testGenerateManyToOneEntity() throws Exception
metawidget.append("\t\t\t").append("").append(CRLF);
metawidget.append("\t\t").append("");
- Assert.assertThat(contents, containsString(metawidget.toString()));
+ Assert.assertTrue(contents.contains(metawidget));
// Create
@@ -776,7 +775,7 @@ public void testGenerateManyToOneEntity() throws Exception
.append("")
.append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("").append(CRLF);
- metawidget.append("\t\t\t\t\t\t").append("").append(CRLF);
+ metawidget.append("\t\t\t\t\t\t").append("").append(CRLF);
metawidget.append("\t\t\t\t\t").append("").append(CRLF);
metawidget.append("\t\t\t\t\t").append("")
.append(CRLF);
@@ -784,7 +783,7 @@ public void testGenerateManyToOneEntity() throws Exception
metawidget.append("\t\t\t\t").append("").append(CRLF);
metawidget.append("\t\t\t").append("");
- Assert.assertThat(contents, containsString(metawidget.toString()));
+ Assert.assertTrue(contents.contains(metawidget));
// Search
@@ -1006,8 +1005,7 @@ public void testGenerateOneToManyEntity() throws Exception
"value=\"#{requestScope['customerBeanCustomerGroceriesSelect']}\">")
.append(CRLF);
metawidget.append("\t\t\t\t\t\t\t").append("").append(CRLF);
- metawidget.append("\t\t\t\t\t\t\t").append("").append(CRLF);
+ metawidget.append("\t\t\t\t\t\t\t").append("").append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("").append(CRLF);
metawidget
.append("\t\t\t\t\t\t")
@@ -1025,7 +1023,7 @@ public void testGenerateOneToManyEntity() throws Exception
metawidget.append("\t\t\t\t").append("").append(CRLF);
metawidget.append("\t\t\t").append("");
- Assert.assertThat(contents, containsString(metawidget.toString()));
+ Assert.assertTrue(contents.contains(metawidget));
Assert.assertTrue(contents.contains("xmlns:forgeview=\"http://jboss.org/forge/view\""));
// Search
diff --git a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/PrimaryKeyFacesScaffoldTest.java b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/PrimaryKeyFacesScaffoldTest.java
index 0a852d7706..b5116e9033 100644
--- a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/PrimaryKeyFacesScaffoldTest.java
+++ b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/PrimaryKeyFacesScaffoldTest.java
@@ -6,9 +6,7 @@
*/
package org.jboss.forge.scaffold.faces;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.junit.matchers.JUnitMatchers.containsString;
import java.io.FileNotFoundException;
import java.io.Serializable;
@@ -127,13 +125,12 @@ public void testGenerateFromLegacyEntity() throws Exception
.append("")
.append(CRLF);
metawidget.append("\t\t\t\t\t\t\t\t").append("").append(CRLF);
- metawidget.append("\t\t\t\t\t\t\t\t").append("").append(CRLF);
+ metawidget.append("\t\t\t\t\t\t\t\t").append("").append(CRLF);
metawidget.append("\t\t\t\t\t\t\t").append("").append(CRLF);
metawidget.append("\t\t\t\t\t\t\t").append("")
.append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("").append(CRLF);
- assertThat(contents, containsString(metawidget.toString()));
+ assertTrue(contents.contains(metawidget));
// Create Parent
@@ -165,13 +162,12 @@ public void testGenerateFromLegacyEntity() throws Exception
.append("\t\t\t\t\t")
.append("")
.append(CRLF);
- metawidget.append("\t\t\t\t\t\t").append("").append(CRLF);
+ metawidget.append("\t\t\t\t\t\t").append("").append(CRLF);
metawidget.append("\t\t\t\t\t").append("").append(CRLF);
metawidget.append("\t\t\t\t\t").append("")
.append(CRLF);
metawidget.append("\t\t\t\t").append("").append(CRLF);
- assertThat(contents, containsString(metawidget.toString()));
+ assertTrue(contents.contains(metawidget));
// View Child
diff --git a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/metawidget/widgetbuilder/EntityWidgetBuilderTest.java b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/metawidget/widgetbuilder/EntityWidgetBuilderTest.java
index 7dea80dcb8..01264d7ac4 100644
--- a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/metawidget/widgetbuilder/EntityWidgetBuilderTest.java
+++ b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/metawidget/widgetbuilder/EntityWidgetBuilderTest.java
@@ -8,7 +8,6 @@
import static org.jboss.forge.scaffold.faces.metawidget.inspector.ForgeInspectionResultConstants.N_TO_MANY;
import static org.jboss.forge.scaffold.faces.metawidget.inspector.ForgeInspectionResultConstants.ONE_TO_ONE;
-import static org.jboss.forge.scaffold.faces.metawidget.inspector.ForgeInspectionResultConstants.REVERSE_PRIMARY_KEY;
import static org.metawidget.inspector.InspectionResultConstants.INVERSE_RELATIONSHIP;
import static org.metawidget.inspector.InspectionResultConstants.NAME;
import static org.metawidget.inspector.InspectionResultConstants.PARAMETERIZED_TYPE;
@@ -69,10 +68,9 @@ public void testManyToOne()
attributes.put(TYPE, Bar.class.getName());
attributes.put(READ_ONLY, TRUE);
attributes.put(FACES_LOOKUP, "#{barBean.all}");
- attributes.put(REVERSE_PRIMARY_KEY, "id");
StaticWidget widget = widgetBuilder.buildWidget(PROPERTY, attributes, metawidget);
- String result = "";
+ String result = "";
result += "";
result += "";
diff --git a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/petclinic/FacesScaffoldPetClinicClient.java b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/petclinic/FacesScaffoldPetClinicClient.java
index bd7116ee55..5b379c31e1 100644
--- a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/petclinic/FacesScaffoldPetClinicClient.java
+++ b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/petclinic/FacesScaffoldPetClinicClient.java
@@ -100,11 +100,12 @@ public void testAll() throws Exception
assertEquals("", booleanNode.getTextContent());
assertEquals("boolean-true", booleanNode.getAttributes().getNamedItem("class").getNodeValue());
- assertEquals("Owner id : 1", table.getCellAt(1, 3).getTextContent());
+ assertEquals("Owner firstName: Owner Firstname #1, lastName: Owner Lastname #1, address: Owner Address #1", table.getCellAt(1, 3)
+ .getTextContent());
page = page.getAnchorByText("Pet #1").click();
assertTrue(page.asText().contains("View existing Pet"));
- page = page.getAnchorByText("Owner id : 1").click();
+ page = page.getAnchorByText("Owner firstName: Owner Firstname #1, lastName: Owner Lastname #1, address: Owner Address #1").click();
assertTrue(page.asText().contains("View existing Owner"));
// Create a new Owner
diff --git a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/petclinic/FacesScaffoldPetClinicTest.java b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/petclinic/FacesScaffoldPetClinicTest.java
index 2d291f6156..df6082f630 100644
--- a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/petclinic/FacesScaffoldPetClinicTest.java
+++ b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/petclinic/FacesScaffoldPetClinicTest.java
@@ -6,8 +6,6 @@
*/
package org.jboss.forge.scaffold.faces.scenario.petclinic;
-import static org.junit.matchers.JUnitMatchers.containsString;
-
import java.util.Arrays;
import javax.inject.Inject;
@@ -106,10 +104,10 @@ public void testGenerate() throws Exception
metawidget = "\t\t\t\t\t\r\n";
metawidget += "\t\t\t\t\t\t\r\n";
- metawidget += "\t\t\t\t\t\t\r\n";
+ metawidget += "\t\t\t\t\t\t\r\n";
metawidget += "\t\t\t\t\t\r\n";
- Assert.assertThat(contents, containsString(metawidget));
+ Assert.assertTrue(contents.contains(metawidget));
// Check create screen has h:selectBooleanCheckbox
diff --git a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/shopping/FacesScaffoldShoppingClient.java b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/shopping/FacesScaffoldShoppingClient.java
index 62005c6169..cc59faa009 100644
--- a/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/shopping/FacesScaffoldShoppingClient.java
+++ b/scaffold-faces/src/test/java/org/jboss/forge/scaffold/faces/scenario/shopping/FacesScaffoldShoppingClient.java
@@ -100,7 +100,7 @@ public void testAll() throws Exception
.setSelectedAttribute("2", true);
page = page.getHtmlElementById("create:customerBeanCustomerOrders:customerBeanCustomerOrdersAdd").click();
table = (HtmlTable) page.getHtmlElementById("create:customerBeanCustomerOrders");
- assertEquals("Address id : 2", table.getCellAt(2, 0).getTextContent());
+ assertEquals("Address street: Address Street #2, City: Address City #2, zipCode: 0", table.getCellAt(2, 0).getTextContent());
// Test adding multiple OneToMany (mappedBy) before clicking Save
@@ -109,8 +109,8 @@ public void testAll() throws Exception
.setSelectedAttribute("3", true);
page = page.getHtmlElementById("create:customerBeanCustomerOrders:customerBeanCustomerOrdersAdd").click();
table = (HtmlTable) page.getHtmlElementById("create:customerBeanCustomerOrders");
- assertTrue( "Address id : 2".equals(table.getCellAt(2, 0).getTextContent()) || "Address id : 3".equals(table.getCellAt(2, 0).getTextContent() ));
- assertTrue( "Address id : 2".equals(table.getCellAt(3, 0).getTextContent()) || "Address id : 3".equals(table.getCellAt(3, 0).getTextContent() ));
+ assertTrue( "Address street: Address Street #2, City: Address City #2, zipCode: 0".equals(table.getCellAt(2, 0).getTextContent()) || "Address street: Address Street #3, City: Address City #3, zipCode: 0".equals(table.getCellAt(2, 0).getTextContent() ));
+ assertTrue( "Address street: Address Street #2, City: Address City #2, zipCode: 0".equals(table.getCellAt(3, 0).getTextContent()) || "Address street: Address Street #3, City: Address City #3, zipCode: 0".equals(table.getCellAt(3, 0).getTextContent() ));
assertTrue(!table.getCellAt(2, 0).getTextContent().equals(table.getCellAt(3, 0).getTextContent()));
page = page.getAnchorByText("Save").click();
@@ -128,8 +128,8 @@ public void testAll() throws Exception
table = (HtmlTable) page.getHtmlElementById("customerBeanCustomerAddresses");
assertEquals("Address Street #1", table.getCellAt(1, 0).getTextContent());
table = (HtmlTable) page.getHtmlElementById("customerBeanCustomerOrders");
- assertTrue( "Address id : 2".equals(table.getCellAt(1, 0).getTextContent()) || "Address id : 3".equals(table.getCellAt(1, 0).getTextContent() ));
- assertTrue( "Address id : 2".equals(table.getCellAt(2, 0).getTextContent()) || "Address id : 3".equals(table.getCellAt(2, 0).getTextContent() ));
+ assertTrue( "Address street: Address Street #2, City: Address City #2, zipCode: 0".equals(table.getCellAt(1, 0).getTextContent()) || "Address street: Address Street #3, City: Address City #3, zipCode: 0".equals(table.getCellAt(1, 0).getTextContent() ));
+ assertTrue( "Address street: Address Street #2, City: Address City #2, zipCode: 0".equals(table.getCellAt(2, 0).getTextContent()) || "Address street: Address Street #3, City: Address City #3, zipCode: 0".equals(table.getCellAt(2, 0).getTextContent() ));
assertTrue(!table.getCellAt(1, 0).getTextContent().equals(table.getCellAt(2, 0).getTextContent()));
// Test foreign key constraints