  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | best choice for this use case ... ? | best choice for this use case ... ? 2007-12-03 - By Giovanni Azua
Back 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 (See http://UTF-8.ora-code.com)"%> <%@ 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 //-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- /** * @(protected) the eurosPerListedUnit0 */ public final double getEurosPerListedUnit0() { return calculateFxRate(theHistoricBook0Key); }
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- /** * @(protected) the eurosPerListedUnit1 */ public final double getEurosPerListedUnit1() { return calculateFxRate(theHistoricBook1Key); }
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- /** * @(protected) aHistoricBook0Key the historicBook0Key to set */ public final void setHistoricBook0Key(String aHistoricBook0Key) { theHistoricBook0Key = aHistoricBook0Key; }
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- /** * @(protected) 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@(protected) For additional commands, e-mail: user-help@(protected)
|
|
 |