You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PrimeFaces 4.0:设置inplace组件默认无需点击即可编辑

Make PrimeFaces 4.0 p:inplace Editable on Page Load

Got it, let's get your p:inplace component to switch directly to edit mode as soon as the page loads. Here's how to do it in PrimeFaces 4.0:

Step 1: Add a widgetVar to your inplace component

First, assign a widgetVar attribute to your p:inplace so we can access its client-side API. This lets us trigger the edit mode via JavaScript:

<p:inplace id="ajax" editor="true" widgetVar="inplaceAjax">
    <p:inputText value="#{inplaceView.text}" required="true" label="text" />
</p:inplace>

Step 2: Trigger edit mode on page load

PrimeFaces 4.0's p:inplace widget has a show() method that switches it to edit mode. We'll call this method once the document is fully loaded using jQuery's $(document).ready():

<script type="text/javascript">
    $(document).ready(function() {
        // Call the show() method of the inplace widget to enter edit mode
        inplaceAjax.show();
    });
</script>

How this works

By default, p:inplace renders in view mode. The show() method from its client-side API programmatically triggers the same action as clicking the component, switching it to edit mode immediately when the page finishes loading.

Notes for PrimeFaces 4.0

  • Avoid using the PF() function here—this was introduced in later versions of PrimeFaces. In 4.0, you can directly reference the widget using the widgetVar name you defined.
  • Make sure the script is placed after the p:inplace component, or wrap it in $(document).ready() to ensure the widget is initialized before we call its method.

内容的提问来源于stack exchange,提问作者Mohamed Saber

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:49:40