Re: fields list dependant
Benjamin Papez <[email protected]> Tue, 07 Oct 2008 09:32:28 +0200
| Newsgroups | gmane.comp.cms.jahia.template |
|---|---|
| Message-ID | <[email protected]> |
Hello Jerome,
so you have a main container list, where the containers can hold a sub
container list. A field in the sub container list should be preset with
a dynamic value depending on a field in its parent container. What you
should NOT do is to set a changing value in <content:declareField
value=...>, because these declarations must be constant (see the
Template Developer Guide for more explanations section "Declaration
scope"). If you want to have dynamic default values you may use JEXL
expressions for simple requirements (also explained in the Template
Developer Guide) or you can do it within the eventlistener.jsp.
For instance there is an example in the corporate_portal_templates_v2
blogs\eventlistener.inc, where the "blogAuthor" field is set
dynamically, like this:
if ( "blogEntries".equals(theContainer.getDefinition().getName()) ){
if ( "addContainerEngineAfterInit".equals(eventName) ) {
logger.debug("Start eventlistner for event
addContainerEngineAfterInit for entries Container List");
JahiaField theField = theField =
theContainer.getField("blogAuthor");
if (theField.getValue() == null ||
"".equals(theField.getValue())) {
String author = jParams.getUser().getUsername();
theField.setValue(author);
feh.addUpdatedField(theField.getID(),
theField.getLanguageCode());
updatedFields.add(new Integer(theField.getID()));
logger.debug("Set value for field [blogAuthor] to [" +
theField.getValue() + "]");
}
}
Although this example would be better solved with a JEXL expression
<content:declareField ... value='<jahia-expression
expr="currentUser.username" storeMarker="false"/>'/>
it is just to demonstrate how it could be done with eventlisteners.
In your case, you would need to get ContentContainer parentContainer =
theContainer.getContentContainer().getParent(jParams.getEntryLoadRequest()).getParent(jParams.getEntryLoadRequest())
to get the parent container list and then the parent container. With
JahiaContainer parentJahiaContainer =
parentContainer.getJahiaContainer(jParams,
jParams.getEntryLoadRequest()) you will get the current parent
container revision (depending on language, workflow) and on that object
you can get the wanted field with
parentJahiaContainer.getFieldValue("parentFieldName").
Regards,
Benjamin
On 25.09.2008 12:59 OFFROY, Jerome wrote:
I would like to make 2 select fields in a template (definition)
1 for a main list
and the other for a sub list parameter by the choice in the first
list
can someone tell me if it is possible and if there is an exemple
somewhere
thanks
ps : i want to change the value of the second after the first one
is selected
----------
_______________________________________________
template_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list
_______________________________________________
template_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list