How do I persist field values before refreshing view?

UI Components for JSF
Post Reply
marty494
Posts: 2
Joined: 06 May 2011, 12:31
Location: Woking, United Kingdom

06 May 2011, 13:19

I am new to Primefaces and JSF in general.

I have tried to create a generic means of enabling/disabling form components when required.

Code: Select all

<h:form id="myForm">
<p:remoteCommand name="toggle"
  process="@this,source" 
  actionListener="#{myBean.toggle}"
  update="@form" />
<h:inputHidden id="source" />
<p:inputText id="fldDepot" 
  value="#{myBean.fldDepot}" 
  disabled="#{myBean.isDisabled('fldDepot')}" />
<formlet:jtable
  id="btnDepot"
  disabled="#{myBean.isDisabled('btnDepot')}"
  onsuccess="document.getElementById('myForm:source').value='btnDepot';toggle()" />
<p:commandButton 
  id="btnNew" 
  disabled="#{myBean.isDisabled('btnNew')}" />
The custom component <formlet:jtable> displays a <p:commandButton> that launches an Applet dialog.

The methods of interest in my backing bean are as follows:

Code: Select all

private HashMap<String, Boolean> enabled;
public boolean isDisabled(String field) {
  return enabled.containsKey(field) ? !enabled.get(field) : true;
}
public void toggle() {
  FacesContext ctx = FacesContext.getCurrentInstance();
  String source = ctx.getExternalContext()
    .getRequestParameterMap().get("myForm:source");
  if (source.equals("btnDepot")) {
    enabled.put("btnOperative", true);
    enabled.put("btnNew", true);
  }
}
It enables and disables the required components just fine. However, if I've typed anything into the text fields (fldDepot in this example) then the update="@form" refreshes the view and clears the field!

FYI. The "toggle" method is invoked from javascript after the user closes the Applet dialog. I cannot therefore, use the onsuccess on the <p:commandButton> because that executes before the applet finishes.

I want the <p:remoteCommand> to remain generic and therefore not hard-code any component names into the update attribute (hence I'm using @form).

How can I force the field values to be persisted before the remoteCommand update is processed? I don't want to add valueChangeListeners to all of my components.

Any help greatly appreciated, Martin.

My versions
--------------------------------
primefaces-2.2.1
RI_2.0.2-b10
Tomcat 6.0

porthos
Posts: 122
Joined: 09 May 2011, 03:17

11 May 2011, 00:53

Is there any particular reason you do not want to use process="@form" in the p:remoteCommand to persist your field values then? Or am I misunderstanding what you're trying to do.
-------
PrimeFaces 3.4, Glassfish 3.1.2, Mojarra 2.1.6

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: speandHap and 6 guests