I want to show you how to get the value of the variable from php to java using JSON. JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate(wikipedia). First, you build your database and create a table. …
Monthly Archive: February 2012
Feb 23
Encapsulation
package exercise4; public class Telepon { private int durasi, tarif; private String kodeAsal, kodeTujuan, nomorAsal, nomorTujuan; public int ongkos() { if (kodeAsal.equals(kodeTujuan)) { tarif = 100; } else { tarif = 200; } return tarif * durasi; } public int getDurasi() { return durasi; } public void setDurasi(int durasi) { this.durasi = durasi; } public …
Feb 17
JSF- Build Error Handling (Empty Input Fields)
1. First, you build the xhtml file
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <f:view encoding="UTF-8" contentType="text/html"> <h:head> <title>#{msgs.windowTitle}</title> <h:outputStylesheet library="css" name="styles.css" /> </h:head> <h:body> <h:form> <h:outputText value="#{msgs.greeting}" styleClass="emphasis" /> <br /> <h:messages errorClass="errors" layout="table" /> <h:panelGrid columns="3"> #{msgs.namePrompt}: <h:inputText id="name" value="#{user.name}" required="true" label="#{msgs.namePrompt}" /> <h:message for="name" errorClass="errors" /> #{msgs.agePrompt}: <h:inputText id="age" value="#{user.age}" required="true" size="3" label="#{msgs.agePrompt}" /> <h:message for="age" errorClass="errors" /> </h:panelGrid> <h:commandButton value="#{msgs.submitPrompt}" /> </h:form> </h:body> </f:view> </html> |
The correct label should be declared as:
|
1 2 |
<h:inputText id="name" value="#{user.name}" required="true" label="#{msgs.namePrompt}" /> |
and the correct error message should be declared as:
|
1 2 |
<h:message for="name" errorClass="errors" /> #{msgs.agePrompt}: |
with “for” as same as “name” of the target. 2. and then build user.java
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @Component("user") @Scope("session") public class User implements Serializable { private String name; private String age; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } } |
Feb 17
JSF #TAG
this tutorial will be about xhtml using list item using java class. First, you initialized the index.xhtml the dynamic value of form.yearItems. <h:selectOneMenu value=”#{form.yearOfBirth}” required=”true”> <f:selectItems value=”#{form.yearItems}” /> </h:selectOneMenu> 2. Initialized the java class for getYearItems (remember! variable for yearItems must be declared getYearItems) and then return to other variables (integer or String) public Collection<SelectItem> getYearItems() …
Recent Comments