You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Russell John-Baptiste <rj...@yahoo.com> on 2013/02/13 17:22:03 UTC

Trouble binding form elements to objects after form submittal

I use a loop within a loop. 

  
I iterate over a list of hibernate DB objects.
  
For each row I get a bunch of related objects.

In some cases they are null, so I create temporary objects for the display
  
My problem is that when I submit the form, setCurrentClassValue is never called and 

the temporary objects are not being updated (in valueList).
  
I am not experiencing joy... what am I doing wrong?

Thanks in advance!

tml:

       <t:form t:id="forecast" class="form-inline">
           <tr t:type="loop" source="classForecastDetails" value="currentClass" element="tr">

                            <td class="span5">
                                <t:pagelink context="currentClass.classId"
                                            page="prop:classLink"> ${currentClass.name}</t:pagelink>
                            </td>

                                    <td t:type="loop" source="timeSpan" class="span1" value="currentMonthAndYear" element="td">
        
                                        <t:if test="currentClassValue">
                                            <t:delegate to="case"/>
        
                                            <t:block t:id="studentSelected">
                                                <t:pagelink t:id="studentMoneyField" context="currentClass.classId"
                                                            page="prop:classLink"> ${totalStudentRevenue}</t:pagelink>
                                            </t:block>
        
        
                                            <t:block t:id="groupSelected">
                                                <t:pagelink t:id="groupMoneyField" context="currentClass.classId"
                                                            page="prop:classLink"> ${totalGroupRevenue}</t:pagelink>
                                            </t:block>
        
                                            <t:block t:id="fullTimeOnlySelected">
                                                <t:pagelink t:id="fulltimeMoneyField" context="currentClass.classId"
                                                            page="prop:classLink"> ${totalFullTimeRevenue}</t:pagelink>
                                            </t:block>
        
                                            <t:block t:id="partTimeOnlySelected">
                                                <div class="input-prepend">
                                                <span class="add-on">$</span><t:textfield t:id="pMoneyField" class="span1" value="currentClassValue.totalRevenue"/>
                                                </div>
                                            </t:block>
        
                                            <t:block t:id="corporateOnlySelected">
                                                <div class="input-prepend">
                                                <span class="add-on">$</span><t:textfield   t:mixins="jquery/tooltip"
                                                                                            title="corporate Money"
                                                                                            t:id="cMoneyField"
                                                                                            class="span1"
                                                                                            value="currentClassValue?.totalRevenue"/>
                                                </div><br/><div class="input-prepend">
                                                <span class="add-on">$</span><t:textfield   t:mixins="jquery/tooltip"
                                                                                            title="Cost of Delivery" t:id="CostofDelivery" class="span1" value="currentClassValue?.costOfDelivery"/>
                                                </div>
                                            </t:block>
        
                                        </t:if>
                                    </td>
                        </tr>
         </t:form>

JAVA:


    @Property
    private Map<Class, Map<MonthAndYear, ClassValue>> valuesGrid;

    @Property
    @Persist
    private List<MonthAndYear> timeSpan;

    @Property
    List<Class> classForecastDetails;

    @Property

    Class currentClass;

    @Property
    MonthAndYear currentMonthAndYear;

    @Property
    ClassType classType;

    @Property
    List<Class> classForecastDetails;

    @Property
    @Persist
    private classForecastDetailsSearchKeys searchKeys;

    @Property
    @Persist
    private List<MonthAndYear> timeSpan;

    @Property
     private List<ClassValue> valueList;

    @Inject
    private Block classSelected, groupSelected, partTimeOnlySelected, corprateOnlySelected, fullTimeOnlySelected;


    public Object getCase() {
        if (searchKeys.getUser() != null) {
            return studentSelected;
        } else if (searchKeys.getGroup() != null) {
            return groupSelected;
        } else if (currentClass.getType().equals(ClassType.FULL_TIME)) {
            return fullTimeOnlySelected;
        } else if (currentClass.getType().equals(ClassType.PART_TIME)) {
            return partTimeOnlySelected;
        } else {
            return cOnlySelected;
        }
    }


   public void setCurrentClassValue(ClassValue value) {
         if (!(value == null)){
            setGridValue(currentClass, currentMonthAndYear, value);
        }
    }


    public ClassValue getcurrentClassValue() {
        classValue result = getGridValue(currentClass, currentMonthAndYear);

        if (result == null) {
            return getNewClassValue();
        }

        return result;
    }


    public void setGridValue(Class p, MonthAndYear my, ClassValue v) {
        if (valuesGrid != null) {
            Map<MonthAndYear, ClassValue> map = valuesGrid.get(p);
            if (map == null) {
                map = new HashMap<MonthAndYear, ClassValue>();
                valuesGrid.put(p, map);
            }
            map.put(my, v);
            valueList.add(v);
            showResult = true;
        }
    }


    public ClassValue getGridValue(Class p, MonthAndYear my) {
        if (valuesGrid == null) {
            return null;
        }
        Map<MonthAndYear, classValue> map = valuesGrid.get(p);
        if (map == null) {
            return null;
        }
        return valuesGrid.get(p).get(my);
    }

    public void onValidateFromForecast() {
        //Confirm whether this is the current logged in user, the system user or the selected user via searchKeys
        classLogic.storeClassValues(valueList, getCurrentUser());

    }

