Skip to content

Commit

Permalink
Revert "FORGE-873 Overrides behavior of default HtmlWidgetBuilder..."
Browse files Browse the repository at this point in the history
This reverts commit 065e316.

Reverting since this could be fixed in a better way.
  • Loading branch information
VineetReynolds committed Jul 12, 2013
1 parent fb8d057 commit 913ae1e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand All @@ -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
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <code>targetDir</code>.
Expand Down Expand Up @@ -149,26 +145,27 @@ public StaticXmlWidget buildWidget(String elementName, Map<String, String> 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;
Expand Down Expand Up @@ -198,18 +195,8 @@ public StaticXmlWidget buildWidget(String elementName, Map<String, String> 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

Expand Down Expand Up @@ -381,7 +368,8 @@ protected StaticXmlWidget createDataTableComponent(String elementName, Map<Strin
String simpleComponentType = ClassUtils.getSimpleName(componentType);
String controllerName = StringUtils.decapitalize(simpleComponentType);
select.setConverter(StaticFacesUtils.wrapExpression(controllerName + "Bean.converter"));
addSelectItems(select, StaticFacesUtils.wrapExpression(controllerName + "Bean.all"), attributes);
Map<String, String> emptyAttributes = CollectionUtils.newHashMap();
addSelectItems(select, StaticFacesUtils.wrapExpression(controllerName + "Bean.all"), emptyAttributes);
panelGrid.getChildren().add(select);

// Create 'Add' button
Expand Down Expand Up @@ -585,20 +573,6 @@ protected void addColumnComponent(HtmlDataTable dataTable, Map<String, String> 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
Expand Down Expand Up @@ -654,47 +628,6 @@ protected void addColumnComponent(HtmlDataTable dataTable, Map<String, String> t
}
}
}

/**
* Overrriden to enhance the default f:selectItem widget with more suitable item labels
*/
@Override
protected void addSelectItems( HtmlSelectOneMenu select, String valueExpression, Map<String, String> attributes ) {

// Empty option
//
// Note: a 'null' value (rather than an empty String') renders an <f:selectItem/> rather
// than an <f:selectItem itemValue=""/>. 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
Expand All @@ -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 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -722,19 +721,19 @@ public void testGenerateManyToOneEntity() throws Exception
.append("<h:outputText id=\"customerBeanCustomerLastName\" value=\"#{customerBean.customer.lastName}\"/>")
.append(CRLF);
metawidget.append("\t\t\t").append("<h:outputText/>").append(CRLF);
metawidget.append("\t\t\t").append("<h:outputLabel for=\"employeridcustomerBeanCustomerEmployerId\" value=\"Employer:\"/>")
metawidget.append("\t\t\t").append("<h:outputLabel for=\"customerBeanCustomerEmployer\" value=\"Employer:\"/>")
.append(CRLF);
metawidget
.append("\t\t\t")
.append("<h:link id=\"employeridcustomerBeanCustomerEmployerId\" outcome=\"/employer/view\" value=\"Employer id : #{customerBean.customer.employer.id}\">")
.append("<h:link id=\"customerBeanCustomerEmployer\" outcome=\"/employer/view\" value=\"#{customerBean.customer.employer}\">")
.append(CRLF);
metawidget.append("\t\t\t\t").append("<f:param name=\"id\" value=\"#{customerBean.customer.employer.id}\"/>")
.append(CRLF);
metawidget.append("\t\t\t").append("</h:link>").append(CRLF);
metawidget.append("\t\t\t").append("<h:outputText/>").append(CRLF);
metawidget.append("\t\t").append("</h:panelGrid>");

Assert.assertThat(contents, containsString(metawidget.toString()));
Assert.assertTrue(contents.contains(metawidget));

// Create

Expand Down Expand Up @@ -776,15 +775,15 @@ public void testGenerateManyToOneEntity() throws Exception
.append("<h:selectOneMenu converter=\"#{employerBean.converter}\" id=\"customerBeanCustomerEmployer\" value=\"#{customerBean.customer.employer}\">")
.append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("<f:selectItem/>").append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("<f:selectItems itemLabel=\"Employer id : #{_item.id}\" itemValue=\"#{_item}\" value=\"#{employerBean.all}\" var=\"_item\"/>").append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("<f:selectItems value=\"#{employerBean.all}\"/>").append(CRLF);
metawidget.append("\t\t\t\t\t").append("</h:selectOneMenu>").append(CRLF);
metawidget.append("\t\t\t\t\t").append("<h:message for=\"customerBeanCustomerEmployer\" styleClass=\"error\"/>")
.append(CRLF);
metawidget.append("\t\t\t\t").append("</h:panelGroup>").append(CRLF);
metawidget.append("\t\t\t\t").append("<h:outputText/>").append(CRLF);
metawidget.append("\t\t\t").append("</h:panelGrid>");

Assert.assertThat(contents, containsString(metawidget.toString()));
Assert.assertTrue(contents.contains(metawidget));

// Search

Expand Down Expand Up @@ -1006,8 +1005,7 @@ public void testGenerateOneToManyEntity() throws Exception
"value=\"#{requestScope['customerBeanCustomerGroceriesSelect']}\">")
.append(CRLF);
metawidget.append("\t\t\t\t\t\t\t").append("<f:selectItem/>").append(CRLF);
metawidget.append("\t\t\t\t\t\t\t").append("<f:selectItems itemLabel=\"Grocery id : #{_item.id}\" " +
"itemValue=\"#{_item}\" value=\"#{groceryBean.all}\" var=\"_item\"/>").append(CRLF);
metawidget.append("\t\t\t\t\t\t\t").append("<f:selectItems value=\"#{groceryBean.all}\"/>").append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("</h:selectOneMenu>").append(CRLF);
metawidget
.append("\t\t\t\t\t\t")
Expand All @@ -1025,7 +1023,7 @@ public void testGenerateOneToManyEntity() throws Exception
metawidget.append("\t\t\t\t").append("<h:outputText/>").append(CRLF);
metawidget.append("\t\t\t").append("</h:panelGrid>");

Assert.assertThat(contents, containsString(metawidget.toString()));
Assert.assertTrue(contents.contains(metawidget));
Assert.assertTrue(contents.contains("xmlns:forgeview=\"http://jboss.org/forge/view\""));

// Search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,13 +125,12 @@ public void testGenerateFromLegacyEntity() throws Exception
.append("<h:selectOneMenu converter=\"#{stateBean.converter}\" id=\"parentBeanExampleState\" value=\"#{parentBean.example.state}\">")
.append(CRLF);
metawidget.append("\t\t\t\t\t\t\t\t").append("<f:selectItem/>").append(CRLF);
metawidget.append("\t\t\t\t\t\t\t\t").append("<f:selectItems itemLabel=\"State stateId : #{_item.stateId}\" " +
"itemValue=\"#{_item}\" value=\"#{stateBean.all}\" var=\"_item\"/>").append(CRLF);
metawidget.append("\t\t\t\t\t\t\t\t").append("<f:selectItems value=\"#{stateBean.all}\"/>").append(CRLF);
metawidget.append("\t\t\t\t\t\t\t").append("</h:selectOneMenu>").append(CRLF);
metawidget.append("\t\t\t\t\t\t\t").append("<h:message for=\"parentBeanExampleState\" styleClass=\"error\"/>")
.append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("</h:panelGroup>").append(CRLF);
assertThat(contents, containsString(metawidget.toString()));
assertTrue(contents.contains(metawidget));

// Create Parent

Expand Down Expand Up @@ -165,13 +162,12 @@ public void testGenerateFromLegacyEntity() throws Exception
.append("\t\t\t\t\t")
.append("<h:selectOneMenu converter=\"#{stateBean.converter}\" id=\"parentBeanParentState\" required=\"true\" value=\"#{parentBean.parent.state}\">")
.append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("<f:selectItems itemLabel=\"State stateId : #{_item.stateId}\" " +
"itemValue=\"#{_item}\" value=\"#{stateBean.all}\" var=\"_item\"/>").append(CRLF);
metawidget.append("\t\t\t\t\t\t").append("<f:selectItems value=\"#{stateBean.all}\"/>").append(CRLF);
metawidget.append("\t\t\t\t\t").append("</h:selectOneMenu>").append(CRLF);
metawidget.append("\t\t\t\t\t").append("<h:message for=\"parentBeanParentState\" styleClass=\"error\"/>")
.append(CRLF);
metawidget.append("\t\t\t\t").append("</h:panelGroup>").append(CRLF);
assertThat(contents, containsString(metawidget.toString()));
assertTrue(contents.contains(metawidget));

// View Child

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "<h:link outcome=\"/entityWidgetBuilderTest$Bar/view\" value=\"EntityWidgetBuilderTest$Bar id : #{foo.bar.id}\">";
String result = "<h:link outcome=\"/entityWidgetBuilderTest$Bar/view\" value=\"#{foo.bar}\">";
result += "<f:param name=\"id\" value=\"#{foo.bar.id}\"/>";
result += "</h:link>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,10 +104,10 @@ public void testGenerate() throws Exception

metawidget = "\t\t\t\t\t<h:link outcome=\"/" + targetDir + "/pet/view\">\r\n";
metawidget += "\t\t\t\t\t\t<f:param name=\"id\" value=\"#{_item.id}\"/>\r\n";
metawidget += "\t\t\t\t\t\t<h:outputText id=\"owneriditemOwnerId\" value=\"Owner id : #{_item.owner.id}\"/>\r\n";
metawidget += "\t\t\t\t\t\t<h:outputText id=\"itemOwner\" value=\"#{_item.owner}\"/>\r\n";
metawidget += "\t\t\t\t\t</h:link>\r\n";

Assert.assertThat(contents, containsString(metawidget));
Assert.assertTrue(contents.contains(metawidget));

// Check create screen has h:selectBooleanCheckbox

Expand Down
Loading

0 comments on commit 913ae1e

Please sign in to comment.