我正在将dataTable(绑定dataList)导出到excel文件,调用以下方法 xlsWorkBookPrepare("c:\\export.xls");
方法的一部分:
public void xlsWorkBookPrepare(String file) throws IOException
{
/* prepare of workbook */
Workbook wb = new HSSFWorkbook();
Map<String, CellStyle> styles = Style.createStyles(wb);
...
for (FoodList item : dataList)
{
...
}
/* create file */
FileOutputStream fileOut;
try
{
fileOut = new FileOutputStream(file);
wb.write(fileOut);
fileOut.flush();
fileOut.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
但路径与服务器有关.如何将它保存在客户端?
解决方案(基于Rangi Lin的回答):
HttpServletResponse res = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
res.setContentType("application/vnd.ms-excel");
res.setHeader("Content-disposition", "attachment; filename=test.xls");
try
{
ServletOutputStream fileOut = res.getOutputStream();
wb.write(fileOut);
fileOut.flush();
fileOut.close();
}
catch …Run Code Online (Sandbox Code Playgroud) 我可以在定义的不活动时间后注销用户。
<session-timeout>240</session-timeout>
Run Code Online (Sandbox Code Playgroud)
但是,是否有某种方法可以在指定时间或更好的情况下注销,例如直到指定时间后 5 分钟不活动。?
我有<h:inputText>表格,我需要的是从BLUR事件上的辅助bean执行一些方法:
public void test()
{
System.out.print("HELLO!");
}
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗?
我有跟随xhtml文件vith rich:calendar,我试图使用这个例子禁用一些天.但javascript函数永远不会被调用.我不知道为什么.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html ... >
<f:view locale="en">
<script type="text/javascript">
function isDayEnabled(day){
var date = new Date(day.date);
return (date.getDay() == 6);
}
function getDisabledStyle(day){
if (!isDayEnabled(day)) return 'rich-calendar-boundary-dates disabledDay';
}
</script>
<h:head>
<style type="text/css">
.disabledDay { background-color:gray; }
</style>
</h:head>
<h:body>
<div id="workspace">
<h:form id="form">
<h:outputText value="Datum: " />
<rich:calendar mode="ajax" id="calendar"
isDayEnabled="isDayEnabled();" dayStyleClass="getDisabledStyle();">
</rich:calendar>
....
Run Code Online (Sandbox Code Playgroud)
你可以帮帮我吗?
我能够为"where"限制条件设置变量值:
Query criteria = session.createQuery(
"select test.col1, test.col2, test.col3
"from Test test " +
"where test.col = :variableValue ");
criteria.setInteger("variableValue", 10);
Run Code Online (Sandbox Code Playgroud)
但是可以像这样设置变量列吗?
String variableColumn = "test.col1";
Query criteria = session.createQuery(
"select test.col1, test.col2, test.col3
"from Test test " +
"where :variableColumn = :variableValue ");
criteria.setInteger("variableValue", 10);
criteria.setString("variableColumn", variableColumn);
Run Code Online (Sandbox Code Playgroud)
这是结果:
Exception in thread "main" Hibernate: select .... where ?=? ...
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
...
at _test.TestCriteria.main(TestCriteria.java:44)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Conversion failed when converting the nvarchar value 'test.col1' …Run Code Online (Sandbox Code Playgroud) 我正在以这种方式创建错误消息:
public static void setErrorMessage(String errorMessage) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(errorMessage));
}
Run Code Online (Sandbox Code Playgroud)
并在出现错误时将其显示在表格上(红色):
<h:messages styleClass="error"/>
Run Code Online (Sandbox Code Playgroud)
如何在JSF中分离错误和成功消息?简单地说,如何以绿色显示正面信息,以红色显示否定信息?
如果检查列为IS NULL,是否可以显示来自另一列的数据?
例如:
Color,OriginalColor表:TableColors [Color, OriginalColor]
[W,B] [,G] [B,Y]
而且
SELECT CASE WHEN Color IS NULL "extract the data from OriginalColor"
FROM TableColors
Run Code Online (Sandbox Code Playgroud)
应该得到以下列表:W,G,B
我有两个字符串,例如:
str1 = "aaabbbcccdddeee" str2 = "aaabbbccc" 如何做到像str1 - str2获取dddeee子串?