Hello,
we are changing few pages (realized via servlets only) to madvoc.
After setting up madvoc itself successfully, the first issue occurs.
In the jsp-page you can write a sql statement and choice output format (csv,html).
By hitting the form button , method will be executed in Action class.
The question is: Is it possible to display the result as html table or as cvs-download-file within one action method?
Code snippets:
sql.jsp
<jodd-lagarto:form>
<form id="form" method="post" action="sql.executeSql">
<fieldset><legend>SQL</legend>
<label>Statement:<br />
<textarea name="sql" cols="100" rows="5">${sqlResult.sql}</textarea></label>
<br />
<label>output format:
<select name="format" size="1">
<jodd:iter items="${outputTypes}" var="i">
<jodd:ifelse test="${format == i}">
<jodd:then>
<option selected>${i}</option>
</jodd:then>
<jodd:else>
<option>${i}</option>
</jodd:else>
</jodd:ifelse>
</jodd:iter>
</select>
</label>
<br />
<button type="submit" name="submit">Go</button>
</fieldset>
</form>
</jodd-lagarto:form>
SqlAction.java
@MadvocAction
public class SqlAction {
@Action(method = "POST", extension = Action.NONE)
public String executeSql() {
// cut of business logic (execute sql, set result in model class)
return "#";
}
}
Showing data within html table works.
I struggle with downloading cvs file.
Within old servlet code i have used :
response.setHeader("Content-Type", "text/csv");
response.setHeader("Content-Disposition", "attachment; filename=\"sql.csv\"");
out.println(csvstringwriter.getBuffer().toString());
Should i use two action methods? One for html output, other for csv file - mybe with "RawDownload"
I can change the action attribute of the html form via javascript....
Thank you for your hints / help!
Greetz
Sascha