ArticlesTutorialsInterview Questions & AnswersCertificationsFree Books & Sample ChaptersTechnical Discussions  Your Account | Advertise with us | Feedback |
Few pages of this site are under construction and we are constantly trying to improve it. If you have any suggestions or ideas about how to improve the site, please Let us know.
< t:aliasBean >

« Previous             Tomahawk Tag Home t:aliasBeansScope »

<t:aliasBean>


Contents

  1. Introduction
  2. Tag Attributes
  3. Example

Introduction

MyFaces Tomahawk Alias Bean is a powerful feature for creating generic composition components in JSF. Main idea is to set a dummy alias name and refer it to a real managed bean in context. Get a reference and replace it with the real deal. When used within an aliasBeansScope tag, this tag adds the alias to the aliasBeansScope. This makes configuration with multiple aliasBeans easier to write.


Tag Attributes


AttributeDescription   Type    
alias The variable that will be created to hold a reference to the existing value. This must be an EL expression. (e.g., "#{myAliasBean}") String
id The unique identifier value for this component. The value must be unique within the closest naming container (e.g.,h:form or f:subview).This value must be a static value.String
value The value attribute takes a value-binding EL expression (e.g.,"#{myBean.myProperty}") that identifies the object or literal String value (e.g.,"foo") to assign to the alias.String
rendered A value-binding expression that evaluates to a Boolean condition indicating if this component should be rendered.String


Example


  Let's suppose you have a subform you use often but with different beans.
The aliasBean allows you to design the subform with a fictive bean and to include it in all the pages where you use it. You just need to make an alias to the real bean named after the fictive bean before invoking the fictive bean.

 As an example suppose we need to add Address information to some of the entities in our application. First thing to do is to create the Address class with the addressLine1 and addressLine2.


Address.java

package com.developersBook.aliasBean.example.domain;
public class Address {
private String addressLine1;
private String addressLine2;
public Address() {}
public Address(String addressLine1, String addressLine2){
super();
this.addressLine1 = addressLine1;
this.addressLine2 = addressLine2;
}
public String getAddressLine1() {
return addressLine1;
}
public void setAddressLine1(String addressLine1) {
this.addressLine1 =addressLine1;
}
public String getAddressLine2() {
return addressLine2;
}
public void setAddressLine2(String addressLine2) {
this.addressLine2 =addressLine2;
}
  }

And an example entity that needs a Address information. Let’s say a Person



Person.java

package com.developersBook.aliasBean.example.domain;
public class Person{
private String firstName;
private String lastName;
private Address address;
public Person(){}
public Person(String firstName, String lastName, Address address){
super();
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
}
public Address getAddress(){
return address;
}
public void setAddress(Address address){
this.address = address;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
  }

After creating the domain entities, we need a JSF page and a backing bean to create a new Person.



PersonEditBean.java

package com.developersBook.aliasBean.example.bean;
import com.developersBook.aliasBean.example.domain.Address;
public class PersonEditBean{
private Address address;
public Address getAddress() {
if(address == null){
address = new Address();
}
return address;
}
public void setAddress(Address address){
this.address = address;
}
public void editPerson() {
//save the address with the underlying technology
}
  }

Finally the JSF Page for PersonEdit and the Address jsp fragment.



personEdit.jsp

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head><title></title></head>
<body>
<f:view>
 <h:form>
  <h:panelGrid columns="2">
   <h:outputLabel value="firstName" for="firstName"/>
   <h:inputText id="firstName" value="#{PersonEditBean.person.firstName}" />
   <h:outputLabel value="lastName" for="lastName"/>
   <h:inputText id="lastName" value="#{PersonEditBean.person.lastName}" />
  </h:panelGrid>

  <t:aliasBeansScope>
   <t:aliasBean alias="#{addressAlias}" value="#{PersonEditBean.person.address}" />
   <f:subview id="addressView">
    <%@ include file="address.jsp"%>
   </f:subview>
  </t:aliasBeansScope>


  <h:commandButton action="#{PersonEditBean.person.address}" value="Submit" />
 </h:form>
</f:view>
</body>
</html>


address.jsp (partial)

<%@ page pageEncoding="utf-8"%>
  <h:panelGrid columns="2?>
   <h:outputLabel value="AddressLine1" for="addressLine1"/>
   <h:inputText id="addressLine1" value="#{addressAlias.addressLine1}" />

   <h:outputLabel value="AddressLine2" for="addressLine2"/>
   <h:inputText id="addressLine2" value="#{addressAlias.addressLine2}" />
 </h:panelGrid>


« Previous             Tomahawk Tag Home t:aliasBeansScope »
//-->
//-->
Related Links

Tomahawk
t:aliasBean
t:aliasBeansScope
t:buffer
t:checkbox
t:collapsiblePanel
t:column
t:columns
t:commandButton
t:commandLink
t:commandNavigation
t:commandNavigation2
t:commandSortHeader
t:dataList
t:dataScroller
t:dataTable
t:div
t:document
t:documentBody
t:documentHead
t:dojoInitializer
t:graphicImage
t:headerLink
t:htmlTag
t:iconProvider
t:inputCalendar
t:inputDate
t:inputFileUpload
t:inputHidden
t:inputHtml
t:inputSecret
t:inputText
t:inputTextHelp
t:inputTextarea
t:jsValueChangeListener
t:jsValueSet
t:jscookMenu
t:message
t:messages
t:navigationMenuItem
t:navigationMenuItems
t:newspaperTable
t:outputLabel
t:outputText
t:panelGrid
t:panelGroup
t:panelLayout
t:panelNavigation
t:panelNavigation2
t:panelStack
t:panelTab
t:panelTabbedPane
t:popup
t:radio
t:saveState
t:schedule
t:selectBooleanCheckbox
t:selectItems
t:selectManyCheckbox
t:selectManyListbox
t:selectManyMenu
t:selectOneCountry
t:selectOneLanguage
t:selectOneListbox
t:selectOneMenu
t:selectOneRadio
t:stylesheet
t:swapImage
t:tabChangeListener
t:tree
t:tree2
t:treeCheckbox
t:treeColumn
t:treeSelectionListener
t:updateActionListener
t:validateCreditCard
t:validateEmail
t:validateEqual
t:validateRegExpr
Core Tags
f:actionListener
f:attribute
f:converter
f:convertDateTime
f:convertNumber
f:facet
f:loadBundle
f:param
f:selectitem
f:selectitems
f:subview
f:validateDoubleRange
f:validateLength
f:validateLongRange
f:validator
f:valueChangeListener
f:verbatim
f:view
HTML Tags
h:column
h:commandButton
h:commandLink
h:dataTable
h:form
h:graphicImage
h:inputHidden
h:inputSecret
h:inputText
h:inputTextarea
h:message
h:messages
h:outputFormat
h:outputLabel
h:outputLink
h:outputText
h:panelGrid
h:panelGroup
h:selectBooleanCheckbox
h:selectManyCheckbox
h:selectManyListbox
h:selectManyMenu
h:selectOneListbox
h:selectOneMenu
h:selectOneRadio

  ALSO SEE :

About Us | Our Mission | Terms of use | Author Terms |    Search        | Contact Us | Advertise With Us | Link to Us | Sitemap
Copyright © 2016 developersbook.com. All rights reserved.