Kingsley Mullers

Ranch Hand
+ Follow
since Jan 14, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kingsley Mullers

Good morning, how do i restrict the system from allowing multiple users to logon with the same username and password at the same time, i've developed the front end using swing and LDAP
14 years ago
thanks for your response but how does it find the attribute field since the attribute name needs to be dynamic, so that when i call it from the validation bean it must know which field name to validate.

<h:inputText id="Firstname" value="******" required="true">
<f:validator validatorId="validation" />
</h:inputText>
16 years ago
JSF
Hi guys,

i have written a jsf validation class and it doesnt seem to be working,
my faces.config is configured like this. <validator>
<validator-id>validation</validator-id>
<validator-class>
za.co.fnb.pyramid.validations.Validation
</validator-class>
</validator>

and call my validator on jsf
<h:outputText value="First name" />
<h:inputText id="Firstname" value="" required="true">
<f:validator validatorId="validation" value="Firstname"/>
<f:attribute name="field" value="Firstname" />
</h:inputText>
<h:message errorStyle="color: red" infoStyle="color: green"layout="table" for="Firstname" />

and my validation class

package za.co.fnb.pyramid.validations;

import java.util.Date;
import javax.faces.validator.*;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;

import org.apache.log4j.Logger;


public class Validation implements Validator {

Logger LOG = Logger.getLogger(Validation.class);

public Validation() {}


public void validatetitle(FacesContext context,UIComponent toValidate, Object value) {
String title = (String) value;
if (title=="") {
((UIInput)toValidate).setValid(false);
FacesMessage message = new FacesMessage("Select title");
//context.addMessage(toValidate.getClientId(context), message);
throw new ValidatorException(message);

}
}


public void validatename(FacesContext context,UIComponent toValidate, Object value) {
LOG.debug("validatename");
String Firstname = (String) value;
if (Firstname=="") {
((UIInput)toValidate).setValid(false);
FacesMessage message = new FacesMessage("Capture name");
//context.addMessage(toValidate.getClientId(context), message);
throw new ValidatorException(message);

}
}

public void validatesurname(FacesContext context,UIComponent toValidate, Object value) {
LOG.debug("validatesurname");
String surname = (String) value;
if (surname=="") {
((UIInput)toValidate).setValid(false);
FacesMessage message = new FacesMessage("Capture surname");
//context.addMessage(toValidate.getClientId(context), message);
throw new ValidatorException(message);
}
}


public void validateEmail(FacesContext context,UIComponent toValidate, Object value) {
String email = (String) value;
if ( email.indexOf("@") == -1 || email.startsWith("@") || email.endsWith("@") ) {
throw new ValidatorException(new FacesMessage("Enter a valid email address."));
}
}

public void validateIDnumber(FacesContext context, UIComponent toValidate, Object value) {
LOG.debug("validateIDnumber");
String idnumber = (String) value;
if ( idnumber.length() < 13 ) {
((UIInput)toValidate).setValid(false);
FacesMessage message = new FacesMessage("Invalid identity number");
//context.addMessage(toValidate.getClientId(context), message);
throw new ValidatorException(message);
}

}

public void validateDateofBirth(FacesContext context, UIComponent toValidate, Object value) {
LOG.debug("validateDateofBirth");
Date datefield = (Date) value;
if ( datefield==null ) {
((UIInput)toValidate).setValid(false);
FacesMessage message = new FacesMessage("Capture date of birth ");
(context), message);
throw new ValidatorException(message);
}
}







public void validateNumber(FacesContext context, UIComponent component, Object value) {
String s = String.valueOf(value);
if (!s.matches("\\d\\d\\d\\d")){
throw new ValidatorException(new FacesMessage
("Not a four-digit number."));
}
}






