RichFaces AJAX 调用后 h:outputLabel 的长度发生变化

发布于 2024-11-07 02:13:03 字数 1757 浏览 2 评论 0原文

我一直在尝试将 RichFaces 合并到我们的一个较复杂的页面中,以使其通过 AJAX 运行得更流畅。一切工作正常,它解决了我使用常规表单帖子时遇到的一些问题,所以我真的很想保留它。我遇到的唯一问题是,按下 a4j:commandButton 后,我的大部分 h:outputLabel 都缩短了 3 个像素(这些像素位于文本的左侧) ,这是不寻常的,因为左内边距、边距和边框宽度都是 0px)。这导致我的许多控件发生轻微变化,看起来非常不专业。在我看来,重新渲染比初始渲染完成了更准确的工作。以下是我的页面的相关部分:

<a4j:form id="mainForm">
    ...
    <fieldset id="illustrationDetails">
        <h:outputLabel for="product" value="Product" />
        <h:selectOneMenu id="product" value="#{illustrationManager.illustration.product}" valueChangeListener="#{illustrationManager.illustration.setProduct}" onchange="submit()">
            <f:selectItems value="#{illustrationManager.illustration.products}" />
        </h:selectOneMenu>
        <h:outputLabel for="paymentFrequency" value="Payment" />
        <h:selectOneMenu id="paymentFrequency" value="#{illustrationManager.illustration.paymentFrequency}">
            <f:selectItems value="#{illustrationManager.illustration.paymentFrequencies}" />
        </h:selectOneMenu>
        <h:outputLabel for="expenseGroup" value="Expense Group" />
        <h:selectOneMenu id="expenseGroup" value="#{illustrationManager.illustration.expenseGroupId}">
            <f:selectItems value="#{illustrationManager.illustration.expenseGroups}" />
        </h:selectOneMenu>
    </fieldset>
    ...
    <a4j:commandButton id="calculateButton" value="Calculate" action="#{illustrationManager.calculatePremium()}" ajaxSingle="true" reRender="mainForm" />
    ...
</a4j:form>

在上面的字段集中,除了第一个标签之外的所有标签都表现出此问题。第一个标签通过初始渲染呈现出我认为正确的内容(左侧没有像素),因此重新渲染不会改变第一个标签。

欢迎任何建议!另外,如果您想要更多信息,例如相关控件的 css,请告诉我,我会发布它。

I have been trying to incorporate RichFaces into one of our more complicated pages to make it run a bit more smoothly via AJAX. Everything is working fine and it has solved a few problems I was having using regular form posts so I'd really like to keep it. The only problem in my way is that after pressing an a4j:commandButton most of my h:outputLabels are shortened by 3 pixels (these pixels were to the left of the text, which is unusual since the left padding, margin and border width are all 0px). This causes lots of my controls to shift slightly and looks very unprofessional. It looks to me like the re-rendering has done a more accurate job than the initial render. Here are the relevant parts of my page:

<a4j:form id="mainForm">
    ...
    <fieldset id="illustrationDetails">
        <h:outputLabel for="product" value="Product" />
        <h:selectOneMenu id="product" value="#{illustrationManager.illustration.product}" valueChangeListener="#{illustrationManager.illustration.setProduct}" onchange="submit()">
            <f:selectItems value="#{illustrationManager.illustration.products}" />
        </h:selectOneMenu>
        <h:outputLabel for="paymentFrequency" value="Payment" />
        <h:selectOneMenu id="paymentFrequency" value="#{illustrationManager.illustration.paymentFrequency}">
            <f:selectItems value="#{illustrationManager.illustration.paymentFrequencies}" />
        </h:selectOneMenu>
        <h:outputLabel for="expenseGroup" value="Expense Group" />
        <h:selectOneMenu id="expenseGroup" value="#{illustrationManager.illustration.expenseGroupId}">
            <f:selectItems value="#{illustrationManager.illustration.expenseGroups}" />
        </h:selectOneMenu>
    </fieldset>
    ...
    <a4j:commandButton id="calculateButton" value="Calculate" action="#{illustrationManager.calculatePremium()}" ajaxSingle="true" reRender="mainForm" />
    ...
</a4j:form>

In the fieldset above, all but the first label exhibit this problem. The first label is rendered what I would consider to be correctly (with no pixels to the left) by the initial render and as a result is not changed by the re-render.

Any suggestions would be welcome! Also, if you want more info like the css for the relevant controls let me know and I'll post it.

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

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

发布评论

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

评论(1

没︽人懂的悲伤 2024-11-14 02:13:03

好吧,无论如何,这只是部分答案。 h:outputLabel 左侧有 3 个像素是因为 Mojarra JSF 实现在 标签的开头添加了一个 \n 字符它创建的 标签主体。我和提交这个错误的人一样困惑,为什么这是这样的完毕。 \n 在显示时会转换为空格,这就是我的 3 个像素。

我不知道为什么,但我的 RichFaces AJAX 调用触发的重新渲染会删除这些 \n 字符,因此不再显示空间。

作为解决方法,我已明确在所有标签的前面放置空格,以便始终显示空格。我很惊讶这不是一个常见问题。

Well, this is a partial answer anyway. The 3 pixels to the left of the h:outputLabels was due to the fact that the Mojarra JSF implementation adds a \n character to the beginning of the label tag body it creates. I'm as baffled as the guy who submitted this bug about it as to why this is done. The \n is converted to a space when displayed and that's what my 3 pixels were.

I do not know why, but the re-render triggered by my RichFaces AJAX call removes these \n characters and so the space is no longer displayed.

As a workaround, I have explicitly put spaces at the front of all my labels so that a space is always displayed. I'm surprised this is not a common problem.

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