You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Brendan Wholihan <ho...@yahoo.co.uk> on 2005/02/18 16:27:31 UTC

Question on sorting a contrib:Table and persistent parameters

Hi,

Just started using Tapestry, and would be grateful for some help, just to
check that I'm
not "working against the framework" so to say. I've got a simple app up and
running, based on
Appfuse (excellent starter for Tapestry / hibernate / Spring, thanks Matt).

Basically, I have two pages (bills and calls), each with a Table component
in it. A row in bills
can be clicked, to display the calls for that bill. This works and brings
back the right data, but
if I use the table component from the browser, say to sort a column on the
calls page, it will
loose the context of the billId that it has retrieved.

I changed the bill page to use an external link, which passed the billId in
the URL, to give,

http://localhost:8080/app/calls.html?sp=l28

and the sorting column URL on the table for example, is

http://localhost:8080/app/calls.html?service=direct&service=1&service=contrib%3ASimpleTableColumnPage&service=tableColumnComponent.linkColumn&sp=Acalls%2FcallFormTable.tableView&sp=Scall.dateTime

I noticed that the billId parameter on the URL is being lost. I then set
billId as a persistent
property of the page, and it worked. Unfortunately, after some reading, I
realised that this
meant the billId was being stored in the HttpSession. Is it possible to make
the DirectLink
of the Table component include the billId, and pass it back to the page?

The reason I ask, is then I could open more than one call list from the bill
page, by right
clicking on each bill I wanted. Currently, using the HttpSession means that
both call windows
will only sorted by the last known billId that was requested in the session.

I was thinking of Hidden parameters, but was unsure if that would work,
since was unsure
how and when to get/set them without a post.

It would be nice if there was some way to specify how the page (or maybe
components
aswell) could be persisted. Hence, could the renderer look at its component
hierarchy,
note that a parameter needed to be persisted on the URL, and ensure each
component
it contained (eg the DirectLink) would be rewritten to include the
parameter.Maybe the
persistent attribute could accept values of "URL" and "Cookie" ?

If anyone could suggest a workaround, that would be great, or let me know
I'm barking
up the wrong tree :)

I've included some source below:

Thanks

Brendan

BillList.java (method to display calls)
#########

    public void showBill(IRequestCycle cycle) {
        Object[] parameters = cycle.getServiceParameters();
        Long billId = (Long) parameters[0];
        Bill bill = getBillManager().getBill(billId);

        if (log.isDebugEnabled()) {
            log.debug("Selected billId: " + billId
           + " of type " + ((BillType)bill.getBillType()).getDescription());
        }

        if ( ((BillType)bill.getBillType()).getCode().equals("TEL") ) {
         CallList nextPage = (CallList) cycle.getPage("calls");
         nextPage.setBillId(billId);
         cycle.activate(nextPage);
        } else {
         if (log.isDebugEnabled()) {
                log.debug("Other page type");
            }
        }
    }

calls.page
#######

    <property-specification name="billId"  type="java.lang.Long"
persistent="yes"/>

    <property-specification name="callManager"
type="com.pionconsultants.service.CallManager">
        global.appContext.getBean("callManager")
    </property-specification>

    <component id="callFormTable" type="contrib:Table">

        <binding name="rowClass" expression="beans.evenOdd.next"/>
        <binding name="row" expression="row"/>
        <static-binding name="columns"
          value="
            call.dateTime:Date/Time:dateTime
           ,call.telephoneNo:Telephone No:telephoneNo
           ,call.type:Type:directory.callType.description
           ,call.dspDuration:Duration:dspDuration
           ,call.cost:Cost:cost/>
        <binding name="source"
expression="callManager.getCallsByBillId(billId)"/>
        <static-binding name="initialSortColumn" value="dateTime"/>
  <binding name="arrowUpAsset" expression="assets.upArrow"/>
        <binding name="arrowDownAsset" expression="assets.downArrow"/>
        <binding name="pageSize" expression="50"/>
        <binding name="pagesDisplayed" expression="20"/>
    </component>

calls.html
#######

<form jwcid="@Form" listener="ognl:listeners.formSubmit">

<!-- input type="hidden" jwcid="billId"/ -->
<input type="Submit" value="Update"/>
<button class="button" onclick="location.href='mainMenu.html'"><span
key="button.cancel"/></button>

<table jwcid="callFormTable" class="list callList" id="callList">
    <tr jwcid="call_callDateTimeColumnValue@Block">
            <span jwcid="@Insert" value="ognl:row.callDateTime"
