Output on Jboss server:
Ajax String Example:
Client Side Code:
Code for Backing Bean:
Client Side Code:
Client Side Code:
Ajax String Example:
Client Side Code:
<h:form id ="form1">
<h:inputText value="#{testbean.name}">
<a4j:ajax event="keyup" render="form2">
</a4j:ajax>
</h:inputText>
</h:form>
<h:form id = "form2">
<h:outputText value="#{testbean.name}" />
</h:form>
Code for Backing Bean:
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.*;
@ManagedBean(name="testbean")
@RequestScoped
public class TestBean {
private String name="tosha";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
PickList:Client Side Code:
<h:form>
<h:outputText value="Pick list Example"></h:outputText>
<rich:pickList sourceCaption="Available" targetCaption="Selected" listWidth="165px" listHeight="100px" >
<!-- static list -->
<f:selectItem itemLabel="Option 1" itemValue="1"/>
<f:selectItem itemLabel="Option 2" itemValue="2"/>
<f:selectItem itemLabel="Option 3" itemValue="3"/>
<f:selectItem itemLabel="Option 4" itemValue="4"/>
<f:selectItem itemLabel="Option 5" itemValue="5"/>
<!-- Dynamic list from a backing bean -->
<f:selectItems value="#{listSelectBean.capitals}"/>
</rich:pickList>
</h:form>
Code for backing Bean:package com.trial;
import javax.annotation.PostConstruct;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ManagedBean(name="listSelectBean")
@ApplicationScoped
public class ListSelectBean {
private List capitals;
private List selectedCapitals;
public ListSelectBean() {
capitals = new ArrayList();
capitals.add("India");
capitals.add("Australia");
capitals.add("USA");
}
public List getCapitals() {
return capitals;
}
public void setCapitals(List capitals) {
this.capitals = capitals;
}
public List getSelectedCapitals() {
return selectedCapitals;
}
public void setSelectedCapitals(List selectedCapitals) {
this.selectedCapitals = selectedCapitals;
}
}
Table Example:Client Side Code:
<h:form>
<rich:panel>
<h:panelGrid columns="2">
<a4j:commandButton value="+" action="#{bean.add}" render="list" />
<a4j:commandButton value="-" action="#{bean.remove}" render="list" />
</h:panelGrid>
<rich:dataTable id="list" value="#{bean.list}" var="item"
width="60px">
<rich:column>
<h:outputText value="#{item}" />
</rich:column>
</rich:dataTable>
</rich:panel>
</h:form>
<h:form>
<rich:panel>
<h:panelGrid columns="2">
<a4j:commandButton value="+" action="#{bean.add}" render="list" />
<a4j:commandButton value="-" action="#{bean.remove}" render="list" />
</h:panelGrid>
<rich:dataTable id="list" value="#{bean.list}" var="item"
width="60px">
<rich:column>
<h:outputText value="#{item}" />
</rich:column>
</rich:dataTable>
</rich:panel>
</h:form>
Backing Bean Code:
package com.trial;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.*;
@ManagedBean(name="testbean")
@RequestScoped
public class TestBean {
private String name="tosha";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
No comments:
Post a Comment