You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2012/10/10 20:55:09 UTC

passing values into script after ajaxformloop row has been added.

Hello, I have a AjaxFormLoop that contains several fields. When a new row has
been added, I need to check the db to see if any of the fields within that
row need are required. If any of the fields comes back true, I need to put
the fields into a hashset then pass them to my script where I would use the
script to add Asterisk to the field. This all works fine on render, just not
after the page has loaded and this is only do to the fact AjaxFormLoop
doesn't call afterRender.  Any thoughts on how to do this? Thanks

Current code. 

    private Set<String> fieldIds = new HashSet<String>();

    public FieldValidator getFieldDisabled(Field field) {
        this.requiredFieldAsterisk(field);        
        return this.purchaseRequestValidation.FieldValidator(field,
this.formValidations, this.action);
    }

    //Fields 
    public void requiredFieldAsterisk(Field field) {

       //FormValidations is just a list of all the fields contained within
the database that are required 
       //within this a particular state of the form. 
       for(FormValidation formValidation : this.formValidations) {
           
if(field.getControlName().startsWith(formValidation.getFormField().getDbTableField()))
{
                this.fieldIds.add(field.getControlName());
            }
        } 
    }

//Jquery

function requiredFields(val) {     
    $.each(val, function(index, item) {
        $('label[for=' + item.id + ']').before('*');
    })
}

   void afterRender() {
        js.addScript("requiredFields(%s)", this.fieldIds);
    }



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: passing values into script after ajaxformloop row has been added.

Posted by Lance Java <la...@googlemail.com>.
Note, servlet containers re-use threads between requests so use tapestry's
PerThreadManager.createValue() to create a value that is per-request.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762p5716783.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: passing values into script after ajaxformloop row has been added.

Posted by George Christman <gc...@cardaddy.com>.
Thanks Lance, I'm all set now :)



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762p5716800.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: passing values into script after ajaxformloop row has been added.

Posted by Lance Java <la...@googlemail.com>.
Use an environmental
http://tapestry.apache.org/environmental-services.html



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762p5716789.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: passing values into script after ajaxformloop row has been added.

Posted by George Christman <gc...@cardaddy.com>.
Thanks Lance, I'm really good with css, so that part shouldn't be an issue,
just wasn't sure how you were setting the css class from the mixin :) 

I think the only other obstacle I foresee is the ability to dynamically
validate the required fields based on the submit action. I currently handle
this by only validating required fields server side. I can then pass the
action id into the query restriction on submit and determine which fields
are required on the fly. 

Example
When a user clicks the "Save" button, none of the fields are required.
When a user clicks the "Submit" button, a subset of fields are required
based on the current state of the form. 
When a user clicks the "broadcast" button, a different set of fields are
become required. 

This becomes more complicating with additional actions and state changes.
When the forms state changes, so does all the actions and required fields. 

(IMHO, This entire validation process is way to complicating) .

So the question is, can I dynamically pass into the mixin the submitted
action?

Example

@Property
private ApplicationAction action;

<t:TextField t:mixins="validationMixin(action)"
t:validate="prop:getFieldValidator(vendorInformation,'maxlength=255')"/>



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762p5716786.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: passing values into script after ajaxformloop row has been added.

Posted by Lance Java <la...@googlemail.com>.
You can use the @BindParameter annotation in a mixin to get/set parameters on
the component that the mixin is bound to. So, your mixin could set the
"validate" and "disabled" properties the field.

I'm rubbish at css but I assume you can add a class to each required field
and then style an asterisk in your css file. I'm sure google can help you
there.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762p5716785.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: passing values into script after ajaxformloop row has been added.

Posted by George Christman <gc...@cardaddy.com>.
Actually I think I may be able to use ehcache for this. 

Last question, your saying I may be able to do this with css, "which I would
prefer" and possibly handle the required in the mixin as well. Any thoughts
on how you might get the css / required back to the field? I'm not sure how
t:validate would call getFieldValidator from within the mixin. 

I'm currently handling it like so, 

@InjectComponent
@Property
private Field vendorInformation;

<t:Label class="control-label" for="vendorInformation"/>
<div class="controls">
    <t:TextArea title="Vendor Information" t:id="vendorInformation"
class="vendorInformation" value="pr.vendorInformation"
t:validate="prop:getFieldValidator(vendorInformation, 'maxlength=255')"
disabled="prop:getFieldDisabled(vendorInformation)"/>
</div>

Thanks Lance. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762p5716784.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: passing values into script after ajaxformloop row has been added.

Posted by Lance Java <la...@googlemail.com>.
Have the mixin call methods on a service backed by a cache. If you don't want
to cache forever, perhaps a ThreadLocal cache will do?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762p5716782.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: passing values into script after ajaxformloop row has been added.

Posted by George Christman <gc...@cardaddy.com>.
Hi Lance, 

I planned on initializing the field in setupRender() once I came up with a
viable solution. 

The mixin seems like an interesting solution. I guess my only concern would
be the mixin calling the query everytime a new field called a mixin. Any
thoughts on that? 

Thanks Lance.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762p5716781.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: passing values into script after ajaxformloop row has been added.

Posted by Lance Java <la...@googlemail.com>.
> private Set<String> fieldIds = new HashSet<String>(); 
Never initialize a field in it's declaration, the value should be
initialized on setupRender()

> Any thoughts on how to do this?
I'd do it serverside. Attach a mixin to each field which adds the asterisk
to the dom (this can most likely be done through css instead). The mixin
could also add the "required" validator to each required field.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/passing-values-into-script-after-ajaxformloop-row-has-been-added-tp5716762p5716767.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org