Remotecommand
Author: s | 2025-04-25
RemoteCommand() Creates a new remote command object ready to be passed to the add command. val remoteCommand = object: RemoteCommand ( commandName, description ) To enter the RemoteCommand keyword, use one of the options: Type RemoteCommand; Type RemoteC; Description. The RemoteCommand keyword remotely sends commands to other
remotecommand package - k8s.io/client-go/tools/remotecommand
File he wants to download. The options are presented in a dialog which should be preferably closed when the download is performed. Also the screen should be indicate the file download occurred.Here the RemoteCommand is the solution to these cases. The RemoteCommand allows to call some JSF bean methods and JSF lifecycle methods from JavaScript.p:commandButton value="Download2" ajax="false" onclick="pageRefresh();"> p:fileDownload value="#{fileBean.file}"/>p:commandButton>p:remoteCommand update="@all" name="pageRefresh"/>When we click on the button, the onClick activates the javaScript version of the RemoteCommand and initiates a AJAX partial page refresh of the screen. On the other hand, the click on the button also initiates the ActionListener of the FileDownload component to perform the file download.Since we where able to initiate 2 calls, we can perform 2 actions, the download and the screen update.ConclusionWith the help of the FileDownload component it becomes easier to program the download of a static or dynamic file in JSF. You no longer need a servlet to perform these kind of actions.With the help of the very broad useable RemoteCommand component, we can even initiate 2 actions. The file download and some screen updates. RemoteCommand() Creates a new remote command object ready to be passed to the add command. val remoteCommand = object: RemoteCommand ( commandName, description ) To enter the RemoteCommand keyword, use one of the options: Type RemoteCommand; Type RemoteC; Description. The RemoteCommand keyword remotely sends commands to other If a remote command is invoked, which is not rendered in the actual dom tree, all beans with the "view scoped" annotation reinitialized.It would be nice if this were handled with javascript ("PrimeFaces.ajax.Request.send").Proposal for solution:PrimeFaces.ajax.Request.send = function(cfg) { sourceId = null; if (typeof (cfg.source) === 'string') { sourceId = cfg.source; } else { sourceId = $(cfg.source).attr('id'); } if (!($(PrimeFaces.escapeClientId(sourceId)).length)) { //remove from queue if(!cfg.async) { PrimeFaces.ajax.Queue.poll(); } return false; } // ...}The only problem is that the RemoteCommandRender does not render the script tag in a extra container. For the solution above, this is required too.public class RemoteCommandRenderer extends org.primefaces.component.remotecommand.RemoteCommandRenderer { @Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); RemoteCommand command = (RemoteCommand) component; String clientId = command.getClientId(context); String name = resolveName(command, context); UIComponent form = ComponentTraversalUtils.closestForm(context, command); if (form == null) { throw new FacesException("RemoteCommand '" + name + "'must be inside a form."); } writer.startElement("span", null); writer.writeAttribute("id", clientId, "id"); writer.writeAttribute("class", "hidden", "class"); super.encodeEnd(context, component); writer.endElement("span"); }}1) EnvironmentPrimeFaces version: 6.0.7Application server + version: GlassFish 4.1.1Affected browsers: all browsers2) Expected behaviorThe javascript function PrimeFaces.ajax.Request.send should check the source id.3) Actual behaviorAll beans with the view scoped annotation reinitialized (@PostConstruct has been invoked)4) Steps to reproduceExecute a remoteCommand which is actual not rendered.sample:Click on the button "hide container" two times.5) Sample XHTML ">html xmlns=" xmlns:c=" xmlns:h=" xmlns:f=" xmlns:p=" xmlns:ui=" xmlns:o=" p:outputPanel id="formContainer"> p:outputPanel rendered="#{testPage.renderContainer}"> h:outputText value="Form Container" /> br /> h:form> h:outputText value="Remote Command" /> p:remoteCommand name="hideContainer" action="#{testPage.hideContainer}" process="@this" update=":formContainer" /> h:form> p:outputPanel> p:outputPanel> p:commandButton onclick="hideContainer(); return false;" value="hide container" />h:body>html>6) Sample bean@Named@ViewScopedpublic class TestPage implements Serializable { private static final long serialVersionUID = 372367373223155571L; private boolean renderContainer = true; @PostConstruct public void postConstruct() { System.err.println("postConstruct has been invoked"); } public String hideContainer() { renderContainer = false; return null; } public boolean isRenderContainer() { return renderContainer; } public void setRenderContainer(boolean renderContainer) { this.renderContainer = renderContainer; }}Comments
File he wants to download. The options are presented in a dialog which should be preferably closed when the download is performed. Also the screen should be indicate the file download occurred.Here the RemoteCommand is the solution to these cases. The RemoteCommand allows to call some JSF bean methods and JSF lifecycle methods from JavaScript.p:commandButton value="Download2" ajax="false" onclick="pageRefresh();"> p:fileDownload value="#{fileBean.file}"/>p:commandButton>p:remoteCommand update="@all" name="pageRefresh"/>When we click on the button, the onClick activates the javaScript version of the RemoteCommand and initiates a AJAX partial page refresh of the screen. On the other hand, the click on the button also initiates the ActionListener of the FileDownload component to perform the file download.Since we where able to initiate 2 calls, we can perform 2 actions, the download and the screen update.ConclusionWith the help of the FileDownload component it becomes easier to program the download of a static or dynamic file in JSF. You no longer need a servlet to perform these kind of actions.With the help of the very broad useable RemoteCommand component, we can even initiate 2 actions. The file download and some screen updates.
2025-04-02If a remote command is invoked, which is not rendered in the actual dom tree, all beans with the "view scoped" annotation reinitialized.It would be nice if this were handled with javascript ("PrimeFaces.ajax.Request.send").Proposal for solution:PrimeFaces.ajax.Request.send = function(cfg) { sourceId = null; if (typeof (cfg.source) === 'string') { sourceId = cfg.source; } else { sourceId = $(cfg.source).attr('id'); } if (!($(PrimeFaces.escapeClientId(sourceId)).length)) { //remove from queue if(!cfg.async) { PrimeFaces.ajax.Queue.poll(); } return false; } // ...}The only problem is that the RemoteCommandRender does not render the script tag in a extra container. For the solution above, this is required too.public class RemoteCommandRenderer extends org.primefaces.component.remotecommand.RemoteCommandRenderer { @Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); RemoteCommand command = (RemoteCommand) component; String clientId = command.getClientId(context); String name = resolveName(command, context); UIComponent form = ComponentTraversalUtils.closestForm(context, command); if (form == null) { throw new FacesException("RemoteCommand '" + name + "'must be inside a form."); } writer.startElement("span", null); writer.writeAttribute("id", clientId, "id"); writer.writeAttribute("class", "hidden", "class"); super.encodeEnd(context, component); writer.endElement("span"); }}1) EnvironmentPrimeFaces version: 6.0.7Application server + version: GlassFish 4.1.1Affected browsers: all browsers2) Expected behaviorThe javascript function PrimeFaces.ajax.Request.send should check the source id.3) Actual behaviorAll beans with the view scoped annotation reinitialized (@PostConstruct has been invoked)4) Steps to reproduceExecute a remoteCommand which is actual not rendered.sample:Click on the button "hide container" two times.5) Sample XHTML ">html xmlns=" xmlns:c=" xmlns:h=" xmlns:f=" xmlns:p=" xmlns:ui=" xmlns:o=" p:outputPanel id="formContainer"> p:outputPanel rendered="#{testPage.renderContainer}"> h:outputText value="Form Container" /> br /> h:form> h:outputText value="Remote Command" /> p:remoteCommand name="hideContainer" action="#{testPage.hideContainer}" process="@this" update=":formContainer" /> h:form> p:outputPanel> p:outputPanel> p:commandButton onclick="hideContainer(); return false;" value="hide container" />h:body>html>6) Sample bean@Named@ViewScopedpublic class TestPage implements Serializable { private static final long serialVersionUID = 372367373223155571L; private boolean renderContainer = true; @PostConstruct public void postConstruct() { System.err.println("postConstruct has been invoked"); } public String hideContainer() { renderContainer = false; return null; } public boolean isRenderContainer() { return renderContainer; } public void setRenderContainer(boolean renderContainer) { this.renderContainer = renderContainer; }}
2025-04-19Skip to content Navigation Menu GitHub Copilot Write better code with AI Security Find and fix vulnerabilities Actions Automate any workflow Codespaces Instant dev environments Issues Plan and track work Code Review Manage code changes Discussions Collaborate outside of code Code Search Find more, search less Explore Learning Pathways Events & Webinars Ebooks & Whitepapers Customer Stories Partners Executive Insights GitHub Sponsors Fund open source developers The ReadME Project GitHub community articles Enterprise platform AI-powered developer platform Pricing Provide feedback Saved searches Use saved searches to filter your results more quickly //voltron/issues_fragments/issue_layout;ref_cta:Sign up;ref_loc:header logged out"}"> Sign up Notifications You must be signed in to change notification settings Fork 767 Star 1.8k Description1) EnvironmentPrimeFaces version: 6.2Does it work on the newest released PrimeFaces version? Version? NoDoes it work on the newest sources in GitHub? NoApplication server + version: WildFly 14Affected browsers: Any2) Expected behaviorUsing outside a h:form should render fine.3) Actual behaviorUsing outside a h:form causes a javax.faces.FacesException: RemoteCommand 'doStuff'must be inside a form.4) Steps to reproducecreate a plain view file remote-command-test.xhtmlinsert (not nested inside a h:form, see below)try to render the view.5) Sample XHTML "> Like #2358 this is caused by the renderer which does not consider the form attribute and instead just looks for the enclosing form. Right now only the AjaxBehaviorRenderer considers the form attribute at all.
2025-04-12