format="ognl:dateTimeFormat"/>
    </tr>
    <tr jwcid="call_costColumnValue@Block">
            <span jwcid="@Insert" value="ognl:row.cost"
format="ognl:currencyFormat"/>
    </tr>
</table>

<input type="Submit" value="Update"/>
<button class="button" onclick="location.href='mainMenu.html'"><span
key="button.cancel"/></button>
</form>

CallList.java
#########

public abstract class CallList extends BasePage implements IExternalPage {

 private DateFormat _dateFormat;
 private DateFormat _dateTimeFormat;
 private NumberFormat _currencyFormat;

    public abstract CallManager getCallManager();
    public abstract void setCallManager(CallManager manager);
    public abstract void setBillId(java.lang.Long billId);
    public abstract java.lang.Long getBillId();

    public void activateExternalPage(Object[] parameters, IRequestCycle
cycle) {
     setBillId((Long) parameters[0]);
    }

    public void formSubmit(IRequestCycle cycle) {
     return;
    }

    public DateFormat getDateFormat()
    {
        if (_dateFormat == null)
            _dateFormat =
                DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
        return _dateFormat;
    }

    public DateFormat getDateTimeFormat()
    {
        if (_dateTimeFormat == null)
            _dateTimeFormat =
                DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.MEDIUM, getLocale());
        return _dateTimeFormat;
    }

    public NumberFormat getCurrencyFormat()
    {
        if (_currencyFormat == null)
         _currencyFormat =
                NumberFormat.getCurrencyInstance(getLocale());
        return _currencyFormat;
    }

}








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


Re: Question on sorting a contrib:Table and persistent parameters

Posted by Mind Bridge <mi...@yahoo.com>.
Your comments are very appropriate.

>Maybe the persistent attribute could accept values of "URL" and "Cookie" ?
>

That is _exactly_ what Tapestry 3.1 will do :). Unfortunately, that is 
still in development at the moment, and will take a while until it is 
usable.

Alas, at the moment you are more or less stuck with using a session. 
Hidden, combined with LinkSubmit, and FormTable's 
tableSessionStoreManager property (see my earlier post for details) is a 
possibility to do what you ask, but it won't be too straight-forward...

Brendan Wholihan wrote:

>Hi,
>
>Just started using Tapestry, and would be grateful for some help, just to
>check that I'm
>not "working against the framework" so to say. I've got a simple app up and
>running, based on
>Appfuse (excellent starter for Tapestry / hibernate / Spring, thanks Matt).
>
>Basically, I have two pages (bills and calls), each with a Table component
>in it. A row in bills
>can be clicked, to display the calls for that bill. This works and brings
>back the right data, but
>if I use the table component from the browser, say to sort a column on the
>calls page, it will
>loose the context of the billId that it has retrieved.
>
>I changed the bill page to use an external link, which passed the billId in
>the URL, to give,
>
>http://localhost:8080/app/calls.html?sp=l28
>
>and the sorting column URL on the table for example, is
>
>http://localhost:8080/app/calls.html?service=direct&service=1&service=contrib%3ASimpleTableColumnPage&service=tableColumnComponent.linkColumn&sp=Acalls%2FcallFormTable.tableView&sp=Scall.dateTime
>
>I noticed that the billId parameter on the URL is being lost. I then set
>billId as a persistent
>property of the page, and it worked. Unfortunately, after some reading, I
>realised that this
>meant the billId was being stored in the HttpSession. Is it possible to make
>the DirectLink
>of the Table component include the billId, and pass it back to the page?
>
>The reason I ask, is then I could open more than one call list from the bill
>page, by right
>clicking on each bill I wanted. Currently, using the HttpSession means that
>both call windows
>will only sorted by the last known billId that was requested in the session.
>
>I was thinking of Hidden parameters, but was unsure if that would work,
>since was unsure
>how and when to get/set them without a post.
>
>It would be nice if there was some way to specify how the page (or maybe
>components
>aswell) could be persisted. Hence, could the renderer look at its component
>hierarchy,
>note that a parameter needed to be persisted on the URL, and ensure each
>component
>it contained (eg the DirectLink) would be rewritten to include the
>parameter.Maybe the
>persistent attribute could accept values of "URL" and "Cookie" ?
>
>If anyone could suggest a workaround, that would be great, or let me know
>I'm barking
>up the wrong tree :)
>
>I've included some source below:
>
>Thanks
>
>Brendan
>
>BillList.java (method to display calls)
>#########
>
>    public void showBill(IRequestCycle cycle) {
>        Object[] parameters = cycle.getServiceParameters();
>        Long billId = (Long) parameters[0];
>        Bill bill = getBillManager().getBill(billId);
>
>        if (log.isDebugEnabled()) {
>            log.debug("Selected billId: " + billId
>           + " of type " + ((BillType)bill.getBillType()).getDescription());
>        }
>
>        if ( ((BillType)bill.getBillType()).getCode().equals("TEL") ) {
>         CallList nextPage = (CallList) cycle.getPage("calls");
>         nextPage.setBillId(billId);
>         cycle.activate(nextPage);
>        } else {
>         if (log.isDebugEnabled()) {
>                log.debug("Other page type");
>            }
>        }
>    }
>
>calls.page
>#######
>
>    <property-specification name="billId"  type="java.lang.Long"
>persistent="yes"/>
>
>    <property-specification name="callManager"
>type="com.pionconsultants.service.CallManager">
>        global.appContext.getBean("callManager")
>    </property-specification>
>
>    <component id="callFormTable" type="contrib:Table">
>
>        <binding name="rowClass" expression="beans.evenOdd.next"/>
>        <binding name="row" expression="row"/>
>        <static-binding name="columns"
>          value="
>            call.dateTime:Date/Time:dateTime
>           ,call.telephoneNo:Telephone No:telephoneNo
>           ,call.type:Type:directory.callType.description
>           ,call.dspDuration:Duration:dspDuration
>           ,call.cost:Cost:cost/>
>        <binding name="source"
>expression="callManager.getCallsByBillId(billId)"/>
>        <static-binding name="initialSortColumn" value="dateTime"/>
>  <binding name="arrowUpAsset" expression="assets.upArrow"/>
>        <binding name="arrowDownAsset" expression="assets.downArrow"/>
>        <binding name="pageSize" expression="50"/>
>        <binding name="pagesDisplayed" expression="20"/>
>    </component>
>
>calls.html
>#######
>
><form jwcid="@Form" listener="ognl:listeners.formSubmit">
>
><!-- input type="hidden" jwcid="billId"/ -->
><input type="Submit" value="Update"/>
><button class="button" onclick="location.href='mainMenu.html'"><span
>key="button.cancel"/></button>
>
><table jwcid="callFormTable" class="list callList" id="callList">
>    <tr jwcid="call_callDateTimeColumnValue@Block">
>            <span jwcid="@Insert" value="ognl:row.callDateTime"
>format="ognl:dateTimeFormat"/>
>    </tr>
>    <tr jwcid="call_costColumnValue@Block">
>            <span jwcid="@Insert" value="ognl:row.cost"
>format="ognl:currencyFormat"/>
>    </tr>
></table>
>
><input type="Submit" value="Update"/>
><button class="button" onclick="location.href='mainMenu.html'"><span
>key="button.cancel"/></button>
></form>
>
>CallList.java
>#########
>
>public abstract class CallList extends BasePage implements IExternalPage {
>
> private DateFormat _dateFormat;
> private DateFormat _dateTimeFormat;
> private NumberFormat _currencyFormat;
>
>    public abstract CallManager getCallManager();
>    public abstract void setCallManager(CallManager manager);
>    public abstract void setBillId(java.lang.Long billId);
>    public abstract java.lang.Long getBillId();
>
>    public void activateExternalPage(Object[] parameters, IRequestCycle
>cycle) {
>     setBillId((Long) parameters[0]);
>    }
>
>    public void formSubmit(IRequestCycle cycle) {
>     return;
>    }
>
>    public DateFormat getDateFormat()
>    {
>        if (_dateFormat == null)
>            _dateFormat =
>                DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
>        return _dateFormat;
>    }
>
>    public DateFormat getDateTimeFormat()
>    {
>        if (_dateTimeFormat == null)
>            _dateTimeFormat =
>                DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
>DateFormat.MEDIUM, getLocale());
>        return _dateTimeFormat;
>    }
>
>    public NumberFormat getCurrencyFormat()
>    {
>        if (_currencyFormat == null)
>         _currencyFormat =
>                NumberFormat.getCurrencyInstance(getLocale());
>        return _currencyFormat;
>    }
>
>}
>
>
>
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>  
>



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.8 - Release Date: 2/14/2005


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