Replaced initialized value from any Contexts in property
mladen.babic Feb 9, 2009 3:42 PMHi,
I need a help about initialized value. I have list of entity which is iterated in dataTable component.
What I need is function which populates value from contexts to entity values Eg. We have Project entity as projects value in dataTable. Project entity has property eg.String initValue = 'currentProject.createdDate' and I want that value be replaced with value from any contexts in application equals with value in property(We presume that 'currentProject' already exists in contexts) .
This is snipped of my code:
`
public Object getInitializedValue(String value) {
if (value == null || "".equals(value)) {
return "";
}
String methodName = null;
boolean hasMethod = false;
hasMethod = value.indexOf('.') > -1;
Object injectedObject = Contexts
.lookupInStatefulContexts(hasMethod ? value.substring(0, value
.indexOf('.')) : value);
if (hasMethod) {
methodName = value
.substring(value.indexOf('.') + 1, value.length());
methodName = methodName.substring(0, 1).toUpperCase()
+ methodName.substring(1);
}
if (injectedObject != null) {
try {
injectedObject = hasMethod ? injectedObject.getClass()
.getMethod("get" + methodName, new Class[] {}).invoke(
injectedObject, new Class[] {})
: injectedObject;
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return injectedObject;
} else {
return "";
}
}
`
and this is snippet part of my page
`
<ice:dataTable width="100%" value="#{projects}" rendered="#{not empty values}"
var="project" id="SpTable1">
<ice:column>
<f:facet name="header">
#{messages.value}
</f:facet>
<!-- INITIALIZED VALUE -->
<ice:inputText value="#{initializedValueHandler.getInitializedValue(project.initValue)}" rendered="#{project.value.propertyType eq 'INITIALIZED_VALUE'}" size="40" />
</ice:column>
....
`
This works OK if I want only to show result, but what I really want is to allow user to edit new value in input text field which is not possible because there is no set method.
I think expression value or method might help but I'm not familiar with that.
Any help or idea will be appreciated.
Best regards,
Mladen
I need a help about initialized value. I have list of entity which is iterated in dataTable component.
What I need is function which populates value from contexts to entity values Eg. We have Project entity as projects value in dataTable. Project entity has property eg.String initValue = 'currentProject.createdDate' and I want that value be replaced with value from any contexts in application equals with value in property(We presume that 'currentProject' already exists in contexts) .
This is snipped of my code:
`
public Object getInitializedValue(String value) {
if (value == null || "".equals(value)) {
return "";
}
String methodName = null;
boolean hasMethod = false;
hasMethod = value.indexOf('.') > -1;
Object injectedObject = Contexts
.lookupInStatefulContexts(hasMethod ? value.substring(0, value
.indexOf('.')) : value);
if (hasMethod) {
methodName = value
.substring(value.indexOf('.') + 1, value.length());
methodName = methodName.substring(0, 1).toUpperCase()
+ methodName.substring(1);
}
if (injectedObject != null) {
try {
injectedObject = hasMethod ? injectedObject.getClass()
.getMethod("get" + methodName, new Class[] {}).invoke(
injectedObject, new Class[] {})
: injectedObject;
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return injectedObject;
} else {
return "";
}
}
`
and this is snippet part of my page
`
<ice:dataTable width="100%" value="#{projects}" rendered="#{not empty values}"
var="project" id="SpTable1">
<ice:column>
<f:facet name="header">
#{messages.value}
</f:facet>
<!-- INITIALIZED VALUE -->
<ice:inputText value="#{initializedValueHandler.getInitializedValue(project.initValue)}" rendered="#{project.value.propertyType eq 'INITIALIZED_VALUE'}" size="40" />
</ice:column>
....
`
This works OK if I want only to show result, but what I really want is to allow user to edit new value in input text field which is not possible because there is no set method.
I think expression value or method might help but I'm not familiar with that.
Any help or idea will be appreciated.
Best regards,
Mladen