You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Kamal Bhatt <kb...@tt.com.au> on 2007/12/30 07:02:57 UTC
[CFORMS] Dynamically specifying Help and labels
Hi,
I have a requirement to dynamically allocate the help and labels for
fields in a repeater. My solution, uses jx templates to set fi:help and
fi:label, like so:
<ft:repeater-widget id="style_flds">
<ft:widget id="value">
<fi:label>
<jx:out
value="${form.getChild('styles').getRow(style_idx).getChild('style_flds').getRow(repeaterLoop.index).getChild('label').value}"
/>
</fi:label>
<fi:styling
type="${form.getChild('styles').getRow(style_idx).getChild('style_flds').getRow(repeaterLoop.index).getChild('fld_type').value}"
/>
<fi:help>
<jx:out
value="${form.getChild('styles').getRow(style_idx).getChild('style_flds').getRow(repeaterLoop.index).getChild('help').value}"
/>
</fi:help>
</ft:widget>
</ft:repeater-widget>
This is a hack. Normally I would be fine with this, but as you can
probably guess we are using 2.1.7 CForms. My question is, if we upgrade
and get all ajaxy, what is the likelihood my hack will continue to work?
Another question, for the development team, has anyone thought about being
able to dynamically set labels in the definition? It seems like a rather
onerous assumption that ever field in a repeater will be labelled the same
way. What would be nice would be able to set state, label and headings in
the definition (where it belongs) using javascript. For example:
<fd:field id="value">
<fd:datatype base="string" />
<fd:state>
<fd:javascript>
if (blah) return(WidgetState.ACTIVE);
else return(WidgetState.INVISIBLE);
</fd:javascript>
<fd:state>
<fd:label>
<fd:javascript>
if (blah) return("First label");
else return("Second label");
</fd:javascript>
</fd:label>
</fd:field>
Anyway, my two cents.
Cheers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [CFORMS] Dynamically specifying Help and labels
Posted by Grzegorz Kossakowski <gk...@apache.org>.
Kamal Bhatt pisze:
> Now, one thing I don't see a work around for is dynamically setting
> min-size, max-size and initial-size for repeaters (aside from
> dynamically generating the definitions, which is such a bad solution, it
> isn't worth considering). Is there a workaround to this? Was there an
> architectural reason for not supporting this, as this seems like a
> common usecase? This is not a show stopper for me, but it is definitely
> something I would like to do (for reasons similar to my original post).
I think that it's again the same situation as with customizing label. Standard form definition
covers around 80% of use-cases. If your use-case is unusual Forms framework always leaves the doors
to customization room open. In this case it's writing custom validator. You could write a simple
Javascript validator consisting of a few lines of scripting that could calculate value for max-size
according to your needs.
> I would be happy to document how I did the dynamic generation of labels,
> but seeing as I am not using 2.1.8 CForms, I don't see much of a point
> right now. If we ever move to 2.1.8, I will happily post instructions on
> the Cocoon wiki.
Kamal, we will certainly appreciate any contribution to Cocoon's documentation!
--
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [CFORMS] Dynamically specifying Help and labels
Posted by Kamal Bhatt <kb...@tt.com.au>.
>
> As Sylvain already pointed out, if we allowed labels to be dynamic and supported by framework
> someone other will raise his hand and tell us he needs access key to be dynamic and supported by the
> framework. Personally speaking, I'm also against adding such feature to Forms even though your
> use-case is valid. I believe that good frameworks does not try to cover all possible cases but only
> common ones and leave enough freedom to implement solution in those rare ones.
>
>
I agree with that in part. However, I don't see why everything specified
in the definition shouldn't be dynamic . Maybe the arguement should be
the appropriateness of having the label, help, etc there in the first
place (I think that was a comment made in the thread you sent me). As
there is a work around, I am not going to press the issue.
Now, one thing I don't see a work around for is dynamically setting
min-size, max-size and initial-size for repeaters (aside from
dynamically generating the definitions, which is such a bad solution, it
isn't worth considering). Is there a workaround to this? Was there an
architectural reason for not supporting this, as this seems like a
common usecase? This is not a show stopper for me, but it is definitely
something I would like to do (for reasons similar to my original post).
I would be happy to document how I did the dynamic generation of labels,
but seeing as I am not using 2.1.8 CForms, I don't see much of a point
right now. If we ever move to 2.1.8, I will happily post instructions on
the Cocoon wiki.
Cheers.
--
Kamal Bhatt
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [CFORMS] Dynamically specifying Help and labels
Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Kamal Bhatt pisze:
> Am I correct in assuming that if we don't use ajax then the bu:replace
> in not necessary? Is there anywhere I can find documentation on the "bu"
> namespace?
Unfortunately, there is not much resources on bu namespace apart from sample of AJAX block.
BrowserUpdateTransformer has been considered as rather internal aspect of Forms that users shouldn't
be bothered about.
As see now, there are cases when knowledge about BU transformer is needed. Anyway, you can even take
a look at transformer's source code because this transformer is really simple one.
But if you need a help I'm ready to explain how AJAX works in Forms.
>> Yep, it has been discussed a long time ago. I found a good response
>> from Sylvain on this topic:
>> http://article.gmane.org/gmane.text.xml.cocoon.devel/35520
>>
>> Reading from that, your solution is not a hack really. You only need
>> to adopt it to AJAX techniques.
>>
>> I hope that helps you a bit.
>>
>>
> Thanks for that. I personally disagree with the statement that this
> shouldn't be done dynamically. The next thread suggests that the concept
> may be revisited if someone could come up with a usecase. Does my
> scenario count?
As Sylvain already pointed out, if we allowed labels to be dynamic and supported by framework
someone other will raise his hand and tell us he needs access key to be dynamic and supported by the
framework. Personally speaking, I'm also against adding such feature to Forms even though your
use-case is valid. I believe that good frameworks does not try to cover all possible cases but only
common ones and leave enough freedom to implement solution in those rare ones.
What I would love to see is to figure out in detail how to achieve your goal using template and add
it to the documentation as FAQ entry.
> Thanks for the reply.
No problem!
--
Grzegorz Kossakowski
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [CFORMS] Dynamically specifying Help and labels
Posted by Kamal Bhatt <kb...@tt.com.au>.
Grzegorz Kossakowski wrote:
>
> I don't think so it is going to work without minor adjustments. You will need to wrap fi:* you are
> generating manually with bu:replace tags according to a widget value change. You just need to add
> construct like:
> <jx:if test="form.updatedWidgetIds.contains('label')">
> <bu:replace>
> <fi:label>
> <jx:out
> value="${form.getChild('styles').getRow(style_idx).getChild('style_flds').getRow(repeaterLoop.index).getChild('label').value}"/>
> </fi:label>
> </bu:replace>
> </jx:if>
>
> It must be done that way so update of label is performed only if widget that label value relies on
> was changed. Construct shown above will work in non-AJAX mode, also.
>
> I must admit I was typing from my head so there may be some minor details missing.
>
Am I correct in assuming that if we don't use ajax then the bu:replace
in not necessary? Is there anywhere I can find documentation on the "bu"
namespace?
>
> Yep, it has been discussed a long time ago. I found a good response from Sylvain on this topic:
> http://article.gmane.org/gmane.text.xml.cocoon.devel/35520
>
> Reading from that, your solution is not a hack really. You only need to adopt it to AJAX techniques.
>
> I hope that helps you a bit.
>
>
Thanks for that. I personally disagree with the statement that this
shouldn't be done dynamically. The next thread suggests that the concept
may be revisited if someone could come up with a usecase. Does my
scenario count?
Thanks for the reply.
Kamal.
--
Kamal Bhatt
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [CFORMS] Dynamically specifying Help and labels
Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Kamal Bhatt pisze:
> Another point of clarification, if label does not change from the first
> time you start the screen, am I correct in thinking that the bu:replace
> is not necessary?
Yes, but then you should use just a plain ft:widget-label tag instead.
--
Grzegorz Kossakowski
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [CFORMS] Dynamically specifying Help and labels
Posted by Kamal Bhatt <kb...@tt.com.au>.
> I don't think so it is going to work without minor adjustments. You will need to wrap fi:* you are
> generating manually with bu:replace tags according to a widget value change. You just need to add
> construct like:
> <jx:if test="form.updatedWidgetIds.contains('label')">
> <bu:replace>
> <fi:label>
> <jx:out
> value="${form.getChild('styles').getRow(style_idx).getChild('style_flds').getRow(repeaterLoop.index).getChild('label').value}"/>
> </fi:label>
> </bu:replace>
> </jx:if>
>
> It must be done that way so update of label is performed only if widget that label value relies on
> was changed. Construct shown above will work in non-AJAX mode, also.
>
> I must admit I was typing from my head so there may be some minor details missing.
>
>
>
Another point of clarification, if label does not change from the first
time you start the screen, am I correct in thinking that the bu:replace
is not necessary?
Thanks.
--
Kamal Bhatt
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [CFORMS] Dynamically specifying Help and labels
Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Kamal Bhatt pisze:
> Hi,
> I have a requirement to dynamically allocate the help and labels for
> fields in a repeater. My solution, uses jx templates to set fi:help and
> fi:label, like so:
>
> <ft:repeater-widget id="style_flds">
> <ft:widget id="value">
> <fi:label>
> <jx:out
> value="${form.getChild('styles').getRow(style_idx).getChild('style_flds').getRow(repeaterLoop.index).getChild('label').value}"
> />
> </fi:label>
> <fi:styling
> type="${form.getChild('styles').getRow(style_idx).getChild('style_flds').getRow(repeaterLoop.index).getChild('fld_type').value}"
> />
> <fi:help>
> <jx:out
> value="${form.getChild('styles').getRow(style_idx).getChild('style_flds').getRow(repeaterLoop.index).getChild('help').value}"
> />
> </fi:help>
> </ft:widget>
> </ft:repeater-widget>
>
> This is a hack. Normally I would be fine with this, but as you can
> probably guess we are using 2.1.7 CForms. My question is, if we upgrade
> and get all ajaxy, what is the likelihood my hack will continue to work?
I don't think so it is going to work without minor adjustments. You will need to wrap fi:* you are
generating manually with bu:replace tags according to a widget value change. You just need to add
construct like:
<jx:if test="form.updatedWidgetIds.contains('label')">
<bu:replace>
<fi:label>
<jx:out
value="${form.getChild('styles').getRow(style_idx).getChild('style_flds').getRow(repeaterLoop.index).getChild('label').value}"/>
</fi:label>
</bu:replace>
</jx:if>
It must be done that way so update of label is performed only if widget that label value relies on
was changed. Construct shown above will work in non-AJAX mode, also.
I must admit I was typing from my head so there may be some minor details missing.
> Another question, for the development team, has anyone thought about being
> able to dynamically set labels in the definition? It seems like a rather
> onerous assumption that ever field in a repeater will be labelled the same
> way. What would be nice would be able to set state, label and headings in
> the definition (where it belongs) using javascript. For example:
>
> <fd:field id="value">
> <fd:datatype base="string" />
> <fd:state>
> <fd:javascript>
> if (blah) return(WidgetState.ACTIVE);
> else return(WidgetState.INVISIBLE);
> </fd:javascript>
> <fd:state>
> <fd:label>
> <fd:javascript>
> if (blah) return("First label");
> else return("Second label");
> </fd:javascript>
> </fd:label>
> </fd:field>
>
> Anyway, my two cents.
Yep, it has been discussed a long time ago. I found a good response from Sylvain on this topic:
http://article.gmane.org/gmane.text.xml.cocoon.devel/35520
Reading from that, your solution is not a hack really. You only need to adopt it to AJAX techniques.
I hope that helps you a bit.
--
Grzegorz Kossakowski
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org