So as in the picture i have a share, save and apply button.
image
i've read some articles about the copy to clipboard but it seems only works with a button (?), As what i used is a command link ,since i wanted a transparent button so i used a command link instead of command button(i read this from another articles).
This is my xhtml file
<h:commandLink id="share">
<i class="fa fa-share-alt" style="color: black"/>
<h:outputText value=" Share" escape="false" style="color: black;"/>
</h:commandLink>
<pe:clipboard id="clipboardbtn" trigger="share" action="copy" text="http://localhost:8082/index.xhtml">
<p:ajax event="success" listener="#{clipboardController.successListener}" />
<p:ajax event="error" listener="#{clipboardController.errorListener}" />
</pe:clipboard>
This is my controller
public void successListener(final ClipboardSuccessEvent successEvent) {
final FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Success",
"Component id: " + successEvent.getComponent().getId() + " Action: " + successEvent.getAction()
+ " Text: " + successEvent.getText());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
I'm really stuck in here and the references for this isn't that much :(
I've been searching everywhere but only found about that commandbutton references not commandlink, but i needed to use a commandlink since i wanted the UI like in the image i've attahced above.
Just replacing h:commandLink with p:commandLink should solve your problem.
You may also want to add some update="#form" clauses so that you can see the messages.
<h:form>
<p:growl globalOnly="false" showDetail="true" />
<p:commandLink id="btnAjaxCopy" onclick="return false;" >
<i class="fa fa-share-alt" style="color: black"/>
<h:outputText value=" Share" escape="false" style="color: black;"/>
</p:commandLink>
<pe:clipboard id="clipAjax" trigger="btnAjaxCopy" action="copy" text="PrimeFaces Clipboard Rocks Ajax!">
<p:ajax event="success" listener="#{clipboardController.successListener}" update="#form"/>
<p:ajax event="error" listener="#{clipboardController.errorListener}" update="#form"/>
</pe:clipboard>
</h:form>
Related
So i have designed a simple form having selectOneListbox / selectManyMenu elements which I am using to generate a piece of text based upon the user selections.
It's working fine. Now what I want is when the user clicks 'clear' button, the selections should be undone and the page should come back to the initial state(no selections).
How can I achieve this ?
xhtml
<h:form>
<h:panelGrid columns="6" style="margin-bottom:10px;" cellpadding="5" columnClasses="label, value">
<p:panel>
<h6 style="width:10.4em;background-color:#ACBECE;">Comment Type</h6>
<!-- comment type -->
<p:selectOneListbox id="basic1" value="#{decisionTreeBean.option1}" style=" font-size: 12px;background-color:silver;width:12em; height:10em; border-style:solid !important;border-width:0.5px !important; border-color:grey !important;">
<f:selectItems value="#{decisionTreeBean.commentType}" var="X" itemLabel="#{X}" itemValue="#{X}" />
</p:selectOneListbox>
</p:panel>
<p:panel>
<h6 style="width:10.4em;background-color:#ACBECE;">MTCN</h6>
<p:selectManyMenu id="advanced1" value="#{decisionTreeBean.option2}" showCheckbox="true" style="font-size: 12px;background-color:silver;width:12em; height:10em; border-style:solid !important;border-width:0.5px !important; border-color:grey !important;">
<f:selectItems value="#{decisionTreeBean.mtcns}" var="X" itemLabel="#{X}" itemValue="#{X}" />
</p:selectManyMenu>
</p:panel>
</h:panelGrid>
<!-- Text Area -->
<p:inputTextarea id="decisionNotes" readonly="#{facesContext.renderResponse}" value="#{decisionTreeBean.decisionNotes}" styleClass="dispostionInputTextArea" autoResize="true">
</p:inputTextarea>
<br/>
<p:commandButton id="generateBtn" value="Generate Text" action="#{decisionTreeBean.generateText}" update=":#{p:component('decisionNotes')}">
</p:commandButton>
<p:commandButton id="clearBtn" value="Clear" action="#{decisionTreeBean.clearText}" update=":#{p:component('decisionNotes')}">
</p:commandButton>
<p:ajaxStatus onstart="PF('statusDialog').show()"
onsuccess="PF('statusDialog').hide()" />
<p:dialog widgetVar="statusDialog" modal="true" draggable="false"
closable="false" resizable="false" showHeader="false">
<p:graphicImage value="/images/ajax-loader.gif" />
</p:dialog>
</h:form>
In my bean, I have a clear method which clears the content of the textarea. I want this button to undo the selections as well as part of the ajax call.
public void clearText() {
this.decisionNotes=" ";
}
(for brevity I have included just 2 columns here in xhtml. There are in total 5 separate selection columns with same functionality)
I would simply reset the values of the Menu/Box in the bean method too:
public void clearText() {
this.decisionNotes=" ";
this.option1 = null;
//and so on...
}
Then you just need to update the components in the update attribute of your button. But I'd update the whole form instead of each component if you want to refresh nearly each component in the form. So just use update="#form":
Note: The default process value of p:commandButton is #form. So your clear button will process the whole form on every click altough it doesn't need to. I'd set it to process="#this", so it will just perform it's action.
I am unable to download the zip file.
After clicking ok button in confirmDialog I am unable to download a zip file.
If I am not using confirmDialog I can able to download the file.
Could any one help me on this,
Here I added the code for the reference.
<h:form>
<p:panelGrid rendered="true">
<p:commandButton style="HEIGHT: 24px; WIDTH: 300px" id="AjaxFalse"
value="AjaxFalse"
action="#{testDownload.getZipFile}"
title="AjaxFalse" rendered="true">
<p:confirm message="Are you sure?"
header="Confirmation"
icon="ui-icon-alert" />
</p:commandButton>
</p:panelGrid>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade" width="500">
<h:panelGroup layout="block" style="text-align: center">
<p:commandButton value="Ok" type="submit" styleClass="ui-confirmdialog-yes" style="width:70px;"/>
<p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no" style="width:70px;"/>
</h:panelGroup>
</p:confirmDialog>
</h:form>
My backingbean is
public class TestDownload
{
//some code here
//Downloading the zip file in jsf2.x
public String getZipFile()
{
try{
//enter code here
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
ec.setResponseHeader("Content-Disposition", "attachment;filename=\"" + Test + ".zip\"");
ec.setResponseCharacterEncoding("UTF-8");
ec.setResponseContentType("application/zip");
//This method will generate the required file.
new BulkloadImporter().generateIntegrationXSDs(getId(), ec.getResponseOutputStream());
fc.responseComplete();
return "Save";
}
catch(Exception e)
{
//Handling exception
}
}
//some code here
}
This issue is not 'download' related. Up to now (PrimeFaces 5.3/5.3.2) using a <p:confirm...> global dialog in combination with ajax="false" does not work. The server side action in general will not be called.
There are two possible solutions:
Don't use global mode and do the download on the button in the confirmDialog
Use the workaround mentioned in the issue (not tested this myself)
An example of non-global usage can be found in the PrimeFaces Documentation (adapted to this case):
Getting started with ConfirmDialog ConfirmDialog has two modes; global and non-global. Non-Global mode is almost same as the dialog
component used with a simple client side api, show() and hide().
<h:form>
<p:commandButton type="button" onclick="PF('cd').show()" />
<p:confirmDialog message="Are you sure about downloading this file?"
header="Initiating download" severity="alert"
widgetVar="cd">
<p:commandButton value="Yes Sure" action="#{testDownload.getZipFile}" ajax="false"
update="messages" oncomplete="PF('cd').hide()"/>
<p:commandButton value="Not Yet" onclick="PF('cd').hide();" type="button" />
</p:confirmDialog>
</h:form>
When I click somewhere inside my panelGrid, it runs action from my commandButton which is inside as well. Whole accordionPanel is inside h:form ..
jsf:
<p:accordionPanel value="#{test.getAllTests()}" var="currentTest" activeIndex="false">
<p:tab title="#{currentTest.name}">
<h:panelGrid columns="2" cellpadding="10">
<p:graphicImage value="resources/img/testIT/#{currentTest.imageSrc}" width="100" height="100" />
<p:outputLabel>
<h2>#{currentTest.name}</h2>
<p>#{currentTest.description}</p>
<p:commandButton value="Zvolit test" styleClass="testChoseButton" actionListener="#{test.setSelectedTest(currentTest)}" action="testProgress.xhtml" />
<p:spacer height="5px" width="20px" style="float: right;" />
<p:button value="Statistika testu" styleClass="testChoseButton" />
</p:outputLabel>
</h:panelGrid>
</p:tab>
</p:accordionPanel>
test.setSelectedTest(currentTest):
public void setSelectedTest(Test selectedTest) {
this.selectedTest = selectedTest;
System.err.println("Selected test: " + selectedTest.getId() + " - " + selectedTest.getName());
}
I do not know what more you could need guys. Thnx for help.
You're misusing p:outputLabel, it generates a HTML <label> element which is not what you want. I'd think both these will work:
p:outputPanel
h:panelGroup
They can both produce a HTML span or a div based on the layout attribute.
I'd take <h:panelGroup> which is meant for exactly this kind of grouping.
I am new to JSF and PrimeFaces. I wish to use on-screen keyboard in my login page for my JSF project and I found primefaces keyboard. When I press the enter button in the primefaces keyboard, it doesn't work.
Even if I added onkeypress="if (event.keyCode == 13) #{usersBean.login()};"
I tried to add in <h:form> and the <p:keyboard>. It only work for pressing the physical enter button but not the one in the primefaces keyboard.
Below is the sample of my login page that using the primefaces keyboard:
<f:view>
<h:form id="loginForm" onkeypress="if (event.keyCode == 13) #{usersBean.login()};">
<h2><h:outputText value="User Login"/></h2>
<h:panelGrid columns="2" style=" padding-top: 20px">
<h:outputLabel value="Email / ID:" for="userIdEmail" />
<h:inputText id="userIdEmail" value="#{usersBean.userIdEmail}" title="Email / ID" required="true" requiredMessage="The Email / ID field is required." style="width: 200px"/>
<h:outputLabel value="Password:" for="userPassword" />
<p:keyboard id="userPassword" value="#{usersBean.loginPassword}" title="UserPassword" showMode="button" password="true" style="width: 195px" />
</h:panelGrid>
<div>
<h:commandButton id="loginButton" value="Login" action="#{usersBean.login()}" binding="#{usersBean.loginButton}" style="margin-right: 5px"/>
<h:message for="loginButton" styleClass="errorStyle" style="text-align: center"/>
</div>
</h:form>
</f:view>
Anyone have any idea how to proceed to the login method after pressing the enter button in the primefaces keyboard?
I need to confirm with the user if he or she are sure about delete his or her account.
For this I think a popup screen would be cool. But most browser block the popup windows.
So I was trying to do that with popupPanel.
But I'm guessing that would not be possible because I have a commandLink inside of it, here's what I'm doind so far :
<rich:popupPanel id="popup_delete_profile" modal="true" onmaskclick="#{rich:component('popup_delete_profile')}.hide()">
<f:facet name="header">
<h:outputText value="Aviso" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popup_delete_profile')}.hide(); return false;">
Close
</h:outputLink>
</f:facet>
<p>Are you sure ?</p>
<h:commandLink value="Yes" action="#{userc.deleteUser}"></h:commandLink>
<h:outputLink value="#" onclick="#{rich:component('popup_delete_profile')}.hide(); return false;">
No
</h:outputLink>
</rich:popupPanel>
This is my manageBean:
public void deleteUser(){
try {
eaoUser.delete(userb.getUser());
// here I would like to refresh the popupPanel saying that was deleted with success and then logout
} catch (Exception e) {
view.errorMessage("ocorreu um erro, por favor tente novamente");
e.printStackTrace();
}
}
EDIT:
public String deleteUser() {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
return "/index.xhtml?faces-redirect=true";
}
Any idea how to do that ?
There are two samples for your problem in the richFaces live demo
RichFaces 3.3
RichFaces 4.0
In the RF 4 live demo, they include a sample of the Managed Bean.
Hope it helps.
How to invoke managed bean action in rich:popupPanel
Add this code in your popUp.xhtml page
Note:replace rich:popuppanal and use rich:modalPanel
<a4j:commandLink styleClass="no-decor" execute="#this" render="#none"
oncomplete="#{rich:component('confirmPane')}.show()">
<h:graphicImage value="/images/icon-delete.gif" />
</a4j:commandLink>
<rich:modalPanel id="confirmPane" width="282" height="70">
Are you sure you want to delete the row?
<button id="cancel" onclick="#{rich:component('confirmPane')}.hide();" >
<h:outputText value="cancel" escape="false" />
</button>
<button id="delete" onclick="#{rich:component('confirmPane')}.hide(); clickHiddenButton('officeForm:yesSubmit');return true;">
<h:outputText value="yes" escape="false" />
</button>
<h:commandButton id="yesSubmit" style="visibility:hidden;"
onclick="#{rich:component('confirmPane')}.hide()" action="deleteRecord" />
</rich:modalPanel>