Skip to content

Commit

Permalink
FORGE-1787: If webroot is specified, ensure that slash is in context
Browse files Browse the repository at this point in the history
path
  • Loading branch information
gastaldi committed May 5, 2014
1 parent 429b515 commit 216c91f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
Expand Up @@ -364,7 +364,7 @@ else if (servlet instanceof ServletFacet_3_1)

result.add(ScaffoldUtil.createOrOverwrite(web.getWebResource(FORGE_STYLE_CSS),
getClass().getResourceAsStream(SCAFFOLD_FORGE_STYLE_CSS), overwrite));

result.add(ScaffoldUtil.createOrOverwrite(web.getWebResource(REMOVE_PNG),
getClass().getResourceAsStream(SCAFFOLD_REMOVE_PNG), overwrite));

Expand Down Expand Up @@ -595,7 +595,8 @@ public boolean accept(Resource<?> resource)
for (Resource<?> resource : web.getWebResource(targetDir + "/").listResources(filter))
{
HtmlOutcomeTargetLink outcomeTargetLink = new HtmlOutcomeTargetLink();
outcomeTargetLink.putAttribute("outcome", targetDir + "/" + resource.getName() + "/search");
String outcome = targetDir.isEmpty() || targetDir.startsWith("/") ? targetDir : "/" + targetDir;
outcomeTargetLink.putAttribute("outcome", outcome + "/" + resource.getName() + "/search");
outcomeTargetLink.setValue(StringUtils.uncamelCase(resource.getName()));

HtmlTag listItem = new HtmlTag("li");
Expand Down Expand Up @@ -703,7 +704,8 @@ private void resetMetaWidgets()
this.rmEntityMetawidget.setConfig(SCAFFOLD_META_WIDGET_REMOVE_ENTITY);
}

private List<Resource<?>> generateFromEntity(String targetDir, final Resource<?> template, final JavaClassSource entity,
private List<Resource<?>> generateFromEntity(String targetDir, final Resource<?> template,
final JavaClassSource entity,
final boolean overwrite)
{
resetMetaWidgets();
Expand Down
Expand Up @@ -65,10 +65,9 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;


/**
* Builds widgets with Forge-specific behaviours (such as links to other scaffolding pages).
*
*
* @author Richard Kennard
*/

Expand Down Expand Up @@ -151,7 +150,12 @@ public StaticXmlWidget buildWidget(String elementName, Map<String, String> attri
controllerName = StringUtils.decapitalize(controllerName);

HtmlOutcomeTargetLink link = new HtmlOutcomeTargetLink();
link.putAttribute("outcome", getTargetDir() + "/" + controllerName + "/view");
String outcome = getTargetDir();
if (!outcome.isEmpty() && !outcome.startsWith("/"))
{
outcome = "/" + outcome;
}
link.putAttribute("outcome", outcome + "/" + controllerName + "/view");

StandardBindingProcessor bindingProcessor = metawidget.getWidgetProcessor(StandardBindingProcessor.class);

Expand All @@ -161,7 +165,8 @@ public StaticXmlWidget buildWidget(String elementName, Map<String, String> attri
(StaticUIMetawidget) metawidget);
}

link.putAttribute("rendered", StaticFacesUtils.wrapExpression("!empty " + StaticFacesUtils.unwrapExpression(link.getValue())));
link.putAttribute("rendered",
StaticFacesUtils.wrapExpression("!empty " + StaticFacesUtils.unwrapExpression(link.getValue())));

String reverseKey = "id";
if (attributes.containsKey(REVERSE_PRIMARY_KEY))
Expand All @@ -173,7 +178,8 @@ public StaticXmlWidget buildWidget(String elementName, Map<String, String> attri
param.putAttribute("name", "id");
param.putAttribute(
"value",
StaticFacesUtils.wrapExpression(StaticFacesUtils.unwrapExpression(link.getValue()) + StringUtils.SEPARATOR_DOT_CHAR
StaticFacesUtils.wrapExpression(StaticFacesUtils.unwrapExpression(link.getValue())
+ StringUtils.SEPARATOR_DOT_CHAR
+ reverseKey));
link.getChildren().add(param);

Expand Down Expand Up @@ -209,11 +215,12 @@ public StaticXmlWidget buildWidget(String elementName, Map<String, String> attri
}

// Change the labels of the f:selectItems in the h:select widget (when FACES_LOOKUP is present)
String facesLookup = attributes.get( FACES_LOOKUP );
String facesLookup = attributes.get(FACES_LOOKUP);

if ( facesLookup != null && !"".equals( facesLookup ) ) {
if (facesLookup != null && !"".equals(facesLookup))
{
HtmlSelectOneMenu select = new HtmlSelectOneMenu();
addSelectItems( select, facesLookup, attributes );
addSelectItems(select, facesLookup, attributes);
return select;
}

Expand Down Expand Up @@ -598,7 +605,7 @@ 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))
if (columnAttributes.containsKey(FACES_LOOKUP) && columnAttributes.containsKey(REVERSE_PRIMARY_KEY))
{
StaticHtmlMetawidget output = (StaticHtmlMetawidget) link.getChildren().get(1);
String displayExpression = "forgeview:display(" + dataTable.getAttribute("var")
Expand Down Expand Up @@ -667,16 +674,18 @@ 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 ) {
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 );
if (WidgetBuilderUtils.needsEmptyLookupItem(attributes))
{
addSelectItem(select, null, null);
}

// Add the select items
Expand All @@ -694,7 +703,7 @@ protected void addSelectItems( HtmlSelectOneMenu select, String valueExpression,
selectItems.putAttribute("itemLabel", StaticFacesUtils.wrapExpression(displayExpression));
}

select.getChildren().add( selectItems );
select.getChildren().add(selectItems);
}

//
Expand All @@ -719,12 +728,13 @@ private String getTargetDir()
return target;
}

private void addSelectItem( HtmlSelectOneMenu select, String value, String label ) {
private void addSelectItem(HtmlSelectOneMenu select, String value, String label)
{

SelectItem selectItem = new SelectItem();
selectItem.putAttribute( "itemLabel", label );
selectItem.putAttribute( "itemValue", value );
selectItem.putAttribute("itemLabel", label);
selectItem.putAttribute("itemValue", value);

select.getChildren().add( selectItem );
select.getChildren().add(selectItem);
}
}

0 comments on commit 216c91f

Please sign in to comment.