【问题标题】:jodd cannot sent response to viewjodd 无法发送对视图的响应
【发布时间】:2019-12-28 15:37:28
【问题描述】:

我有一个使用 joy-5.0.13 构建的应用程序,我无法将一些变量值发送到要在屏幕上呈现的模板。我敢肯定,我现在缺少一些简单的东西。
这是我的行动:

@MadvocAction
public class IndexAction {

    @PetiteInject
    private TemperatureService temperatureService;

    @Out
    List<TemperatureLog> temps;

    @Action    
    public void view() {        
        temps = temperatureService.getLastHoutTemperatures();       
        System.out.println(temps);      
    }

这就是名为 index.jsp 的文件

<%@ taglib prefix="j" uri="/jodd" %>
<html>
<head>
    <title>SmartHome</title>
</head>
<body>

    <j:iter items="${temps}" var="tl">
         ${tl.temperature}<br/>
    </j:iter>   

</body>
</html>  

这是来自控制台的日志:

80281 [DEBUG] j.m.c.MadvocController.invoke:102 - Action path: GET /index
80281 [DEBUG] j.m.c.MadvocController.invoke:125 - Invoke action for '/index' using    ro.videanuadrian.sh.action.IndexAction#view
80291 [DEBUG] j.j.i.LocalizationUtil.setRequestBundleName:78 - Bundle name for this request: ro.videanuadrian.sh.action.IndexAction
80297 [DEBUG] j.j.JtxTransactionManager.requestTransaction:272 - Requesting TX jtx{Required,readonly,Read Committed,-1}
80299 [DEBUG] j.j.JtxTransaction.<init>:102 - New JTX {status:Active, mode:jtx{Required,readonly,Read Committed,-1}}
80321 [DEBUG] j.d.j.DbJtxSessionProvider.getDbSession:57 - Requesting db TX manager session
80322 [DEBUG] j.d.DbSession.<init>:60 - Creating new db session
80323 [DEBUG] j.d.j.DbJtxResourceManager.beginTransaction:71 - begin jtx
80325 [DEBUG] j.d.DbSession.beginTransaction:242 - Beginning transaction
80325 [DEBUG] j.d.p.CoreConnectionPool.getConnection:256 - Returning valid pooled connection
80443 [DEBUG] j.d.DbQueryBase.execute:686 - Executing statement: SELECT tt.id, tt.sensor_id, tt.temperature, tt.timestamp FROM sh_temperature_log tt  WHERE tt.timestamp>1577460508000 ORDER BY tt.id ASC
80503 [DEBUG] j.d.DbQueryBase.execute:704 - execution time: 70ms
80526 [DEBUG] j.j.w.LeanJtxWorker.maybeCommitTransaction:93 - commit tx
80526 [DEBUG] j.j.JtxTransaction.commitOrRollback:255 - Commit JTX
80526 [DEBUG] j.d.j.DbJtxResourceManager.commitTransaction:83 - commit jtx
80526 [DEBUG] j.d.DbSession.commitTransaction:254 - Committing transaction
80614 [DEBUG] j.d.DbSession.closeSession:84 - Closing db session
[TemperatureLog [sensorId=1, timestamp=1577535822000, temperature=23.0], TemperatureLog [sensorId=1, timestamp=1577535826000, temperature=24.0], TemperatureLog [sensorId=1, timestamp=1577535829000, temperature=25.0], TemperatureLog [sensorId=1, timestamp=1577535844000, temperature=26.5]]
80623 [DEBUG] j.m.c.MadvocController.render:202 - Result type: ServletDispatcherActionResult
80623 [DEBUG] j.m.r.AbstractTemplateViewActionResult.render:91 - new target: /index:
80623 [DEBUG] j.m.r.ServletDispatcherActionResult.targetExists:105 - target check: /index.jspf
80624 [DEBUG] j.m.r.ServletDispatcherActionResult.targetExists:105 - target check: /index.jsp
80625 [DEBUG] j.m.r.AbstractTemplateViewActionResult.render:102 - target found: /index.jsp  

但在视图中我只得到: ${tl.温度}

这就像它没有到达视图引擎的结果。我进行了一些调试,似乎 actionResult 为空。

知道我做错了什么吗?

谢谢

附:我已经尝试过toturial,但我遇到了同样的问题:

Messages

${msg.messageId} ${msg.text}
    ${resp.responseId} ${resp.text}

new message...

REST APi: message 1  

这是我的输出

【问题讨论】:

  • 您是否尝试过使用不同的 taglib 进行迭代?看起来j:iter 的主体没有被评估(这是一个问题)。我稍后会尝试重现。
  • 嗨,Igor,我有t tried to use other taglib. Ill 检查并告诉你

标签: jodd


【解决方案1】:

这应该可行。这是一个工作示例:

@MadvocAction
public class FooAction {
    @Out
    List<Integer> temps;

    @Action
    public void view() {
        temps = new ArrayList<>();
        temps.add(30);
        temps.add(20);
        System.out.println(temps);
    }
}

此操作映射到/foo。这个很重要!您需要调用该操作,而不是浏览器中的 .jsp。我的foo.jsp 代码看起来像你的:

Temperatures:
<j:iter items="${temps}" var="tl">
    ${tl}<br/>
</j:iter>

所以,它确实应该有效。

也许您可以使用 Jodd-Joy:它是一个预定义的 Jodd 捆绑包。它在开头很好地显示了链接列表,如下所示:

如果您愿意,可以将您的代码/示例发给我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    • 2020-10-21
    • 2018-08-29
    • 1970-01-01
    相关资源
    最近更新 更多