

|
|
Home >> Miscellaneous
JSF-based example web application with usage of some of the tags
such as selectManyCheckbox and selectItems, outputText and inputText
and commandButton.
For the sake of simplicity I am going to take an already explained
example on JSF-based application from this web site pages, and
include some more tags from JSF tag libraries.
Before going through this Page, I would suggest to go through the
example that has used only inputText, outputText and commandButton
tags. As I am going to add selectManayCheckbox and selectItems tags
to this example JSP pages.
Refering to the earlier example page
I am going to add an array of javax.faces.model.SelectItem as instance
variable in the managed bean for this example, that is
"sample.ButtonEventCapture"
There are setter and getter methods for the SelectItem array, as shown below:
And in the constructor of this managed bean, SessionItem array is being
instantiated and filled with some hypothetical values such as one, two, three,
..., seven, eight etc.
ButtonEventCapture.java
package sample;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
public class ButtonEventCapture
{
public ButtonEventCapture()
{
//creating default set of select items with ids as first
//argument and label as the second argument to the
//constructor.
tableData = new SelectItem[]{new SelectItem("0","Zero"),
new SelectItem("1","One"),
new SelectItem("2","two"),
new SelectItem("3","three"),
new SelectItem("4","four"),
new SelectItem("5","five"),
new SelectItem("6","six"),
new SelectItem("7","seven"),
new SelectItem("8","eight")};
}
public void setTxtName(String txtName)
{
this.txtName = txtName;
}
public String getTxtName()
{
return txtName;
}
public void setTxtPass(String txtPass)
{
this.txtPass = txtPass;
}
public String getTxtPass()
{
return txtPass;
}
public String submitButton()
{
System.out.println((new StringBuilder("Name: ")).append(txtName).toString());
System.out.println((new StringBuilder("Pass: ")).append(txtPass).toString());
if(txtName.trim().equalsIgnoreCase(""))
FacesContext.getCurrentInstance().addMessage("name_blank",
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Please enter name", ""));
if(txtPass.trim().equalsIgnoreCase(""))
FacesContext.getCurrentInstance().addMessage("pass_blank",
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Please enter password", ""));
if(txtName.length() > 8)
FacesContext.getCurrentInstance().addMessage("name_too_large",
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Name should be lesser than 8 characters", ""));
Iterator itr = FacesContext.getCurrentInstance().getMessages();
if(itr.hasNext())
{
FacesMessage msg = (FacesMessage)itr.next();
List list = FacesMessage.VALUES;
if(list.size() > 0)
return null;
}
return "preview";
}
public String cancelButton()
{
System.out.println("Cancel button is clicked...");
return null;
}
public SelectItem[] getTableData() {
return tableData;
}
public void setTableData(SelectItem[] objs) {
System.out.println(objs.length);
//this is the method that receives user
//selection from UI, in form of an array.
}
public void setSelectedData(String[] arg) {
System.out.println(arg.length + " " +arg[0]);
}
public String[] getSelectedData() {
return selectedData;
}
String txtName;
String txtPass;
SelectItem[] tableData;
String[] selectedData;
}
|
Above section in blue with bold letters are used for showing multiple checkboxes
(SelectItem[]) and receiving user selected values (in String[]).
selectedData String array can be prepopulated in the managed bean's constructor
to be able to show some of the checkboxes already checked while page loads.
Like for this example, I can add code for prepopulating selectedData String[]
as follows:
selectedData = new String[2];
selectedData[0] = "2"; // id as String
selectedData[1] = "5"; // id as String
|
So using the above code, I can be having third and sixth checkboxes with label as
"two" and "five", as checked.
The index.jsp page used in this example is as follows:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="sampleHtml" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="sampleCore" %>
<html>
<body>
<sampleCore:view locale="en_US">
<sampleCore:loadBundle basename="sample" var="s"/>
<h4><sampleHtml:outputText value="#{s.title_text}"/></h4>
<sampleHtml:messages layout="table"/>
<sampleHtml:form>
<table>
<tr><td><sampleHtml:outputText value="#{s.name_text}"/></td>
<td><sampleHtml:inputText value="#{SampleMGMTBean.txtName}"/></td></tr>
<tr><td><sampleHtml:outputText value="#{s.pass_text}"/></td>
<td><sampleHtml:inputSecret value="#{SampleMGMTBean.txtPass}"/></td></tr>
<tr><td><sampleHtml:commandButton value="Submit"
action="#{SampleMGMTBean.submitButton}"/></td>
<td><sampleHtml:commandButton value="Cancel"
action="#{SampleMGMTBean.cancelButton}"/></td></tr>
</table>
<sampleHtml:selectManyCheckbox id="manyChkBoxes" value="#{SampleMGMTBean.selectedData}">
<sampleCore:selectItems value="#{SampleMGMTBean.tableData}"/>
</sampleHtml:selectManyCheckbox>
</sampleHtml:form>
</sampleCore:view>
</body>
</html>
|
This example page doesn't make any business sense, other than just to show possible
visual appearance of these JSF-based UI components and their Tags.
In order to make this example run, one may require all other files such as
web.xml, preview.jsp, faces-config.xml files from the initial example Page
from this web site ( Refering to the earlier example page)
If anything missed out , please let me know at
techienjoy at yahoo . com
|
|
|
|
|
|
|
|
|
|
|
| Android Examples : |
List of ANDROid examples
with source code and output
screens captured and shown.
|
|
|
|
|
|
|
| Google GWT Example : |
Example using GWT and some design patterns and various
ways of implementing this example.
|
|
|
|
|
|
|
| Android ListView Example : |
Example on Android List View
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
|
|
|
|
|
|
|
|
|
| Android Tab View Example : |
Example on Android Tab View
explained with a very simple scenario
and appropriate screens captured and shown.
|
|
|
|
|
|
|
|
| Android Gallery Example : |
Example on Android Gallery View
explained with a very simple scenario
and appropriate screens captured and shown.
|
|
|
|
|
|
|
|
|
|
|
| Android ListView Example : |
Example on Android ListView and
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
|
| Android Sensors Example : |
Example on Android Sensors Listed and
explained with a very simple scenario
and article with appropriate screens
captured and shown.
|
|
| Android ListView Example : |
Example on Android ListView
explained with a very simple scenario
whereby showing folder and files with
structure and appropriate screens
captured and shown.
|
|
|
|
|
|
|
References :
Tags: TabHost and TabActivity Example on Android Platform
Tags: ListView Example on Android Platform
Tags: android sensors list
Tags: android listview example
Tags: android imageview example
Tags: Android example download any file sourcecode
Tags: android expandable list dynamically created example
Tags: android expandable list example
Tags: Android Gallery surfaceviews spinner
Tags: Android example download any file sourcecode
Tags: Android Layout Example
Tags: Android Text To Speech Example
Tags: DOJO Example Dialog
Tags: DOJO Example Tree Widget
Tags: different logger file log4j
Tags: JDBC Transaction isolation
Tags: event handling java code
Tags: example quartz scheduler
Tags: example tag library web application
Tags: Flex
Tags: index
Tags: inmemory image creation java awt
Tags: JSF Example Main
Tags: JSF Example Tags CheckBoxes
Tags: JSF Example Tags dataTable
Tags: JSF Example Tags SelectBoxes
Tags: JSF Example Tags Walkthrough
Tags: JSF Example Validation
Tags: JSF Resource Bundle
Tags: log4j example 1
Tags: log4j example
Tags: Miscellaneous
Tags: Mule ESB File Transport
Tags: Mule ESB JMS Transport
Tags: stream download batch
Tags: sychronized block wait notify
Tags: thread wait notify example
Tags: using apache commons log
Tags: web load test
Tags: Wizard Framework Idea Java
DISCLAIMER :
The content provided in this page is not warranted and/or guaranteed by techienjoy.com.
techienjoy.com is not liable for any negative consequences that may result/arise from
implementing directly/indirectly any information covered in these pages/articles/tutorials.
All contents of this site is/are written and provided on an "AS IS" basis,
without WARRANTIES or conditions of any kind, either express or implied, including, without
limitation, merchantability, or fitness for a particular purpose. You are solely responsible
for determining the appropriateness of using or refering this and assume any risks associated
with this.
In spite of all precautions taken to avoid any typo in these pages, there might be some
issues like grammatical mistakes and typos being observed in these pages, techienjoy.com
extends sincerest apologies to all our visitors for the same.
|
| 

|