@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
String attribute = (String)component.getAttributes().get("value");
LOG.debug("attribute");
if (attribute=="title") {
validatetitle(context, component, value);

} else if (attribute=="Firstname") {
validatename(context, component, value);
LOG.debug("Firstname");

} else if (attribute=="Surname") {
validatesurname(context, component, value);
LOG.debug("Surname");

} else if (attribute=="Email") {
validateEmail(context, component, (String)value);

} else if (attribute=="Id") {
validateIDnumber(context, component, value);

} else if (attribute=="Gender"){
validateGender(context, component,value);

} else if (attribute =="Resident"){
validateResident(context,component,value);

} else if (attribute=="citizen") {
validateCitizenship(context, component, value);

} else if (attribute=="language") {
validateLanguage(context, component, value);

} else if (attribute=="race") {
validateRace(context, component, value);

} else if (attribute=="marital") {
validateMarital(context, component, value);

}else if(attribute=="status"){
validateStatus(context,component,value);

} else if (attribute=="dateofbirth") {
validateDateofBirth(context, component, value);

} else if (attribute=="insolvent") {
validateInsolvent(context, component, value);

} else if (attribute=="rehabilated") {
validateRehabilated(context, component, value);
}

}
}
16 years ago
JSF
Hi Guys,

i've got this code in my project to validate fields, i've made this my backend bean and added it to my faces.config.xml.when i call this bean to validate the fields, nothing happens. i call my bean like this, validation being the name of the class and validate surname is the method name in my input attribute, can anybody tell me what i'm doing wrong. i call individual methods for each and every field, to validate but no luck

<h:outputText value="Surname" />
<h:inputText id="Surname" value="" required="true" validator="#{validation.validatesurname}" />
<h:message errorStyle="color: red"
infoStyle="color: green" layout="table" for="Surname" />

Back end bean


import javax.faces.validator.*;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;

import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;

public class Validation implements Validator {


public Date validateDate(FacesContext context, UIComponent component, String value) throws ConverterException, java.text.ParseException {

String pattern = "yyyy/MM/dd";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Date nDate;

try {

nDate = sdf.parse(value);
} catch (ParseException ex) {
FacesMessage message = new FacesMessage();
message.setDetail("Date required (yyyy/MM/dd)");
message.setSummary("Date required (yyyy/MM/dd)");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ConverterException(message);
}
if(nDate.getTime() > new Date().getTime()){
FacesMessage message = new FacesMessage();
message.setDetail("Invalid birth day to ID number");
message.setSummary("Invalid birth day to ID number");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ConverterException(message);
}

return nDate;

}
public void validateEmail(FacesContext context,UIComponent toValidate, Object value) {
String email = (String) value;
if ( email.indexOf("@") == -1 || email.startsWith("@") || email.endsWith("@") ) {
throw new ValidatorException(new FacesMessage("Enter a valid email address."));
}
}

public void validatesurname(FacesContext context,UIComponent toValidate, Object value) {
String surname = (String) value;
LOG.debug("validatesurnname");
if (surname=="") {
((UIInput)toValidate).setValid(false);
FacesMessage message = new FacesMessage("Capture surname");
context.addMessage(toValidate.getClientId(context), message);
LOG.debug("validatesurname");
}
}
public void validatePassport(FacesContext context, UIComponent toValidate, Object value) {
String passport = (String) value;
if ( passport=="" ) {
((UIInput)toValidate).setValid(false);
FacesMessage message = new FacesMessage("Invalid passport");
context.addMessage(toValidate.getClientId(context), message);
}

}
public void validateAddress(FacesContext context, UIComponent toValidate, Object value) {
String address = (String) value;
if ( address=="" ) {
((UIInput)toValidate).setValid(false);
FacesMessage message = new FacesMessage("Capture address");
context.addMessage(toValidate.getClientId(context), message);
}

}
public void CellNumberValidator(FacesContext context, UIComponent component, Object value) {
String strValue = (String)value;
if (strValue.length() != 10){
throwException("Number of cell phone digits must be 10");
}
}



}


16 years ago
JSF
Hi folks,

Does JSF have a ModalDialogWindow component, to pop up a list of some sort to so one can select from.

thanks
16 years ago
JSF
Hi folks


I need a bit of help in creating a generic java bean.
I have created 5 different java beans each returning objects.
Now after returning these objects i want to create generic bean which will put all objects returned from the different beans in singe List .
How do I approach this?


