Spotfire Redirecting to home after link click - redirect

Ask: Have a button that when clicked downloads a file from a folder on the server and remains on the current page.
Current state and problem: I have a CustomWizardPromptControlPage that writes a simple button to the HTMLTextWriter. The onclick event for the button fires off a window.open(urlToDocument, '_blank'). By doing the button with the onclick it does actually allow me to download the file, however the parent page redirects to the home page.
Already tried: href - didn't download the file and redirected me to the home page. form submit - didn't do anything.
If anyone can give me some insight as to why Spotfire does this and what I can do to stop it from happening it would be greatly appreciated
--Follow up with working code sample for comments request
namespace ACompanyName.SpotFire.ExportWithFilters
{
public class ExportWithFiltersWebPromptControl : CustomWizardPromptControl
{
public ExportWithFiltersWebPromptControl(ExportWithFiltersFileSettings settings)
{
this.AddPage(new ExportWithFiltersPage(settings));
}
private class ExportWithFiltersPage : CustomWizardPromptControlPage
{
private readonly ExportWithFiltersFileSettings _settings;
public ExportWithFiltersPage(ExportWithFiltersFileSettings settings) : base("Export with Filters")
{
_settings = settings;
}
protected override void OnGetContentsCore(HtmlTextWriter writer)
{
var domain = "https://dev.AURL.com";
var filename = _settings.ExportWithFiltersFileInfo.Name;
var fullFilePath = string.Format("{0}/{1}/{2}", domain, "Exports", filename);
writer.WriteLine("Download Export with Filters", fullFilePath);
}
protected override void OnGetScriptsCore(StringBuilder builder)
{
}
protected override void OnLeavePageCore(FormData data)
{
}
protected override bool OnValidatePromptCore(FormData data)
{
return true;
}
}
}
}

Turned out that Spotfire didn't like putting <button> into the page. Swapped it out with an hyperlink with a target of blank and it worked like a charm. If a button is still desired, stylized div should do the trick.

Related

Maintain navigation history in WebView

In my app I have main activity and child activities. An action on main activity opens a child activity. Each child activity loads web page that have various urls all pointing to server locations.
I am able to navigate to all the urls but when I press back, I am not redirected to the previous page. Instead it exists and brings me to main activity. The back button action should navigate to last url location. How to do that?
You need to add each url to a List object and then use that object to navigate back.
private LinkedList<String> navigationHistory;
#Override
protected void onCreate(Bundle savedInstanceState) {
....
mWebView.setWebViewClient(new MyWebViewClient());
....
}
#Override
public void onBackPressed() {
if (navigationHistory.size() > 0) // Check if the url is empty
{
navigationHistory.removeLast(); // Remove the last url
if (navigationHistory.size() > 0) {
// Load the last page
mWebView.loadUrl(navigationHistory.getLast());
} else {
super.onBackPressed();
}
} else {
super.onBackPressed();
}
}
private class MyWebViewClient extends WebViewClient {
#Override
public void onPageFinished(WebView view, String url) {
if (!navigationHistory.contains(url)) // Check for duplicate urls
navigationHistory.add(url); // add each loading url to List
super.onPageFinished(view, url);
}
}

Link to last version of stateful page

I have a number of stateful pages with some state for each page. For example each page has a form that was submitted.
How can I organize a menu with links to last versions of these stateful pages? Should I store anywhere (may be in the session) reference to appropriate object for each page? If I use
onClick() { setResponsePage(MyPage.class); }
than I lose the previous state of the page. I want to link to last state of the page.
Each time the page is rendered store the page's id in the session.
int pageId = pageInstance.getPageId();
A list or stack data structure could be used to hold the identifiers.
You can implement the navigation menu using a repeater (RepeatingView or such) that creates a new link for each page id in the session.
In the link's click handler you can redirect the user as follows:
Page pageInstance = (Page) new PageProvider(pageId, null).getPageInstance();
setResponsePage(pageInstance);
pageId = this.getPageId(); // get current version of lets say a HomePage
//OnClick for Link
public void onClick()
{
WebPage homePageInstance =
(WebPage) new PageProvider(HomePage.pageId, null).getPageInstance();
setResponsePage(homePageInstance);
}
});
I make it passing int previousId parameter via constructor :
#MountPath(value = "editSomethingPage")
public class TestPage extends WebPage {
int previousPageId = 0;
public TestPage(int previousPage) {
super();
this.previousPageId = previousPage;
}
#Override
protected void onInitialize() {
super.onInitialize();
add(new Link("goBack") {
#Override
public void onClick() {
if (previousPageId != 0) {
setResponsePage((Page) AuthenticatedWebSession.get().getPageManager().getPage(previousPageId));
} else {
setResponsePage(PreviousPage.class);
}
}
});
}
}
It prevents creation of new page instance and keeps all states of page made by user.

How to find out component-path

