Hello Jose,

The problem is that you're not updating the reference map with the new
value. Re-assigning the string value has no effect on the Map (this is how
references work in Java). This should work:

@FacesComponent(value="myComponent")
 public class MyComponent extends UINamingContainer  {
   public void changeStringValue(ActionEvent e){
     getAttributes().put("myString", "HERE IM SETTING A NEW VALUE");
   }
 }
___

Kito D. Mann | @kito99 | Author, JSF in Action
Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and consulting
http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info |
@jsfcentral
+1 203-404-4848 x246

* Listen to the latest headlines in the JSF and Java EE newscast:
http://blogs.jsfcentral.com/roller/editorsdesk/category/JSF+and+Java+EE+Newscast
* Sign up for the JSFCentral Newsletter: http://oi.vresp.com/?fid=ac048d0e17



On Wed, Jul 25, 2012 at 4:08 PM, José Luis Cetina <maxtorz...@gmail.com>wrote:

> I pass a string reference to my composite component with the value =
> ORIGINAL VALUE, then my composite component have a button, this button
> change the original value to = HERE IM SETTING A NEW VALUE, then when
> i press my button in my "normal page: page.xhtml for review it",the
> value still without any change (ORIGINAL VALUE), why this happend, if
> my string is pass as a reference because is an object, what im doing
> wrong?
>
> Resume:
>
> 1. I pass a String (as attribute to my composite component) with the
> value: ORIGINAL VALUE
> 2. Then in the composite component i get this attribute and change it
> to =HERE IM SETTING A NEW VALUE
> 3. When i review the value in page.xhtml i see again ORIGINAL VALUE
> (not expected)
> 4. If i review my value in my composite component i have:HERE IM
> SETTING A NEW VALUE
>
> I try to set my Bean to RequestScoped, ViewAccessScoped and
> SessionScoped and the problem is the same.
>
> Here is an example:
>
> My composite component: myComponent.xhtml
>
>  <ui:component  xmlns="http://www.w3.org/1999/xhtml";
>           xmlns:p="http://primefaces.org/ui";
>           xmlns:cc="http://java.sun.com/jsf/composite";
>           xmlns:ui="http://java.sun.com/jsf/facelets";
>           xmlns:h="http://java.sun.com/jsf/html";>
>
>         <cc:interface componentType="myComponent">
>             <cc:attribute name="myString" type="java.lang.String"/>
>         </cc:interface>
>
>         <cc:implementation>
>             <p:commandButton value="Change Value"
>                              actionListener="#{cc.changeStringValue}"/>
>         </cc:implementation>
>
>     </ui:component>
> My FacesComponent Class:
>
> @FacesComponent(value="myComponent")
>  public class MyComponent extends UINamingContainer  {
>    public void changeStringValue(ActionEvent e){
>      String originalValue = (String) getAttributes().get("myString");
>      //Here i change the value
>      originalValue = "HERE IM SETTING A NEW VALUE";
>    }
>  }
> My page.xhtml
>
> <h:body>
>  <h:form id="myform">
>  <test:myComponent myString="#{myBean.myString}/>
>  <p:commandButton value="Review change"
>      actionListener="#{myBean.showValue}"/>
> <h/form>
> </h:body>
> ManagedBean:
>
> @Named
> @ViewAccessScoped
> public void MyBean implements Serializable{
>    public String myString = "ORIGINAL VALUE";
>
>    public void showValue(ActionEvent e){
>     //why here i see ORIGINAL VALUE if my component change the reference
> value??
>      System.out.println("Value: "+myString);
>    }
>
>   //setters and getters...
> }
>
>
>
> What im doing wrong???
>

Reply via email to