I am trying to popup a html page from wicket application. The html page will not have corresponding .java file. The page is static html page.
I tried to pop up html page which is a part of wicket application using following logic:
PopupSettings popupSettings =
new PopupSettings(PopupSettings.RESIZABLE | PopupSettings.SCROLLBARS).setHeight(500).setWidth(700);
Link link = new Link("link") {
#Override
public void onClick() {
System.out.println("clicked");
setResponsePage(PopupPage.class);
}
};
link.setPopupSettings(popupSettings);
add(link);
But for this to work i need to have html page with its java page. But in my requirement I have fixed html page (say test.html) and I want to pop up it.
Also I want to popup this html page on click of button. But I didn't get any method like setPopupSettings() for button. Can someone tell me the way in which I can implement it for a button?
The easiest way i can think of is to add button in your html:
<button type="button" wicket:id="popupButton">Pop</button>
And in the code you can do something like this:
add(new WebMarkupContainer("popupButton").add(AttributeAppender.append("onclick",
"window.open('test.html', 'popup', 'width=500,height=700,scrollbars=yes');")));
Or if you want it to be more dynamic, you can use a model:
add(new WebMarkupContainer("popupButton").add(AttributeAppender.append("onclick",
new AbstractReadOnlyModel<String>() {
#Override
public String getObject() {
return "window.open('test.html', 'popup', 'width=500,height=700,scrollbars=yes');";
}
})));
Related
Hello fellow GWT folks.
In my usage of GWT, I'm having an issue with a FocusPanel not handling the clickEvent that is added to it. I don't do GWT the standard way, ie building the GUI with UI binder or pure java code widgets. My host GWT HTML file is 1 large file that has div tags that represent the 'pages' of content. I use GWT to control the DOM.
I have this HTML that I'm importing as the contents of the FocusPanel.
<div id="editCardsResponses">
<div id="editCardsSuccess" class="success-box clickable">
<span id="editCardsSuccessLabel">Your card was successfully deleted/edit/added.</span>
<span class="glyphicon glyphicon-remove"></span>
</div>
...
</div>
Here's the Code...
RootPanel editCardsSuccess = RootPanel.get("editCardsSuccess");
FocusPanel editCardsSuccessPanel = new FocusPanel(editCardsSuccess);
editCardsSuccessPanel.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
hideWidget(editCardsSuccessPanel);
}
});
This didn't work until I did this...
final HTMLPanel editCardsSuccess = view.getEditCardsSuccess();
editCardsSuccess.addDomHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
hideWidget(editCardsSuccess);
}
}, ClickEvent.getType());
I even tried adding the FocusPanel to the parent DIV, thinking that the FocusPanel wasn't attached to the DOM, but that also didn't work.
RootPanel.get("editCardsResponses").add(editCardsSuccessPanel);
I would like to use the FocusPanel, as GWT wants to add a hidden input the DOM, in addtion to the element it wraps. I assume the hidden input handles some cross browser issue that I might lose if I just use the domHandler method.
Can anyone help explain why the FocusPanel.ClickHandler wouldn't be taking effect, but an attached domHandler would?
If DOM attachment is the problem, Is there a way to re-attach elements/widgets that were detached?
If I go with the domHandler way... what compatibility do I loose by not getting the hidden input that the GWT FocusPanel widget provides?
Add DOM ONCLICK handler event on the Element.
sample code:
final Element desc = RootPanel.get("editCardsSuccess").getElement();
DOM.sinkEvents((com.google.gwt.user.client.Element) desc, Event.ONCLICK);
DOM.setEventListener((com.google.gwt.user.client.Element) desc, new EventListener() {
#Override
public void onBrowserEvent(Event e) {
switch (DOM.eventGetType(e)) {
case Event.ONCLICK:
System.out.println("click");
break;
}
}
});
There is nothing wrong with adding a DOM handler the way you described. It will work across all browsers.
I have two jsp pages. The first one with "Hello World" text message. The second JSP page with "Hello JSP" text message. Now in my third JSP page I have two buttons button1 and button 2. Can someone suggest some code snippet which I can use to call the first JSP page on click of the button 1 and **on click of button 2 , it should call the second JSP page?
On click of the first button only the first jsp page value should be displayed i.e Hello World and on click of the second button only second page value should be displayed i.e Hello JSP.
Kindly suggest the approach to achieve this.
Kind regards
Just put some javascript that sets the window location to the page you want to display as the script of the button
<input type="button"
value="Button 1"
onclick="window.location.assign('HelloWorld.jsp')">
<input type="button"
value="Button 2"
onclick="window.location.assign('HelloWorldJSP.jsp')">
Put the correct addresses in there for your JSP pages. This will cause the browser to reload from the address of the JSP page, and that JSP will 'fill the browser' with its contents.
JavaScript using AJAX
<script>
function loadXMLDoc(page)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",page,true);
xmlhttp.send();
}
</script>
Code For Buttons
<button type=button onclick='loadXMLDoc("page_one.jsp")'>Button 1</button>
<button type=button onclick='loadXMLDoc("page_two.jsp")'>Button 2</button>
And inside body
<div id="myDiv"></div>
It does not make a lot of sense to "call" a JSP page. Are you trying to submit a different set of information based on which button you click (I think so)? And if you submit different information, what do you want to do with the result?
The simplest thing - have two forms that get submitted to different URLs. Clicking on button 1 should submit it to the URL of first JSP, clicking on button 2 should submit it to the URL of the second JSP. Or these could be simple GET links. If the three JSPs, a.jsp, button1.jsp, and button2.jsp are in the same (and accessible through direct web URL) directory , a.jsp could be -
Click for Hello World
Click for Hello JSP
Content of button1.jsp and button2.jsp is trivial.
Keep in mind that in general, you should not be submitting directly to a JSP URL. May I also suggest that you spend some time reading up on how JSP, servlets and HTTP work in general and in conjunction with each other?
Always try your practices to forward via the servlets, and below is one of the implementation. Set both buttons as a submit type.
Use hidden textbox for storing the clicked id/name of button inside of the form.
$("#button1").click(function() {
var buttonId = $("#buttonId").val('button1');
return true;
});
$("#button2").click(function() {
var buttonId = $("#buttonId").val('button2');
return true;
});
Submit the form and get the value of buttonId in your servlet like this,
String clickedButton = request.getParameter("hidden_name");
finally forward the page to whatever you like this,
if(clickedButton.equals("button1")){
// do your stuff
}else if(clickedButton.equals("button2")){
// do your stuff
}
I have a simple application structure that will contain three composites at any one time - my header, footer and content composites. The composites are laid out in the follow manner.
<body>
<div id="header">
<div id="content">
<div id="footer">
</body>
The composites are assigned to the three <div>'s in my EntryPoint. The EntryPoint also contains a History Handler as follows.
History.addValueChangeHandler(new ValueChangeHandler<String>() {
#Override
public void onValueChange(ValueChangeEvent<String> event) {
String historyToken = event.getValue();
if(historyToken.isEmpty()) {
parseTokens();
ContentContainer.INSTANCE.setContent(new IndexScreen());
}
else if(historyToken.equalsIgnoreCase("registration")) {
ContentContainer.INSTANCE.setContent(new RegisterScreen());
}
else if(historyToken.equalsIgnoreCase("login")) {
ContentContainer.INSTANCE.setContent(new LoginScreen());
}
}
});
History.fireCurrentHistoryState();
In my Composites, I have several ClickEvent handlers that look similar to the following.
#UiHandler("registerLink")
public void handleClick(ClickEvent event) {
ContentContainer.INSTANCE.setContent(new RegisterScreen());
History.newItem("registration", true);
}
This registers the history very nicely. It also brings me to the appropriate pages when I click the back button. However, it has the very odd effect of focusing the browser on the content composite, with the effect of the browser being scrolled to the bottom. It's not a deal breaker but it kind of breaks the user experience a little. (Do let me know if the explanation isn't clear, I'll add images)
What exactly is causing this and how can I fix it?
GWT history tokens work with the hash # token. In html this was originally intended to use the browser to focus on a specific part of the page, if an element has a name or id with the string after the # token. Could it be you have an id matching your history token?
Also in you handleClick you call setContent. But if I'm correct the call after it triggers a change event and will end up in the onValueChange, which also calls the setContent. So it looks like you are calling setContent twice here.
I am using SWT browser in my application
I have edited SWT source code according to my need, Now I want a feature of view web page source code by click on button
I have managed "Go to Home page " like this
public void goHome() {
int[] rgdispid = auto.getIDsOfNames(new String[]{"GoHome"});
int dispIdMember = rgdispid[0];
auto.invoke(dispIdMember);
}
I want to know if there is any string for "view page source" like "GoHome"
Or is there any other way to do this.
Thanks in advance
Based on the API of the SWT Browser, looks like you can get the HTML of the page by calling the getText() method.
Eclipse SWT Browser API
I am trying to make a application which would connect to a site with the login provided by the user. I don't have any experience in interacting with websites in Java so I googled some and found hmtlunit to fit my needs.
But I ran into an error when trying to click the submit button for the login form:
public static boolean attempt_login(String username, String password) throws ElementNotFoundException, IOException {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
webClient.setJavaScriptEnabled(false);
webClient.setThrowExceptionOnScriptError(false);
webClient.setRefreshHandler(new RefreshHandler() {
public void handleRefresh(Page page, URL url, int arg) throws IOException {
System.out.println("handleRefresh");
}
});
HtmlPage page = (HtmlPage) webClient.getPage(Config.LOGIN_PAGE);
List<HtmlForm> forms = page.getForms();
HtmlForm form = null;
for(HtmlForm f : forms){
if(f.getId().equals("login_form")){
form = f;
}
}
if(form == null){
throw new NullPointerException("Could not find form!");
}
form.getInputByName("username").setValueAttribute(username);
form.getInputByName("password").setValueAttribute(password);
page = (HtmlPage) form.getInputByValue("Login Now!").click();
System.out.println(page.asText());
return false;}
Somehow it fails to find the submitButton to login
com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[input] attributeName=[value] attributeValue=[Login Now!]
at com.gargoylesoftware.htmlunit.html.HtmlForm.getInputByValue(HtmlForm.java:737)
at domain.Helper.attempt_login(Helper.java:41)
at TesterStartUp.main(TesterStartUp.java:15)
The html source code:
<button type="submit" value="Login Now!" onmouseover="this.style.backgroundPosition='bottom';" onmouseout="this.style.backgroundPosition='top';" onclick="return SetFocus();">Login Now!</button>
When I googled for a solution, I found something about disabling javascript would help. So i told the webclient to disabled it ( webClient.setJavaScriptEnabled(false);) but still had the exception.
At first I had the same issue with trying to select the form ("login_form") but there was a method where I could get the list of all forms and then just see if one matched the list. I couldn't find a way around it for the submit button, So I hoped someone else knows a solution to this problem.
Thanks in advance,
Sir Troll
The HtmlUnit getInputByValue() method operating on a <form> will only return types of HtmlInput, and the only Input Button type -- HtmlButtonInput -- represents <input type="button"> and NOT <button>. You will need to change your HTML or use a different HtmlUnit method call.
I had same kind of issue that I resolved myself:
When you try to login using html unit first check if login box is appearing onclick using jquery or not. If login box/div is appearing after click a button then you need to refresh the page (web client) to access new input elements
HtmlPage page = webClient.getPage("https://www.yourwebsite.com/#");
HtmlAnchor link=page.getElementByName("link");
link.click();
page.refresh();
If your site has a button instead of anchor link change it for html button, After refreshing may you can found the element.
Hope it will help and solve your issue