即时写表

发布于 2024-08-15 06:49:04 字数 837 浏览 5 评论 0原文

我有以下功能,我想写入页面而不是 println。我怎样才能做到这一点?我的页面中需要一个包含该信息的表格,但我没有找到任何相关信息,我看到了如何将集合写入页面,但我更喜欢动态写入页面。

预先感谢您的回复。

def tablaAmortizacion(xhtml:NodeSeq,monto:Double,amort:Double,start:java.util.Calendar) {
    var formatter = new java.text.SimpleDateFormat("dd/MM/yyyy")
    var end = new java.util.GregorianCalendar()
    end.setTime(start.getTime)
    end.add(java.util.Calendar.MONTH,1)
    var difference = Math.abs(start.getTimeInMillis - end.getTimeInMillis)
    var days = difference / (1000 * 60 * 60 * 24)

    println("Monto sal: " + monto + "   Amortizacion: " + amort + "   Start: " + formatter.format(start.getTime)  + "   End: " + formatter.format(end.getTime) + "   Days: " + days)

    if (monto > amort) {
        tablaAmortizacion(xhtml,monto-amort,amort,end)
    }

}

费尔南多·阿瓦洛斯.

I have the following function, and I would like to write to the page instead of the println. How can I do that? I need a table with that information in my page, But I did't find any information about that, I saw how to write collections to the page, but I would rather prefer write to the page on the fly.

Thanks in advance and I hope for your response.

def tablaAmortizacion(xhtml:NodeSeq,monto:Double,amort:Double,start:java.util.Calendar) {
    var formatter = new java.text.SimpleDateFormat("dd/MM/yyyy")
    var end = new java.util.GregorianCalendar()
    end.setTime(start.getTime)
    end.add(java.util.Calendar.MONTH,1)
    var difference = Math.abs(start.getTimeInMillis - end.getTimeInMillis)
    var days = difference / (1000 * 60 * 60 * 24)

    println("Monto sal: " + monto + "   Amortizacion: " + amort + "   Start: " + formatter.format(start.getTime)  + "   End: " + formatter.format(end.getTime) + "   Days: " + days)

    if (monto > amort) {
        tablaAmortizacion(xhtml,monto-amort,amort,end)
    }

}

Fernando Avalos.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再让梦枯萎 2024-08-22 06:49:04

或者您可以执行类似的操作,在方法中生成表。

def list = <table>
<thead>
<tr>
    <th>monto-amort</th>
    <th>amort</th>
    <th>end</th>
    <th/>
</tr>
</thead>
<tbody>
  {generateTableBody()}
</tbody>

def generateTableBody = {
//calculate values here.
<tr><td>{monto-amort}</td><td>{amort}</td><td>{end}</td></tr>
}

Or you can do something like this where you generate the table in the method.

def list = <table>
<thead>
<tr>
    <th>monto-amort</th>
    <th>amort</th>
    <th>end</th>
    <th/>
</tr>
</thead>
<tbody>
  {generateTableBody()}
</tbody>

def generateTableBody = {
//calculate values here.
<tr><td>{monto-amort}</td><td>{amort}</td><td>{end}</td></tr>
}
悍妇囚夫 2024-08-22 06:49:04

我不确定你的意思是写入页面。您的意思是要在渲染后将表格动态添加到页面吗?
如果您指的是 ajax 方式,您应该查看 comet 聊天应用程序。

或者你的意思是你想要某种像 jsp/jsf 页面那样的表达语言?
如果您的意思是 jsp/jsf 页面,那么答案是您不能,根据设计。如果您需要动态生成 html,请在代码片段中执行此操作,而不是在 xhtml 中。

答案如下:
在你的 xhtml 文件中,你可以有类似的内容:

<table>
    <thead>
    <tr>
        <th>First Name</th>
        <th>Middle Name</th>
        <th>Last Name</th>
        <th/>
    </tr>
    </thead>
    <tbody>
    <lift:PersonSnippets.list>
        <tr>
            <td>
                <party:firstName/>
            </td>
            <td>
                <party:middleName/>
            </td>
            <td>
                <party:lastName/>
            </td>
            <td>
                <party:edit/>
                <party:delete/>
            </td>
        </tr>
    </lift:PersonSnippets.list>
    </tbody>
</table>

然后你的代码片段看起来像:

def list(xhtml: NodeSeq): NodeSeq = {

val people = Model.createNamedQuery[Person]("findAllPeople").getResultList()

people.flatMap(person =>
        bind("party", xhtml,
          "firstName" -> Text(person.getFirstName()),
          "middleName" -> Text(person.getMiddleName()),
          "lastName" -> Text(person.getLastName()),
          "edit" -> link("/contact/person/edit", () => personVar(person), Text(?("Edit"))),
          "delete" -> link("/contact/person/delete", () => personVar(person), Text(?("Delete")))
          ))

}

I'm not sure what you mean write to the page. Do you mean you want to dynamically add your table to the page after it's rendered?
If you mean in an ajax kind of way, you should look at the comet chat app.

Or do you mean you want some sort of expression language like jsp/jsf pages do?
If you mean like jsp/jsf pages, the answer is you can't, by design. If you need to dynamically generate html, you do that in your snippet, not in the xhtml.

here's the answer:
In your xhtml file you can have something like:

<table>
    <thead>
    <tr>
        <th>First Name</th>
        <th>Middle Name</th>
        <th>Last Name</th>
        <th/>
    </tr>
    </thead>
    <tbody>
    <lift:PersonSnippets.list>
        <tr>
            <td>
                <party:firstName/>
            </td>
            <td>
                <party:middleName/>
            </td>
            <td>
                <party:lastName/>
            </td>
            <td>
                <party:edit/>
                <party:delete/>
            </td>
        </tr>
    </lift:PersonSnippets.list>
    </tbody>
</table>

Then your snippet looks like:

def list(xhtml: NodeSeq): NodeSeq = {

val people = Model.createNamedQuery[Person]("findAllPeople").getResultList()

people.flatMap(person =>
        bind("party", xhtml,
          "firstName" -> Text(person.getFirstName()),
          "middleName" -> Text(person.getMiddleName()),
          "lastName" -> Text(person.getLastName()),
          "edit" -> link("/contact/person/edit", () => personVar(person), Text(?("Edit"))),
          "delete" -> link("/contact/person/delete", () => personVar(person), Text(?("Delete")))
          ))

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文