PrimeFaces 4.0:设置inplace组件默认无需点击即可编辑
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 thewidgetVarname you defined. - Make sure the script is placed after the
p:inplacecomponent, or wrap it in$(document).ready()to ensure the widget is initialized before we call its method.
内容的提问来源于stack exchange,提问作者Mohamed Saber

