Ajax/update/submit/required components problem

UI Components for JSF
Post Reply
babaguna
Posts: 8
Joined: 06 Oct 2011, 16:04

06 Oct 2011, 16:35

Hi there,

I have the following scenario - let's say I have 3 fields on a simple page. The first is required and the second when changed fills the third.
When the page opens and I enter any value in s2 and press Tab - the value goes correctly in field s3.
Then I press 'Submit' and because 's1' is empty and required the validation says in 'uiTopMessage' that the field s1 is required.
So far so good.
And here goes the problem - now I enter any other value in field 's2' and press Tab - the method gets executed and the debugger shows it correctly, but the new value is not displayed on page!
If 's1' is not empty, the jsf validation is ok, and the method Save() is executed. After that handle_s2_Change() also works.
So - before jsf validation anything works fine, but if jsf validation fails(in that case for the required field) the field does not get updated.
If I make 's3' disabled - the problem disappears.

That is major issue for me :(

Here is the code:

<?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:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<f:view contentType="text/html">
<h:head><title>tst</title></h:head>

<h:body>
<p:messages id="uiTopMessage" />

<h:form id="HtmlForm">

<p:inputText value="#{tstCntrl.s1}" id="s1" required="true"/>

<p:inputText value="#{tstCntrl.s2}" id="s2">
<f:ajax event="change" listener="#{tstCntrl.handle_s2_Change(event)}" render="s3"/>
</p:inputText>

<p:inputText value="#{tstCntrl.s3}" id="s3"/>

<p:commandButton value="Submit" actionListener="#{tstCntrl.Save()}" update="uiTopMessage"/>

</h:form>
</h:body>
</f:view>
</html>



package com.scon.WebIns.jsf.base;

import com.scon.WebIns.jsf.sys.JsfUtil;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.AjaxBehaviorEvent;

@ManagedBean(name = "tstCntrl")
@ViewScoped
public class TestsController implements Serializable {

String s1;
String s2;
String s3;

public void handle_s2_Change(AjaxBehaviorEvent event) {
this.s3 = this.s2;
}

public void Save(){
JsfUtil.addSuccessMessage("OK");
}

public String getS1() {
return s1;
}

public void setS1(String s1) {
this.s1 = s1;
}


public String getS2() {
return s2;
}

public void setS2(String s2) {
this.s2 = s2;
}

public String getS3() {
return s3;
}

public void setS3(String s3) {
this.s3 = s3;
}
}
PF 4.0, Mojarra 2.2.5, Glassfish 4.0

babaguna
Posts: 8
Joined: 06 Oct 2011, 16:04

10 Oct 2011, 10:06

any ideas :(
PF 4.0, Mojarra 2.2.5, Glassfish 4.0

babaguna
Posts: 8
Joined: 06 Oct 2011, 16:04

20 Oct 2011, 08:25

Mojarra 2.0.6
PrimeFaces 2.2.1
GlassFish 3.0.1

and also on:
Mojarra 2.1.1
PrimeFaces 2.2.1
GlassFish 3.1.1
PF 4.0, Mojarra 2.2.5, Glassfish 4.0

smallya
Posts: 264
Joined: 19 Mar 2010, 19:22
Contact:

27 Oct 2011, 00:41

Instead of <f:ajax> can you try this

<p:ajax event=".." listener="" update="<third_field_id> process="@form"/>

This should do a ajax update of the third field when the second field is updated.

HTH
Netbeans 7.2| GlassFish 3.2 | PostgreSQL 9.1| MongoDB | Primefaces 3.4.2
_______________________________________________________________
Subraya Mallya
http://tinyhabit.com |http://twitter.com/tinyhabit

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests