You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Vincent Sevel <vs...@sqli.com> on 2005/03/24 15:29:22 UTC

RE : using x:aliasBean from myfaces components with jsf-ri

It *does* work with 1.0.9.

Personal opinion : it is so much better that way than going through the
complexity of defining a brand new jsf component for this level of
reuse; plus you have the freedom to use jsf components in the subform,
rather than plain html like it seems we have to in renderers. Defining a
new component should be around that kind of simplicity (the parallel
could be made with defining a new panel in swing). 

My only wish would be a special <x:include alias='' value='' page=''/>
component (with some children like <x:param alias='' value=''/>) that
handles the subview and jsp:include.

Related question : considering the code below, which is a strict
application of the aliasBean, what would it take to be able to use a
custom tag such that my alias.jsp would be as simple as: <firstlastname
person="#{aliasPage.father}"/>, while still preserving firstlastname.jsp
intact?

-------------------------------------------- faces-config.xml

	<managed-bean>
	    <managed-bean-name>alias</managed-bean-name>
	    <managed-bean-class>alias.AliasPage</managed-bean-class>
	    <managed-bean-scope>request</managed-bean-scope>
	</managed-bean>

-------------------------------------------- AliasPage.java

public class AliasPage {
  private Person father = new Person();
  
  public String refresh() {
    System.out.println("father: "+father.getFirstname()+"
"+father.getLastname());
    return null;
  }

-------------------------------------------- Person.java

public class Person {
  
  private String firstname;
  private String lastname;
...

-------------------------------------------- alias.jsp

		<x:aliasBean alias="#{holder}"
value="#{aliasPage.father}">
			<f:subview id="father">
				<jsp:include
page="firstlastname.jsp"/><p/>
			</f:subview>
		</x:aliasBean>

-------------------------------------------- firstlastname.jsp

		<h:inputText value="#{holder.firstname}"/> <h:inputText
value="#{holder.lastname}"/>

thanks

v.

-----Message d'origine-----
De : Mathias Broekelmann [mailto:mbroekelmann@psi.de] 
Envoyé : jeudi, 24. mars 2005 14:34
À : MyFaces Discussion
Objet : Re: using x:aliasBean from myfaces components with jsf-ri

Hi Vincent,

have you tried 1.0.9?

There where some issues with aliasbean see:

http://issues.apache.org/jira/browse/MYFACES-125?page=comments#action_60
623

Mathias

Vincent Sevel schrieb:
> Hi,
> 
> I have been having troubles using aliasBean from myfaces with the 
> jsf-ri. I have tried the following code with both implementations:
> 
> faces-config.xml
> 
>          <managed-bean>
> 
>              <managed-bean-name>person</managed-bean-name>
> 
>              <managed-bean-class>custom.Person</managed-bean-class>
> 
>              <managed-bean-scope>request</managed-bean-scope>
> 
>          </managed-bean>
> 
>  
> 
> // Person.java
> 
> *public* *class* Person {
> 
>   
> 
>   *private* String firstname;
> 
>   *private* String lastname;
> 
>   
> 
>   *public* String refresh() {
> 
>     System.out.println("person: "+firstname+" "+lastname);
> 
>     *return* *null*;
> 
>   }
> 
>  
> 
>   *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;
> 
>   }
> 
>  
> 
> <!-- alias.jsp -->
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> 
> <%@ page language="java" %>
> 
> <html>
> 
>   <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
> 
>   <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
> 
>   <%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
> 
>   <body>
> 
>     <f:view>
> 
>       <h:form>
> 
>                  <x:aliasBean sourceBean="#{person}"
alias="#{holder}">
> 
>                           <f:subview id="form2">
> 
>                                    <h:inputText
value="#{holder.firstname}"/>
> 
>                                    <h:inputText
value="#{holder.lastname}"/><p/>
> 
>                           </f:subview>
> 
>                  </x:aliasBean>
> 
>                  
> 
>                  <h:commandButton value="Refresh"
action="#{person.refresh}"/>
> 
>       </h:form>
> 
>       <h:messages layout="table" style="color: red"/>
> 
>     </f:view>
> 
>   </body>
> 
> </html>
> 
>  
> 
> 
> 
> bringing the page works in both implementations, but pressing the 
> refresh button works in my-faces (1.0.8) and result in an exception in

> jsf-ri (1.1_01) :
> 
> java.lang.ClassCastException: java.lang.Boolean
> 
>          at
com.sun.faces.el.ValueBindingImpl.getType(ValueBindingImpl.java:93)
> 
>          at
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedVa
lue(HtmlBasicInputRenderer.java:111)
> 
>          at
javax.faces.component.UIInput.getConvertedValue(UIInput.java:713)
> 
>          at javax.faces.component.UIInput.validate(UIInput.java:638)
> 
>          at
javax.faces.component.UIInput.executeValidate(UIInput.java:849)
> 
>          at
javax.faces.component.UIInput.processValidators(UIInput.java:412)
> 
>          at
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.
java:912)
> 
>          at
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.
java:912)
> 
>          at
org.apache.myfaces.custom.aliasbean.AliasBean.processValidators(AliasBea
n.java:179)
> 
>          at
javax.faces.component.UIForm.processValidators(UIForm.java:170)
> 
> 
> 
> furthermore, the exception occurs on the 2nd inputText, although the 
> value binding expressions are very similar!
> 
> it is unfortunate that this component does not work with the RI
because 
> it appears to be a very effective way of reusing component trees, 
> specially when you need several of them in the same page, binding to 
> differents objects. Any fix or workaround?
> 
> thanks
> v.
> 
>  
>