I use junit to assert the existing of wicket components:
wicketTester.assertComponent("dev1WicketId:dev2WicketId:formWicketId", Form.class);
This works for some forms. For complex structure, it is defficult to find out the path of the form by searching all html files. Is there any method how to find out the path easy?
If you have the component you can call #getPageRelativePath(). E.g.
// Supposing c is a component that has been added to the page.
// Returns the full path to the component relative to the page, e.g., "path:to:label"
String pathToComponent = c.getPageRelativePath();
You can get the children of a markup container by using the visitChildren() method. The following example shows how to get all the Forms from a page.
List<Form> list = new ArrayList<Form<?>>();
Page page = wicketTester.getLastRenderedPage();
for (Form form : page.visitChildren(Form.class)) {
list.add(form);
}
An easy way to get those is to call getDebugSettings().setOutputComponentPath(true); when initializing your application. This will make Wicket to output these paths to the generated HTML as an attribute on every component-bound tag.
It's recommended to only enable this on debug mode, though:
public class WicketApplication extends WebApplication {
#Override
public void init() {
super.init();
if (getConfigurationType() == RuntimeConfigurationType.DEVELOPMENT) {
getDebugSettings().setOutputComponentPath(true);
}
}
}
Extending the RJo's answer.
It seems that the method page.visitChildren(<Class>) is deprecated (Wicket 6), so with an IVisitor it can be :
protected String findPathComponentOnLastRenderedPage(final String idComponent) {
final Page page = wicketTester.getLastRenderedPage();
return page.visitChildren(Component.class, new IVisitor<Component, String>() {
#Override
public void component(final Component component, final IVisit<String> visit) {
if (component.getId().equals(idComponent)) {
visit.stop(component.getPageRelativePath());
}
}
});
}

Wicket model window throw error when first open in new tab by right click and then click on model window link

When i am going to one page(A) to another page(B) using Ajax link URL show like ...?wicket:interface=:58::::#
On B page i have a link for open model window.when we direct click on link of model window its working fine but when first open link in new Tab by right click and then click on model window link its throwing an error.
I am using setResponsePage( new B(variable)) for come to another page.when i am using setResponsePage(B.class) instead of setResponsePage( new B(variable)) its working fine.
Note : I don't want to use pageparameter with bookmarkable and setResponsePage.
Error is :
org.apache.wicket.WicketRuntimeException: component listForm:group:issueList:1:editStatus not found on page com.B[id = 18], listener interface = [RequestListenerInterface name=IBehaviorListener, method=public abstract void org.apache.wicket.behavior.IBehaviorListener.onRequest()]
org.apache.wicket.protocol.http.request.InvalidUrlException: org.apache.wicket.WicketRuntimeException: component listForm:group:issueList:1:editStatus not found on page com.B[id = 18], listener interface = [RequestListenerInterface name=IBehaviorListener, method=public abstract void org.apache.wicket.behavior.IBehaviorListener.onRequest()]
at ...........................
... 27 more
"editStatus" is a link name on model window.
Code that i am using Class A
class A extends WebPage {
Link<String> escalated = new Link<String>("escalated") {
public void onClick() {
setResponsePage(new B(Variables));
} };
}
class B extends WebPage {
public B(variables..) {
}
final ModalWindow model = new ModalWindow("UpdateModel");
model.setContent(new C(model,variables,model.getContentId()));
item.add(new AjaxLink<Void>(**"editStatus"**) {
public void onClick(AjaxRequestTarget target) {
model.show(target);
}
}.add(new Image("edit_icon", "image/edit.png")));
}
}
class C extends Panel {
public C(.....) {
}
}
I have solved this issue.Error was relating with state of wicket component.
Use StatelessLink instead of Link.
correct code :
class A extends WebPage {
StatelessLink escalated = new StatelessLink("escalated") {
public void onClick() {
setResponsePage(new B(Variables));
} };
}
it would also removed "...?wicket:interface=:58::::#" from url.
when we used Link,AjaxLink it would maintain state.so when we open any link in new tab it would changed state on server side(change ids of component) but on client side it would remain same. so when we click any link on same page there are no information of updated ids and it would have thrown an error.

How to implement content assist's documentation popup in Eclipse RCP

I have implemented my own editor and added a code completion functionality to it. My content assistant is registered in source viewer configuration like this:
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
if (assistant == null) {
assistant = new ContentAssistant();
assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
assistant.setContentAssistProcessor(getMyAssistProcessor(),
MyPartitionScanner.DESIRED_PARTITION_FOR_MY_ASSISTANCE);
assistant.enableAutoActivation(true);
assistant.setAutoActivationDelay(500);
assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
}
return assistant;
}
When I press Ctrl + SPACE inside the desired partition, the completion popup appears and works as expected.
And here's my question.. How do I implement/register a documentation popup that appears next to completion popup? (For example in java editor)
Well,
I'll answear the question myself ;-)
You have to add this line
assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
to the configuration above. Then when creating CompletionProposals, the eighth (last) parameter called additionalProposalInfo of the constructor is the text, which will be shown in the documentation popup.
new CompletionProposal(replacementString,
replacementOffset,
replacementLength,
cursorPosition,
image,
displayString,
contextInformation,
additionalProposalInfo);
More information about can be found here.
Easy, isn't it.. if you know how to do it ;)
For the styled information box (just like in JDT).
The DefaultInformationControl instance need to received a HTMLTextPresenter.
import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
public class MyConfiguration extends SourceViewerConfiguration {
[...]
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
if (assistant == null) {
[...]
assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
}
return assistant;
}
#Override
public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent,new HTMLTextPresenter(false));
}
};
}
}
Proposals can then use basic HTML tags in the string from method getAdditionalProposalInfo().
public class MyProposal implements ICompletionProposal {
[...]
#Override
public String getAdditionalProposalInfo() {
return "<b>Hello</b> <i>World</i>!";
}
}