JasperReports on new tab - java

I'm a newbie here and I would like to consult something regarding JasperReports and servlets.
I have a form called appform.jsp which is an application page.
What I want to achieve is that when I click the Submit button of the application page, a new tab will open then a PDF file will be displayed.
The submit button calls the sevlet that will generate the pdf then the PDF will be displayed in a new tab.
I wonder if this line is correct
<input type="submit" value="Submit" onClick="validateForm(); openinnewtab('<%=request.getContextPath()+"/readFields"%>')" >
validateForm() is just a javascript checker for empty fields, readFields is my servlet and my form's onsubmit tag is on return false;
Thank you.

give target="_blank" in the form tag. some browsers open a page some a tag . you can also try target="_new" using this you can easily open new tab

Related

How to redirect to other page after .pdf exported in Primefaces?

I want to archive a "Close and Print" function, where after closing the invoice it will be exported right away as .pdf (this is the "print" in the system) and the user will be redirected to the invoice list.
This is the command button I tried to create:
<p:menuitem oncomplete="javascript:saved=true"
action="#{myController.setFinalAndPrint}"
disabled="#{myController.selected.status == 2}"
value="#{bundle.Finalize} & #{bundle.Print}"
update=":center,:growl"
icon="ui-icon-check"
ajax="false"
class=""/>
This is the setFinalAndPrint method in my controller:
public void setFinalAndPrint() {
setFinal();
breadCrumb.goToInvoice();
reportForm();
}
setFinal is working fine, reportForm is also working fine, Chrome is getting the popup to save the .pdf but the page isn't redirected...
Is it possible to export a .pdf and navigate somehow to other page?
Thank you!
EDIT.:
Tried with:
oncomplete="location.reload( true );"
sadly this doesn't work as well :(
Found out myself:
use WidgetVar on the button and use jQuery like this:
<script type="text/javascript">
jQuery(document).ready(function(){
PF('myWidgetVar').jq.click();
})
</script>

Why i can't use request.getParameter in my form

i have a question about using request.getParameter(), i knew that it can use to post the value using request.getParameter, Is it necessary match request.getParameter and <input>???
My original code in HTML:
<INPUT type=submit name="submit" value="download">
In JSP:
String start = request.getParameter("submit");
Now I want to change a button and use div
div name="submit"id="submit" class="btnStyleFunc"
onclick="document.body.style.cursor='wait';this.disabled='true';
document.getElementById('form').submit();">
But it doesn't work, anyone can help me ?
Now i use the method below, but another problem is raised...the action does not stop...
String start = request.getParameter("submit1");
<input type=hidden name=submit1 value=download>
<div class="btnStyleFunc" onclick="document.body.style.cursor='wait';
this.disabled='true';document.getElementById('form').submit();">
Does anyone know what the problem is ?
A clicked submit button is a successful form control and its name/value pair will be submitted to the server in the form data.
If you submit a form with JavaScript, there is no clicked submit button, so it won't appear in the data. A div cannot have a name and is not a form control anyway — it isn't a submit button, even if it triggers JavaScript that submits the form.
Using a div with JavaScript also breaks the form for:
Anyone not using a mouse/trackpad/etc to navigate the page (a div won't get the focus when tabbing through interactive elements)
Anyone with JavaScript disabled
Anyone using a screen reader in forms mode (div elements are not form controls).
Use a real submit button instead.

Update iframe in container page on submit of <form> in container page

I have a main html page which contains an IFRAME.
I have a server side jsp code that is displayed with some default values inside the IFRAME for the first time.
Whenever a person tries to use a search button in the main page the results are displayed in the IFRAME updating its content.
I have a servlet that does the calculation on the searched data and updates the IFRAME content.
The problem:
I have used the sendRedirect method in servlet to refresh the IFRAME but to no avail.
The string I am passing to sendRedirect is /results.jsp?search=value&size=1 (jsp to be displayed in iframe).
The servlet does its calculation work properly but opens a new page in place of the mainpage: not a desired output.
The mainpage with its interface should remain there, only the IFRAME should refresh.
My question:
Is this the correct method to refresh an iframe? If not kindly tell me what should I use to update my iframe (jsp) via servlet.
PS: Please forgive the absurdity of the quesion if any. I am new to the jsp-servlet.
Any help is much appreciated
When you do a redirect using response.sendRedirect() method, the actual 'frame' where the servlet was called will be modified. That frame can be the entire page, or an iframe, or even the legacy frames used in javadocs.
As #Jake223 said, set the target attribute to the iframe name in the form:
If you are using a form to submit the information, then you do something like this:
<iframe name="resultframe"></iframe>
<form action=[path to servlet] target="resultframe">
<input type="text" name="searchq"/>
<input type="submit" value="search"/>
</form>
If you are using javascript to create the iframe, then use the src attribute of the iframe:
<iframe src=[path to servlet]?[request params]></iframe>
If the search mechanism is an HTML form, you can set the target attribute of the form to the name of the iframe in question. See W3Schools's page on this for more details.

Change default button name of Browse in ace:FileEntry

I am trying to use ace:fileEntry component to upload images to my database but now, I want to change the name of the button "Browse" in my case "Seleccionar archivo" but I don't know where that name is stored.
<ace:fileEntry id="ImageFileEntry"
fileEntryListener="#{usuarioBean.sampleListener}"
useSessionSubdir="true">
</ace:fileEntry>
<h:commandButton id="submit" value="subir"></h:commandButton>
I attached a screenshot
http://i.stack.imgur.com/8b817.png
thanks
The ace:fileEntry will render an <input type="file"> element, the text on this button is always defined by your browser/the language of your browser. It is not possible to change it, have a look at this post for more information and some workarounds: Change default text in input type="file"?

How to manipulate the history of the web page?

Here is my what I have
<div id=A></div>
<div id=B></div>
<input type="button" value="ChangeA" onClick="createTableA();">
<input type="button" value="ChangeB" onClick="createTableB();">
So in my jsp file, I use javascript and jQuery to manipulate the content of those two div dynamically. For example, if I click on changeA, the function createTableA() will dynamically manipulate <div id=A></div> and append a table to it. So my question is if I click on changeA, then click changeB, how can I manipulate the history so that if I click the back button, I go back to the content of Table A
I've been using the jQuery History plugin for just this sort of thing and it's been working pretty well for me.
Each "page" is referenced by a hash in your URL. That way "changing pages" doesn't refresh the page, but does store the page state in history and allow for bookmarking.
EDIT
I'll expand on the example given in the link to apply more for your situation.
function loadTable(hash)
{
if(hash == "ChangeA")
createTableA();
if(hash == "ChangeB")
createTableB();
}
$(document).ready(function() {
$.history.init(loadTable);
$("input[id^='Change']").click(function(){
$.history.load(this.attr('value'));
return false;
});
});
What the above code does is sets an event handler on all input tags whose id begins with 'Change' so that when those buttons are clicked, loadTable is called. If you change your buttons to look like this:
<input type="button" id="ChangeA" value="ChangeA">
<input type="button" id="ChangeB" value="ChangeB">
clicking button A will put this http://www.example.com/yourpage.html#ChangeA in the address bar and load table A, also adding that table change to the browser history.
The native 'location' object has a 'hash' property that you could use for navigation in AJAX/JS applications.
You could use History plugin or Address plugin.
Address plugin gives more flexibility and recommended for more complex apps.
You should check out Ben Alman's Back Button and Query Library Great api for mucking with the browser history and has some great examples to get you started.
YUI also has a browser history manager: YUI3: http://developer.yahoo.com/yui/3/history/ or YUI 2: http://developer.yahoo.com/yui/history/

Categories

Resources