<h:commandLink target=“_blank” only after validation - jsf

I used the h:commandLink target="_blank" method to get the new tab, but it shows the
validation errors in the new tab. I want it to only open the new tab if the validation is passed.
So, is there a way to validate and open a new window only if validation passes?
without using javascript or jquery.
thanks
i have tried in h:commandButton but it opens in same tab

As far as I can see you can't do without javascript, because the target attribute forces the browser to open a new tab/window immediately, followed by the server request.

Related

How can I open a dialog when the page is opened

In one of our page we have a search button that open a search dialog so that the users can search and import some data from a remote system.
Now got I new requirement that this same dialog must be showed every time the page is opened - but only when the page will be used to create a new registry, in the update mode it should be showed only if the user click the button.
I've already tried some things, I can call the dialog by MB using Primefaces engine as below:
RequestContext.getCurrentInstance().execute("dialogArmaBos.show()")
This command Works great for the button case, but I can get it working when the page opens. If I try to use in the PostConstruct nothing happens.
I tried also <f:event type="preRenderView" ... with <f:metadata ... but nothing changes too.
Is there some way to make it?
According to the fabulous PrimeFaces documentation There is a visible attribute. Quote from the docs:
visible false Boolean When enabled, dialog is visible by default.
So simply use an EL in that attribute to have it show on pageload
<p:dialog visible="#{myBean.createMode}"... >
and have a boolean field in that bean that returns true if in creation mode.
For the rest you can show/hide it with the client-side api if needed

Is it possible to save a file using client side javascript in xpages

I customize my confirmation prompt using sweetAlert, I did it, now my problem is using a customize confirmation prompt, I cannot use SSJS code but I need to save a document with a file upload.
I need Help with this thanks!
My workaround for this is an XPoages button that contains the required SSJS code for saving the document. The button resides in a hidden normal DIV (style="display:none"). When executing you CSJS just refer to the clientId of that button and fire the event click() like in
function csjsAction(){
dojo.byId("#{id:yourButton}").click();
}

Button not working after javascript call

By clicking a commandLink, I call an event on actionListener and after that, my dataGrid updates via AJAX then, onComplete, I call a javascript. It works fine on the first time but when I click the commandLink again, it does nothing.
Here's my code:
<p:commandLink id="addCompBtn" value="Add Computer" actionListener="#{coltsysLab.addComputer}" update=":organizeForm:availableComputers :organizeForm:labStat" oncomplete="getPos();"/>
My Javascript just positions each computer in a specific fixed location.
I am not sure what getPos() does; however, let's assume that it does not release event binding to the input DOM.
Try updating the commandLink as well:
<p:commandLink id="addCompBtn" value="Add Computer" actionListener="#{coltsysLab.addComputer}" update="#this,availableComputers,labStat" oncomplete="getPos();"/>
You should try removing oncomplete="getPos();" from your button and test again. If the button works fine beyond the 1st time then the problem must come from your JavaScript function. If that's the case, you should use the Developer Tools on any browser to investigate the issue. For example, on Chrome browser, right-click anywhere on the page then click Inspect Element, the Console section might help.

Displaying Extension Library Dialog box when page loads?

Is there any way to display an extension pages dialog box when my page loads?
Add a <xp:scriptBlock /> with the following client-side code as its value:
XSP.addOnLoad(function(){XSP.openDialog("#{id:dlgMessage}");});
...just be sure to place the component outside any refresh targets, or it will launch the dialog again after every partial refresh event with a target that includes it.
Try adding a dojo.addOnLoad() (in a xp:scriptblock) that displays the dialog using CSJS: XSP.openDialog()
Bruce,
You could use jQuery to 'push' the button on page load.
Try putting this clientside js code in your onClientLoad event
$(document).ready(function(){
$('a.btn').trigger('click');
});
You will have to load jQuery to use this if you don't already have it loaded. You might also be able to do the same thing with dojo.
EDIT: You might have to modify the selector (the tag and class in the parens line 2) above if not using bootstrap. I would give it a unique class so as not to 'push' any other buttons at the same time.

Intercept a4j:commandButton request

I am developing web application using A4J, Richfaces.
One of my requirement is, I need to check if the user has changed any values in the form when he is trying navigate away from the page.
I have save and cancel buttons in the page.
I am using a4j:command button for cancel functionality. Clicking on cancel button should do below things
Check if the user has modified anything in the form (this I am doing by using javascript and have a flag if user changed any values)
Display confirmation box (javascript confirm with values "Do you really want to discard the changes -- YES NO") when user changes form values
If user says YES, then submit the form using AJAX (by using A4J)
My a4j command button code is like this
<a4j:commandButton action="MyClass.cancel_action"
onclick="checkIsPageChanged()"/>
The issue here is, while using using a4j:commandButton, I cannot call the intermediate javascript function (the function which checks if user has updated any values and displays confirmation box) and then submit the request using ajax.
I have looked at the code generated by JSF and the code is like (not the exact but syntact)
<input type="button"
onclick="checkIsPageChanged();AJAX.submit('')/>
The thing is when I click on button, it is calling only checkIsPageChanged() and not calling AJAX.submit().
Any workaround for this will help me.
Thank you in advance.
Use a4j:jsFunction and call that from your a4j:commandButton when the checkIsPageChanged() returns true.
eg.
<a4j:commandButton action="MyClass.cancel_action"
onclick="if(checkIsPageChanged()) { cancel(); }"/>
<a4j:jsFunction name="cancel" action="MyClass.cancel_action"/>
To be more specific we can use:
onclick="if(!isPageChanged()) {return false}"
Returning false will not submit the request.

Resources