jsf - p:remoteCommand destroys @ViewScoped managed bean -


i having trouble adding p:remotecommand form. looks like:

<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"     xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"     xmlns:util="http://java.sun.com/jsf/composite/components/util"     xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions"     xmlns:p="http://primefaces.org/ui">     <h:head>         <title>reset test</title>         <link type="text/css" rel="stylesheet" href="/treetable-sscce/css/example.css" />         <h:outputscript library="primefaces" name="jquery/jquery.js"/>     </h:head>      <div class="box">         <h2>box</h2>         <h:panelgroup id="mypanel">             headline: <h:outputtext value="#{resetbean.headline}" />             <br/>             message : <h:outputtext value="#{resetbean.message}" />             <br/>         </h:panelgroup>     </div>      <div class="box">         <h2>form</h2>         <h:form id="myform" acceptcharset="utf-8">              <p:growl id="growl" showdetail="true" sticky="false" severity="info, warn" />                     <!--  register custom validate event -->             <f:event listener="#{resetbean.validateform}" type="postvalidate" />              <p:remotecommand name="resetbyescape" action="#{resetbean.resetaction}"                  immediate="true" update=":myform :mypanel" />              <h:outputlabel for="headline">meldungsüberschrift</h:outputlabel>             <h:inputtext id="headline" value="#{resetbean.headline}" />             <br/>              <h:outputlabel for="message">meldungsüberschrift</h:outputlabel>             <h:inputtextarea id="message" value="#{resetbean.message}" />             <br/>              <h:commandbutton action="#{resetbean.resetaction}"                           value="reset" immediate="true" onclick="resetform()"/>              <h:commandbutton action="#{resetbean.submitaction}" value="submit"  immediate="false"/>          </h:form>     </div>      <script type="text/javascript">         <!--//--><![cdata[//><!--          var resetform = function()         {             $("[id$='headline']").val(null)             $("[id$='message']").val(null)         }          var escapepressed = function()         {             resetform();             resetbyescape();         }           $(document).keyup(function(e) {if (e.keycode == 27) escapepressed();});          //--><!]]>     </script> </html> 

here bean code:

package de.example.beans;  import java.io.serializable;  import javax.annotation.postconstruct; import javax.annotation.predestroy; import javax.faces.bean.managedbean; import javax.faces.bean.viewscoped; import javax.faces.event.componentsystemevent; import javax.faces.validator.validatorexception;  import org.apache.log4j.logger;  @viewscoped @managedbean public class resetbean implements serializable  {     private static final long serialversionuid = 7282752623428425109l;     private static final logger log = logger.getlogger(resetbean.class);      protected string headline = null;     protected string message = null;      public resetbean() {         log.error("resetbean");     }      @postconstruct     public void postconstruct() {         log.error("postconstruct");     }      @predestroy     public void predestroy() {         log.error("predestroy");     }      public void resetaction() {         log.error("resetaction");         headline = null;         message = null;     }      public void submitaction() {         log.error("submitaction headline="+headline+" message="+message);     }      public void validateform(componentsystemevent event) throws validatorexception {         log.error("validateform");     }      public string getheadline() {         return headline;     }      public void setheadline(string headline) {         this.headline = headline;     }      public string getmessage() {         return message;     }      public void setmessage(string message) {         this.message = message;     }  } 

both h:command button , p:remotecommand execute same action in same fashion. difference is, h:command button responds mouse click, while esc key triggers p:remotecommand via javascript on using esc key.

the problem is, route via p:remotecommand seems destroy backing bean somehow (the bean @viewscoped). @predestroy annotated method never called, however: next action on page after using p:remotecommand forces component created scratch! default constructor , @postconstruct called. naturally important parameters missing , whole view gets shot hell.

any idea happening? why difference between p:remotecommmand , h:commandbutton in instance? chance of working around problem?

i reproduce problem. in case , maybe same case here (question provides 'sample' code, not real one) caused nested forms template->page.

if have ui:composition template or similar that, @ end of generated html on client side may creates nested forms this:

<h:form> ...   <h:form>    ...   </h:form> ... </h:form> 

which invalid html code.

remove unnecessary forms or reorganize code , test again. should not call @postconstruct method when p:remotecommand called through javascript


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -