struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Giovanni Azua <g...@imc.nl>
Subject best choice for this use case ... ?
Date Mon, 03 Dec 2007 13:11:03 GMT
hi,

I have the following use-case -I think should be pretty common- and 
would like to
know what would be the best design choice:

- There is a form that contains an autocompleter field filled with all 
stock indexes.
- In the same form there are other dependent input values displayed e.g. 
exchange
  rate that correspond to the selected index.
- Initially the input action makes sure the  dependent fields are 
correctly populated
  i.e. they match the initially selected index.

Now when the user changes the index selection, some of the form fields
must also be updated to be consistent with the new selection.

These are the two design choices I have found using ajax so far:

1-. Have the master field index publish a topic and have the dependent 
fields listen
     to that topic and trigger the execution of an action. The problem I 
encountered
     here is that:
         a) The request parameters e.g. historicBook0 are empty, don't 
know how to
             push them to the action, I could use javascript directly to 
encode it but not sure
             if this could lead to race conditions i.e. how will the 
javascript ensure to execute
             before the topic publication triggers execution of the action.
         b) The widget autocompleter seem not to understand the result 
of the action. I tried
              using the json plugin and having a getter of the action 
match the widget name but
              does not work ...

Below find the not working sources with the problems described above.

2-. The second choice is using JSON RPC with javascript directly but 
this approach
though viable seems rather frameworkless i.e. hacky to me.

My gut feeling is that solution #1 is the one but just don't know how to 
solve those
issues.

TIA,
regards,
Giovanni

************** struts.xml *********************

<package name="remote"  extends="json-default">
    <action name="Remote*" 
class="com.sag.optimizer.ui.web.action.remote.Remote{1}Action">
       <result type="json"/>           
    </action>      
</package>

************* mypage.jsp *********************

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>

<s:url var="exchangeRates" action="RemoteExchangeRates.action" />

<s:form id="formAngleAlgoConfSimulation" action="%{targetAction}" 
method="post" theme="%{currentTheme}">
    <sx:autocompleter tooltip="Provide the first Historic Book" 
valueNotifyTopics="/changedHistoricBook0" searchType="substring" 
label="Historic Book 1" cssStyle="width: 250px;" dropdownHeight="180" 
name="historicBook0" list="historicBooks" listKey="id" listValue="name" 
/>       
    ...
    <sx:autocompleter tooltip="Provide the Currency Rate 1" 
href="%{#exchangeRates}" autoComplete="false" preload="false" 
listenTopics="/changedHistoricBook0" label="Currency Rate 1" 
showDownArrow="false" cssStyle="width: 250px;" name="eurosPerListedUnit0" />
    ...
    <s:submit value="%{buttonLabel}" align="center"/>
</s:form>
 
*********** Action ***************************

/**
 * Determines the exchange rates for a Historic book pair
 */
public
class RemoteExchangeRatesAction
extends ActionSupport
{
    
//------------------------------------------------------------------------
    // public
    
//------------------------------------------------------------------------
    /**
     * @return the eurosPerListedUnit0
     */
    public final double
    getEurosPerListedUnit0()
    {
         return calculateFxRate(theHistoricBook0Key);
    }

    
//------------------------------------------------------------------------
    /**
     * @return the eurosPerListedUnit1
     */
    public final double
    getEurosPerListedUnit1()
    {       
        return calculateFxRate(theHistoricBook1Key);
    }

    
//------------------------------------------------------------------------
    /**
     * @param aHistoricBook0Key the historicBook0Key to set
     */
    public final void
    setHistoricBook0Key(String aHistoricBook0Key)
    {
        theHistoricBook0Key = aHistoricBook0Key;
    }

    
//------------------------------------------------------------------------
    /**
     * @param aHistoricBook1Key the historicBook1Key to set
     */
    public final void
    setHistoricBook1Key(String aHistoricBook1Key)
    {
        theHistoricBook1Key = aHistoricBook1Key;
    }
       
    
//------------------------------------------------------------------------
    // members
    
//------------------------------------------------------------------------
    private String theHistoricBook0Key;
    private String theHistoricBook1Key;
}


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


Mime
View raw message