| Author |
Message |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 08/01/2009 15:18:09
|
anarancio
Joined: 17/07/2008 00:00:00
Messages: 3
Offline
|
hi all, I am new creating custom components and I have a question.
I create a new component let say something like this:
<test:testComponent attr1="#{someBean.attr1}" />
as you can see I have a component that have an attribute declared, and I am using the attribute of a bean as the value of that attribute.
the result of the tag is a normal textarea component and I am displaying attr1 as his value.
Now the value is displayed correctly but when the user change the value the attribute someBean.attr1 is not updated, I put a breakpoint on the setProperties method of the tag but it's never called (I think this method should be called when the attribute is updated).
In conclusion I need to update the someBean.attr1 with the value of the textarea (for example as ice:inputText does).
anybody have any clue of how to do this? (any will be a lot of help)
thanks a lot in advance,
Alex
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 09/01/2009 12:55:23
|
anarancio
Joined: 17/07/2008 00:00:00
Messages: 3
Offline
|
Ok I make it work :)
It seems that we have to do this thing in the decode method of the component, there we can get the values from the request and sent to the value bindings.
Regards!
Alex
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 12/03/2009 09:48:46
|
dodge
Joined: 31/08/2007 00:00:00
Messages: 22
Offline
|
Hi
I am facing this problem also. Could you post your code in the decode method for setting the value?
thanks
/A
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 12/06/2009 13:08:52
|
ekozokas
Joined: 24/11/2006 00:00:00
Messages: 10
Offline
|
I tried fixing this with the decode method and had no luck. I seemed to have problems with object references getting mixed up.
I was able to get this to work without using the decode method.
I added this to my getValue() method on the component and was able to grab my attribute values.
Code:
if( bindings.containsKey( "myAttribute" ) ) {
ValueExpression myAtttributeTagValueExpression = bindings.get( "myAttribute" );
myAttribute = ( MyAttribute )myAttributeTagValueExpression.getValue( FacesContext.getCurrentInstance().getELContext() );
}
I also added this attribute and full tag details to the *.tld file.
I think most of my other changes were pretty standard.
I am still interested in how you got the decode method to work.
Please post some code chunks if possible.
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 12/06/2009 13:17:18
|
michelle2
Joined: 14/11/2007 00:00:00
Messages: 449
Offline
|
ekozokas wrote:
I tried fixing this with the decode method and had no luck. I seemed to have problems with object references getting mixed up.
I was able to get this to work without using the decode method.
I added this to my getValue() method on the component and was able to grab my attribute values.
Code:
if( bindings.containsKey( "myAttribute" ) ) {
ValueExpression myAtttributeTagValueExpression = bindings.get( "myAttribute" );
myAttribute = ( MyAttribute )myAttributeTagValueExpression.getValue( FacesContext.getCurrentInstance().getELContext() );
}
I also added this attribute and full tag details to the *.tld file.
I think most of my other changes were pretty standard.
I am still interested in how you got the decode method to work.
Please post some code chunks if possible.
You don't necessarily have to get your attribute values in decode, decode is mostly for getting values from the session.
But you can, if you want like this
@Override
public void decode(FacesContext context, UIComponent component) {
super.decode(context, component);
Map map = (Map) context.getExternalContext().getSessionMap().get(
CurrentStyle.class.getName());
String baseId = component.getClientId(context);
String contentId = baseId + "_header";
String style = (String) map.get(contentId);
SelectList selectList = (SelectList) component;
UIComponent parentComponent = component.getParent();
if (style != null) {
Boolean newState = Boolean.TRUE;
if (style.indexOf("display:none") != -1) {
newState = Boolean.FALSE;
}
Boolean currentState = selectList.getSelected();
if (newState.equals(true)) {
StackContainer container = (StackContainer) parentComponent;
selectList.setSelectedIndex(container.getRowIndex());
component = selectList;
ActionEvent ae = new ActionEvent(component);
component.queueEvent(ae);
selectList.setSelected(newState);
}
}
}
I've attached a couple components you can study.
| Filename |
mcv-comps.jar |
Download
|
| Description |
to use these components just include the jar, waringing these components are meant for a mobile app, but will work in firefox , safari or webkit not ie |
| Filesize |
53 Kbytes
|
| Downloaded: |
134 time(s) |
|
|
|
 |
|
|