I have two jsp files as follow:
myform.jsp
<%@ page contentType='text/html; charset=UTF-8' errorPage='' %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:form id="myform" name="myform" namespace="/" theme='simple' action='createPage' method='post'>
<table width='100%'>
<tr>
<td>
<table width='100%'>
<s:select id='parameterDataType' name='parameterDataType' theme="xhtml" required="true" key='param.datatype' list='#application.myList' emptyOption="true" listKey='listKey' listValue='listValue'/>
</table>
<table width='100%'>
<s:if test="parameterDataType != null">
<tr id='defParameterDefaultValue'>
<td class="tdLabel" >
<s:label cssClass="label" key="param.value"/></td>
<td ><%@ include file='/pages/datatypes.jsp' %></td>
</tr>
</s:if>
</table>
</td>
</tr>
</table>
</s:form>
<script language='JavaScript' type='text/JavaScript'>
<s:url id="reloadPage" namespace="/" action="reloadPage" />
function reloadPage()
{
var form = document.forms[0];
form.action = '<s:property value="reloadPage"/>';
form.action += '?parameterDefaultValue=';
form.submit();
}
$("#parameterDataType").change(function()
{
reloadPage();
});
</script>
and
datatype.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<s:if test="parameterDataType == 'CODE' ">
<s:textfield id='parameterDefaultValue' name='parameterDefaultValue' theme="simple" size='27'/>
</s:if>
<s:if test="parameterDataType == 'DATE' ">
<sj:datepicker id='parameterDefaultValue' name='parameterDefaultValue' parentTheme="simple" displayFormat="%{session.sessionAttr.pref.dateDisplayformat}" appendText="%{session.sessionAttr.pref.dateAppendText}" changeMonth="%{session.sessionAttr.pref.changeMonth}" changeYear="%{session.sessionAttr.pref.changeYear}"/>
</s:if>
<s:if test="parameterDataType == 'BUSINESS_UNIT' ">
<s:select id='parameterDefaultValue' name='parameterDefaultValue' theme="simple" list='#session.businessUnitSelectList' listKey='id' listValue='name' emptyOption='true' />
</s:if>
<s:if test="parameterDataType == 'TERM' ">
<s:select id='parameterDefaultValue' name='parameterDefaultValue' theme="simple" list='#session.termList' listKey='id' listValue='description' emptyOption='true' />
</s:if>
and an action class method
public String reloadPage()
{
return SUCCESS;
}
My aim is to display the a field in the datatype.jsp based on the value selected in myform.jsp.
When a user for example selects CODE from the myform.jsp select, the page reloads to include the datatype.jsp. If i use the property tag i.e.
<s:property value="parameterDataType" />
to print the value of parameterDataType in the datatype.jsp, i get the value CODE but it never enters the if statement.
Please is there anything that i am doing wrong? if there is a better way of achieving this, i will appreciate it.
I later solved the issue using a similar technique i got on this site
thanks for your responses