Re: Trouble binding form elements to objects after form submittal

Posted by RJB III <rj...@yahoo.com>.
Thank you Thiago! 

I tried it and it worked! (imagine that!). 


below is my final solution for those it may help in the future. 

I simply put what I had in setupRender into onPrepareForSubmit just like
Thiago suggested and recreated my temporary objects and tapestry figured out
the rest:

    public void onPrepareForSubmit() {
        classForecastDetails =
classLogic.findClassesWithValuesInRange(searchKeys);
        buildGrid();
    }


 private void buildGrid() {
        clearGrids();

        for (Class c : classForecastDetails) {
            for (MonthAndYear my : timeSpan) {
                Double total = totals.get(my);
                ClassValue value = c.getValueForMonthAndYear(my);

                if (value != null) {
                    value.setModificationData(getDefaultModificationData());
                    setGridValue(p, my, value);

                    if (total == null) {
                        total = 0.0;
                    }

                    if (searchKeys.getUser() != null) {
                        total +=
value.getTotalRevenueForStudent(searchKeys.getUser());
                    } else if (searchKeys.getGroup() != null) {
                        total +=
value.getTotalRevenueForGroup(searchKeys.getGroup());
                    } else {
                        total += value.getTotalRevenue();
                    }
                }
                if (total == null) {
                    total = 0.0;
                }
                totals.put(my, total);
            }
        }

    }




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Trouble-binding-form-elements-to-objects-after-form-submittal-tp5720017p5720023.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: Trouble binding form elements to objects after form submittal

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 13 Feb 2013 16:12:52 -0200, RJB III <rj...@yahoo.com> wrote:

> Thank you for the quick response!!!
>
> Ah, my thinking (previously) was that setCurrentClassValue would update  
> my temporary objects one by one.

That's what Tapestry 4 did, and believe me, it wasn't pretty . . .

> My problem now is assuming I have all my temporary objects, how to bind
> those objects to each submited value in my form???

As I said, do what you did in setCurrentClassValue() in a method handling  
the Form's prepare event and it'll work.

-- 
Thiago H. de Paula Figueiredo

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


Re: Trouble binding form elements to objects after form submittal

Posted by RJB III <rj...@yahoo.com>.
Thank you for the quick response!!!

Ah, my thinking (previously) was that setCurrentClassValue would update my
temporary objects one by one.

My problem now is assuming I have all my temporary objects, how to bind
those objects to each submited value in my form???





--
View this message in context: http://tapestry.1045711.n5.nabble.com/Trouble-binding-form-elements-to-objects-after-form-submittal-tp5720017p5720020.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: Trouble binding form elements to objects after form submittal

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
Hi!

On Wed, 13 Feb 2013 14:22:03 -0200, Russell John-Baptiste  
<rj...@yahoo.com> wrote:

> My problem is that when I submit the form, setCurrentClassValue is never  
> called and

That's the expected behavior. The page is not rendered again while  
processing the submit. Use the prepare event of Form to set this temporary  
objects instead.

-- 
Thiago H. de Paula Figueiredo

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