I managed to have it working, sources are below. By the way, I do not
understand why the selected values in the combos are not submited (I have to
use some input hidden in the form...) any tip?
Hope it helps.
@Musachy : thanks for the link but I have problems to use most of the 2.1
examples.
@Dave : i'm struts 2 noob and still don't figure out clearly how to adapt a
pure dojo example to struts-dojo.
struts.xml
==============
<action name="handleSelectActionAjax"
class="org.rca.conticabase.web.action.MultiSelectAction"
method="handleSelect">
<result>/WEB-INF/components/multiSelect.jsp</result>
</action>
<action name="submitSelectAction"
class="org.rca.conticabase.web.action.MultiSelectAction"
method="handleSubmit">
<result>/WEB-INF/pages/ajaxPage.jsp</result>
</action>
==============
MultiSelectAction.java
==============
public class MultiSelectAction extends ActionSupport {
private static final long serialVersionUID = -4617365382177316987L;
private String firstSelectValue;
private String secondSelectValue;
private String thirdSelectValue;
private List<String> secondList;
private List<String> thirdList;
private String message;
public String getFirstSelectValue() {
return firstSelectValue;
}
public void setFirstSelectValue(String s) {
this.firstSelectValue = s;
}
public List<String> getSecondList() {
return secondList;
}
public void setSecondList(List<String> l) {
this.secondList = l;
}
public String getSecondSelectValue() {
return secondSelectValue;
}
public void setSecondSelectValue(String s) {
this.secondSelectValue = s;
}
public List<String> getThirdList() {
return thirdList;
}
public void setThirdList(List<String> l) {
this.thirdList = l;
}
public String getThirdSelectValue() {
return thirdSelectValue;
}
public void setThirdSelectValue(String s) {
this.thirdSelectValue = s;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String handleSelect() throws Exception{
if
(ServletActionContext.getServletContext().getAttribute("firstList") ==
null){
ArrayList<String> firstList = new ArrayList<String>();
firstList.add("1");
firstList.add("2");
firstList.add("3");
ServletActionContext.getServletContext().setAttribute("firstList",
firstList);
}
if (getFirstSelectValue() != null &&
!getFirstSelectValue().equals("")) {
secondList = new ArrayList<String>();
secondList.add(getFirstSelectValue() + "-1");
secondList.add(getFirstSelectValue() + "-2");
}
if (getSecondSelectValue() != null &&
!getSecondSelectValue().equals(""))
{
thirdList = new ArrayList<String>();
thirdList.add(getSecondSelectValue() + "-1");
thirdList.add(getSecondSelectValue() + "-2");
}
return SUCCESS;
}
public String handleSubmit() throws Exception{
message = "your choice: '" + firstSelectValue + "'"
+ ", '" + secondSelectValue + "'"
+ ", '" + thirdSelectValue + "'";
return SUCCESS;
}
}
==============
multiSelect.jsp
==============
<%@ include file="/common/taglibs.jsp"%>
<s:if test="%{#application.firstList != null}">
<s:select label="Level 1" id="firstSelect"
list="%{#application.firstList}"
emptyOption="true" cssStyle="width: 100px;"
onchange="handleSelect(this);" value="firstSelectValue"/>
</s:if>
<s:if test="secondList != null">
<s:select label="Level 2" id="secondSelect" list="secondList"
emptyOption="true" cssStyle="width: 100px;"
onchange="handleSelect(this);" value="secondSelectValue"/>
</s:if>
<s:if test="thirdList != null">
<s:select label="Level 3" id="thirdSelect" list="thirdList"
emptyOption=" true" cssStyle="width: 100px;"
value="thirdSelectValue"/>
</s:if>
==============
ajaxPage.jsp
==============
<%@ include file="/common/taglibs.jsp" %>
<head>
<s:head theme="ajax"/>
</head>
<h3>page: <%= new java.util.Date() %></h3>
<s:include value="/WEB-INF/components/ajaxDiv.jsp" />
<br/>
<div class="separator"></div>
<br/>
<script>
function handleSelect(select) {
document.multiSelectForm.firstSelectValue.value =
document.multiSelectForm.firstSelect.value;
if (select.id == 'firstSelect'){
document.multiSelectForm.secondSelectValue.value = null;
document.multiSelectForm.thirdSelectValue.value = null;
try{
document.multiSelectForm.secondSelect.value = null;
document.multiSelectForm.thirdSelect.value = null;
}
catch(err){}
}
else{
document.multiSelectForm.secondSelectValue.value =
document.multiSelectForm.secondSelect.value;
}
dojo.event.topic.publish('handleSelectTopic');
}
function handleSubmit() {
try{
document.multiSelectForm.firstSelectValue.value =
document.multiSelectForm.firstSelect.value;
document.multiSelectForm.secondSelectValue.value =
document.multiSelectForm.secondSelect.value;
document.multiSelectForm.thirdSelectValue.value =
document.multiSelectForm.thirdSelect.value;
}
catch(err){
// second or third list not present
}
}
</script>
<s:form id="multiSelectForm" name="multiSelectForm" theme="simple"
onsubmit="handleSubmit();">
<s:hidden name="firstSelectValue" />
<s:hidden name="secondSelectValue" />
<s:hidden name="thirdSelectValue" />
<s:url id="handleSelectUrl" action="handleSelectActionAjax" />
<s:div id="multiSelectDiv" href="%{handleSelectUrl}" theme="ajax"
listenTopics="handleSelectTopic" formId="multiSelectForm"
showLoadingText="false">
</s:div>
<br/>
<s:submit value="Submit" action="submitSelectAction"/>
<br/>
submited selection : ${message != null ? message : ''}
</s:form>
--
View this message in context:
http://www.nabble.com/dependant-%3Cs%3Aselect%3E-updated-with-ajax-%3A-how--tp15616529p15708830.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]