Thanks
16 years ago
thanks for your response, but if you want to pass these values to a business delegate bean obviously in a single object, would that have a different approach?
16 years ago
JSF
i've created tabbed panes like this, one containing personal details, one containing address details, one containing account details and so on so forth. All these jsf pages contain a command button called next to tab to the next page until the last one which actually submit data to the database. How do i submit this data, do i submit it page by page or store the data somewhere and submit data all at once?
16 years ago
JSF
hello folks,
i've just tried auto complete using ajax... but the values are always empty
<s:inputSuggestAjax id="id" suggestedItemsMethod="" value="">
can anybody why?
16 years ago
JSF
i'm using eclipse to develop jsf pages
16 years ago
JSF
Can anybody tell me how or where to find auto complete example which does not use Ajax cos i'm having problems with Ajax, the code is correct and everthing but there's no data rendered, tried using sandbox but no luck.
16 years ago
JSF
Can anybody tell me where i can find an example of a page wizard code written specifically for JSF or even Java script, by page wizard i mean showing steps on each page at the top to show how far you are to completing inputting data on each page.
16 years ago
JSF
Hi Folks,

i've been battling with this for a almost a 2 weeks

I�m trying to get this menu bean working, I�ve got a constructor created and initialized

(I think this is where the problem might be) cos this only gets executed once,

When the status changes I want it to display a different menu option---logoff.

When status equals Home, it must display Login and when the status equals Logon then it must change to Log Off

Menu bean displays options on your left hand side of the page with different options�

I�m using java server faces with struts tiles, so I have my layout jsp menu, footer and heading and so forth.

I call the bean directly from my jsf pages and this is all fine even though I�m new to jsf. The jsf part is working fine.

Before you login it should look like this

Home
Login

--------

Admin
Users

--------

Requirements
Actors
Use Case


After you logged in it should look like this


Home
Log Off

--------

Admin
Users

--------

Requirements
Actors
Use Case

16 years ago
hi folks, could you please assist, i'm trying to run a jsf login page on eclipse, running Apache server but the page is complaining about the two errors below: i do have all the jar files imported but still no luck

1) javax.servlet.ServletException: javax/servlet/jsp/tagext/JspIdConsumer
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:272)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



2) java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/JspIdConsumer
16 years ago
JSF
I have constructed an EJB which when you pass xml data to it will decompose the xml into java objects that you can write to the database but there�s another EJB that I need to call before that which basically calls the XML data or return the XML data.

What I basically need to do here, is to first call the EJB which will return an XML data then read/ or map the XML data to java objects and write to the database.
Could anybody give me a sample code how I would need to do this.
i really appreciate it
here is what i have created.

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
import java.io.File;
import java.util.*;
import java.util.Iterator;
import java.util.List;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.ejb.Stateless;
import org.apache.log4j.Logger;
import za.co.fnb.pyramid.exceptions.ProcessEngineException;
import za.co.fnb.pyramid.interfaces.ProcessEngineSessionFacade;


@Stateless(name="ReadingXMLDataSessionFacadeBean", mappedName="ejb/ReadingXMLDataSessionFacade")

public class ReadingXMLDataSessionFacadeBean implements ProcessEngineSessionFacade {

private static final Logger LOG = Logger.getLogger( ReadingXMLDataSessionFacadeBean.class );
public ReadingXMLDataSessionFacadeBean() {
super();
LOG.debug( "ReadingXMLDataSessionFacadeBean()" );

}

public void ping()throws ProcessEngineException, RemoteException {
LOG.debug( "ping()" );
//LOG.debug( "processData(String xmlData)" );
{
try {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false); //do not validate the xml
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource("Contacts.xml"));
LOG.debug("doc");
//get contact list
NodeList list = doc.getChildNodes().item(0).getChildNodes();
for (int i = 0; i < list.getLength(); i++){
if (list.item(i).getNodeName().equalsIgnoreCase("contact")){



NodeList contact = list.item(i).getChildNodes();
LOG.debug("contact");
//build contact object
StringBuffer contactObject = new StringBuffer();
for (int j = 0; j < contact.getLength(); j++){
if (!contact.item(j).getNodeName().equalsIgnoreCase("#text")){
if (j > 1) {contactObject.append(",");}
contactObject.append(contact.item(j).getNodeName()+"="+contact.item(j).getFirstChild().toString());

}

}
//write contact object to database
System.out.println(contactObject.toString());
}

}

}
catch (Exception ex){
ex.printStackTrace();

}

}

/** public static void main(String[] args) {
new InputData().processData("");
}

}**/

}
}