Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Improve render URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed May 15, 2013
1 parent eedd2f7 commit 3aaf287
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
8 changes: 8 additions & 0 deletions portal/src/main/java/org/gatein/portal/page/PageState.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public Phase.View.Dispatch getDispatch() {
return view;
}

Phase.View.Dispatch getDispatch(String action, String target) {
Phase.View.Dispatch view = Controller_.index(path, action, null, null, null);
for (WindowState w : windows) {
w.encode(view);
}
return view;
}

@Override
public NodeContext<NodeState, ElementState> getContext(NodeState node) {
return node.context;
Expand Down
56 changes: 38 additions & 18 deletions portal/src/main/java/org/gatein/portal/page/WindowState.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void encodeQueryParamValue(CharSequence s, Appendable appendable) throws
/** The related portlet lazy loaded. */
private Portlet portlet;

public WindowState(NodeState node, PageState page) {
WindowState(NodeState node, PageState page) {

//
this.page = page;
Expand All @@ -116,13 +116,24 @@ public WindowState(NodeState node, PageState page) {
this.portlet = null;
}

public WindowState(WindowState that, PageState page) {
WindowState(WindowState that, PageState page) {

//
Map<String, String[]> parameters;
if (that.parameters.isEmpty()) {
parameters = NO_PARAMETERS;
} else {
parameters = new HashMap<String, String[]>(that.parameters);
for (Map.Entry<String, String[]> parameter : parameters.entrySet()) {
parameter.setValue(parameter.getValue().clone());
}
}

//
this.page = page;
this.name = that.name;
this.id = that.id;
this.parameters = NO_PARAMETERS;
this.parameters = parameters;
this.windowState = org.gatein.pc.api.WindowState.NORMAL;
this.mode = Mode.VIEW;
this.portlet = null;
Expand Down Expand Up @@ -195,6 +206,19 @@ public Portlet getPortlet() {
return portlet;
}

private Phase.View.Dispatch getDispatch(String action, String windowState, String mode, Map<String, String[]> parameters) {
Phase.View.Dispatch view = Controller_.index(page.path, action, name, windowState, mode);
for (WindowState w : page.windows) {
w.encode(view);
}
if (parameters != null) {
for (Map.Entry<String, String[]> parameter : parameters.entrySet()) {
view.setParameter(parameter.getKey(), parameter.getValue());
}
}
return view;
}

@Override
public MediaType getResponseContentType() {
return MediaType.TEXT_HTML;
Expand All @@ -220,30 +244,26 @@ public String renderURL(ContainerURL containerURL, URLFormat format) {
}
if (containerURL instanceof RenderURL) {
RenderURL renderURL = (RenderURL) containerURL;
view = Controller_.index(page.path, null, name, targetWindowState, targetMode);
WindowState copy = new PageState(page).get(name);
ParametersStateString ns = (ParametersStateString) renderURL.getNavigationalState();
if (ns != null) {
for (Map.Entry<String, String[]> parameter : ns.getParameters().entrySet()) {
view.setParameter(parameter.getKey(), parameter.getValue());
}
copy.parameters = ns.getParameters();
}
if (windowState != null) {
copy.windowState = windowState;
}
if (mode != null) {
copy.mode = mode;
}
view = copy.page.getDispatch();
} else if (containerURL instanceof ActionURL) {
ActionURL actionURL = (ActionURL) containerURL;
view = Controller_.index(page.path, "action", name, targetWindowState, targetMode);
ParametersStateString is = (ParametersStateString) actionURL.getInteractionState();
if (is != null) {
for (Map.Entry<String, String[]> parameter : is.getParameters().entrySet()) {
view.setParameter(parameter.getKey(), parameter.getValue());
}
}
Map<String, String[]> parameters = is != null ? is.getParameters() : null;
view = getDispatch("action", targetWindowState, targetMode, parameters);
} else {
throw new UnsupportedOperationException("Todo");
}
for (WindowState other : page.windows) {
if (other != this) {
other.encode(view);
}
}
return view.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static WebArchive createPortal() {
public void testHello() {
String url = deploymentURL.toString() + "page1";
driver.get(url);
System.out.println("driver.getPageSource() = " + driver.getPageSource());
WebElement click = driver.findElement(By.id("click"));
foo = null;
bar = null;
Expand Down

0 comments on commit 3aaf287

Please sign in to comment.