Skip to content

Commit

Permalink
Added InputOtp example
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Apr 23, 2024
1 parent d667361 commit 8c5d991
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 24 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/primefaces/showcase/menu/AppMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@
*/
package org.primefaces.showcase.menu;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;


import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Named;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@Named
@ApplicationScoped
Expand Down Expand Up @@ -96,6 +94,7 @@ public void init() {
formMenuItems.add(new MenuItem("InputGroup", "/ui/input/inputGroup"));
formMenuItems.add(new MenuItem("InputMask", "/ui/input/inputMask"));
formMenuItems.add(new MenuItem("InputNumber", "/ui/input/inputNumber"));
formMenuItems.add(new MenuItem("InputOtp", "/ui/input/inputOtp"));
formMenuItems.add(new MenuItem("InputPhone", "/ui/input/inputPhone"));
formMenuItems.add(new MenuItem("InputText", "/ui/input/inputText"));
formMenuItems.add(new MenuItem("InputTextArea", "/ui/input/inputTextarea"));
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/org/primefaces/showcase/view/input/InputOtpView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2011-2023 PrimeFaces Extensions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.primefaces.showcase.view.input;

import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import java.io.Serializable;

import lombok.Data;


@Named
@ViewScoped
@Data
public class InputOtpView implements Serializable {

private static final long serialVersionUID = 1L;

private String normal;
private String password;
private Integer number;

public void submit() {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Required: " + normal, null));
context.addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Password: " + password, null));
context.addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Numbers: " + number, null));
}
}
44 changes: 44 additions & 0 deletions src/main/resources/META-INF/resources/ui/input/inputOtp.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="jakarta.faces.facelets"
xmlns:h="jakarta.faces.html"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions"
template="/template/template.xhtml">

<ui:define name="title">
InputOtp
</ui:define>

<ui:define name="description">
InputOtp is an input component suitable for inserting fixed-size PINs or one time passwords (OTP).
</ui:define>

<ui:param name="documentationLink" value="/components/inputotp"/>
<ui:param name="widgetLink" value="InputOtp"/>

<ui:define name="implementation">
<div class="card">
<h:form id="frmOtp">
<p:messages id="msgs">
<p:autoUpdate/>
</p:messages>
<div class="card">
<h5>Required</h5>
<pe:inputOtp id="txtRequired" length="4" value="#{inputOtpView.normal}" required="true"/>

<h5>Password</h5>
<pe:inputOtp id="txtPassword" length="5" mask="true" value="#{inputOtpView.password}"/>

<h5>Numbers</h5>
<pe:inputOtp id="txtNumber" length="6" integerOnly="true" value="#{inputOtpView.number}"/>

<h5>Disabled</h5>
<pe:inputOtp disabled="true"/>
</div>

<p:commandButton value="Submit" actionListener="#{inputOtpView.submit}" update="@form"/>
</h:form>
</div>
</ui:define>

</ui:composition>
41 changes: 22 additions & 19 deletions src/main/resources/META-INF/resources/ui/overlay/dialog.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,41 @@
<p:commandButton value="Show" type="button" icon="pi pi-external-link" onclick="PF('dlg4').show()"/>
</div>

<p:dialog header="Header" widgetVar="dlg1" minHeight="40" width="350" showEffect="fade">
<p:dialog header="Header" widgetVar="dlg1" minHeight="40" width="350" showEffect="fade" closeOnEscape="true">
<p class="m-0">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</p:dialog>

<p:dialog header="Header" widgetVar="dlg2" minHeight="40" width="350" showEffect="fade" modal="true">
<p:dialog header="Header" widgetVar="dlg2" minHeight="40" width="350" showEffect="fade" modal="true"
closeOnEscape="true">
<p class="m-0">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</p:dialog>

<p:dialog header="Header" widgetVar="dlg3" minHeight="40" width="350" showEffect="fade">
<p:dialog header="Header" widgetVar="dlg3" minHeight="40" width="350" showEffect="fade" focus="btnYes"
closeOnEscape="true">
<p class="m-0">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<f:facet name="footer">
<p:commandButton type="button" value="No" styleClass="ui-button-flat mr-2" style="width: 6rem" />
<p:commandButton type="button" value="Yes" style="width: 5rem" />
<p:commandButton type="button" value="No" styleClass="ui-button-flat mr-2" style="width: 6rem"/>
<p:commandButton id="btnYes" type="button" value="Yes" style="width: 5rem"/>
</f:facet>
</p:dialog>

<p:dialog header="Header" widgetVar="dlg4" minHeight="40" width="350" showEffect="fade" minimizable="true" maximizable="true">
<p:dialog header="Header" widgetVar="dlg4" minHeight="40" width="350" showEffect="fade" minimizable="true"
maximizable="true">
<p class="m-0">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</p:dialog>

</ui:define>

</ui:composition>
</ui:composition>

0 comments on commit 8c5d991

Please sign in to comment.