Two Laptop Bag*
The moose likes JSF and the fly likes onblur is not called in inputText ...please help me if any body had same situation or aware of issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "onblur is not called in inputText ...please help me if any body had same situation or aware of issue" Watch "onblur is not called in inputText ...please help me if any body had same situation or aware of issue" New topic
Author

onblur is not called in inputText ...please help me if any body had same situation or aware of issue

Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
my msform.xhtml file has below code:

<t:dataTable value="#{msrFormBB.meterEquipmentInfo}" var="dataItem" cellpadding="0" cellspacing="0" rows="10" styleClass="XcomReadsTable" style="width: 100%;" rowClasses=",Flop">


<h:inputText size="10" maxlength="9" value="#{dataItem.serialNumber}" onblur="getReOrderNumber()" />




getReOrderNumbers() is call defined in backing bean but i ma not sure why this function was not called when i entered and moved from above inputText field.

If you need any more details from my side, please let me know
Srini Mutpur
Greenhorn

Joined: Mar 29, 2008
Posts: 24
The onblur attribute sets the JavaScript code to execute when this element loses focus. It can not set the value in the backing bean.

What exactly you are trying to do ?Could you please provide some more information ?


SCJP 1.5
Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
Thanks for your reply Srini.


well, i have a requirement where user enter value in inputText and when looses focus from it it should call a method(server side call) where i inluded code to gerente list of records from xml file based on input entered entered by the user in inputText field.

yes as i have limited knowledge in JSF, please let me know what are all the options i have to call method in backing bean from JSF.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Mallika gowd wrote:Thanks for your reply Srini.


well, i have a requirement where user enter value in inputText and when looses focus from it it should call a method(server side call) where i inluded code to gerente list of records from xml file based on input entered entered by the user in inputText field.

yes as i have limited knowledge in JSF, please let me know what are all the options i have to call method in backing bean from JSF.



onblur is a client-side event. To call the server, you're either going to have to make the client-side javascript force a form submit or you're going to have to send an AJAX request.


Customer surveys are for companies who didn't pay proper attention to begin with.
Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
Thanks Tim


could you please give example in AJAX to call method from JSF to backing bean method.


thanks in advance.
Bibin Zacharias
Greenhorn

Joined: Mar 31, 2009
Posts: 13
Just try with valueChangeListner in inputText. it may work out.


Thanks
Bibin
bibinz@gmail.com
Viswanath Tg
Greenhorn

Joined: Nov 27, 2007
Posts: 20
in the first case directly associating with a variable

<a4j:region rendered="true">
<h:inputText size="15" id="idname"
value="#{ddd.variblename}" rendered="true"
maxlength="10">
<a4j:support event="onkeyup" ajaxSingle="true">
</a4j:support>
</h:inputText>
</a4j:region>

or

<a4j:support event="onblur"
actionListener="#{xxxxx.methodToBecalled}"
reRender="specify the ids seperated by commas of those components once the response is send back">

</a4j:support>


Helping hands are better than praying lips
Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
Hi Vishwanath,


I tried to implement AJAX but may be some thing wrong in my implementation. please let me know anything wrong i am doing here below.

Backing bean method never called from xhtml.

msrform.xhtml -->

<t:dataTable value="#{msrFormBB.meterEquipmentInfo}" var="dataItem" cellpadding="0" cellspacing="0" rows="10" styleClass="XcomReadsTable" style="width: 100%;" rowClasses=",Flop">


<h:inputText id="myInput" size="10" maxlength="9" value="#{dataItem.serialNumber}"/>

<a4j:support event="onblur" actionListener="#{msrFormBB.reOrderNumbers}" reRender="myInput"> </a4j:support>

</t:dataTable >




backing bean --> msrFormBB-->


Below is the method we are calling from JSF.


public void getReOrderNumbers() {
System.out.println("first step");
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringComments(true);
System.out.println("first step");

factory.setIgnoringElementContentWhitespace(true);
factory.setValidating(true);

DocumentBuilder builder = factory.newDocumentBuilder();
System.out.println("second step");

Document doc = builder.parse(new InputSource("c://projects/ms/WebContent/xmlSuppliesByProductCode.xml"));

System.out.println("third step");

Element root = doc.getDocumentElement();

Element movieElement = (Element) root.getFirstChild();
System.out.println("fourth step");
String serialProdCode="3G3";
System.out.println("serial prod code:"+serialProdCode);

while (movieElement != null) {

ReorderNumGen m = getReOrder(movieElement);
if ((m.productCode).equalsIgnoreCase(serialProdCode))
{
meterReOrderNumGen.add(m);
System.out.println("meter ReOrder Number Generation");
}
String msg = m.productCode;
msg += "," + m.reOrderNumber;
msg += "," + m.desc;

System.out.println(msg);
movieElement = (Element) movieElement.getNextSibling();
}

}catch(Exception e){System.out.println("ABCD"); }



}
Viswanath Tg
Greenhorn

Joined: Nov 27, 2007
Posts: 20

Your implementation
<h:inputText id="myInput" size="10" maxlength="9" value="#{dataItem.serialNumber}"/>

<a4j:support event="onblur" actionListener="#{msrFormBB.reOrderNumbers}" reRender="myInput"> </a4j:support>

Required is - Try this

<h:inputText id="myInput" size="10" maxlength="9" value="#{dataItem.serialNumber}">

<a4j:support event="onblur" actionListener="#{msrFormBB.reOrderNumbers}" reRender="myInput"> </a4j:support>
</h:inputText>
Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
Thank you Viswanath.

yes, I even tried the below option and still i am not able to call the method in BB.

Note: I am using DataTable..is that causing any problem...please see my previous post for code.


thanks for your help.


hey...you from Adoni?
Viswanath Tg
Greenhorn

Joined: Nov 27, 2007
Posts: 20

When on blur event is fired what is displaying in logs....




<a4j:region>
<a4j:form>
<rich:dataTable id="myList" rows="15"
value="#{xxx.myList}" var="abc"
width="100%" >

<rich:column>
<f:facet name="header">
<hutputLabel
value="#{message['sss.bbbb']}" />
</f:facet>

<a4j:region>
<h:inputText value="#{xxxx.op}"
style="width:70px;text-align:right;"
maxlength="9" id="opid">
<a4j:support event="onblur"
action="#{varible as declared in facesConfig.methodnameofBakingBean}"
reRender="particularId">
</a4j:support>

</h:inputText>
</a4j:region>
</rich:column>
</rich:dataTable>
</a4j:form>
</a4j:region>


Replace action listner with action....

One more thing for debugging use a command button and on click of that button check weather the event is firing or not

Abhishk Gupta
Greenhorn

Joined: Oct 08, 2008
Posts: 22
Hi Mallika,

Instead of actionListener try using an action which is bound to a backing bean method.

<a4j:support event="onblur" action="#{msrFormBB.reOrderNumbers}" reRender="myInput"> </a4j:support>

reOrderNumbers method signature should not have any ActionEvent object.


There are only 10 types of people in the world: those who understand ternary, those who don't, and those who mistake it for binary.
Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
I used action instead actionLister even though the BB method is not getting called.

I am posting my code below.

<t:dataTable value="#{msrFormBB.meterEquipmentInfo}" var="dataItem" cellpadding="0" cellspacing="0" rows="10" styleClass="XcomEqTable" style="width: 100%;" rowClasses=",Flop">

<t:column styleClass="ColPos0">
<f:facet name="header">
<hutputText value="Serial Number*"></hutputText>
</f:facet>


<h:inputText id="myInput" size="15" maxlength="9" value="#{dataItem.serialNumber}">
<a4j:support event="onblur" action="#{msrFormBB.reOrderDetails}" reRender="myInput"> </a4j:support>
</h:inputText>

</t:dataTable>

please help me on this.
Abhishk Gupta
Greenhorn

Joined: Oct 08, 2008
Posts: 22
Mallika,
Please post the method reOrderDetails too.
Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
Thanks for quick replay abhishek.

I would like to give brief about my code here....

I have two section in my UI form..that is equipment section and supplies section.
and i defined two different dataTables for above two section.
So when user enters all equipments in dataTable #1 section values should populate supplies order details based on the equipments entered by the user

equipment section jsf code:

<t:dataTable value="#{msrFormBB.meterEquipmentInfo}" var="dataItem" cellpadding="0" cellspacing="0" rows="10" styleClass="XcomEqTable" style="width: 100%;" rowClasses=",Flop">

<t:column styleClass="ColPos0">
<f:facet name="header">
<hutputText value="Serial Number*"></hutputText>
</f:facet>


<h:inputText id="myInput" size="15" maxlength="9" value="#{dataItem.serialNumber}">
<a4j:support event="onblur" action="#{msrFormBB.reOrderDetails}" reRender="myInput"> </a4j:support>
</h:inputText>

</t:dataTable>



Supplies Section JSF code:


<t:dataTable value="#{msrFormBB.meterSuppliesInfo}" var="dataItem" cellpadding="0" cellspacing="0" rows="30" styleClass="XcomSuppTable" style="width: 100%;" rowClasses=",Flop">

<t:column styleClass="ColPos0">

<f:facet name="header">
<hutputText value="Supply Reorder Number*"></hutputText>
</f:facet>

<h:selectOneMenu size="45" value="#{dataItem.suppReOrderNumber}" >
<f:selectItem itemValue="" itemLabel="Please Select"/>
<f:selectItems value="#{msrFormBB.sortOptions}" />

</h:selectOneMenu>


</t:column>
</t:dataTable>

----------------------------------------

Now little expalination about Backing Bean msrFormBB

there i have two lists defined to popupate and insert data in to the database they are 1)msrFormBB.meterEquipmentInfo 2) msrFormBB.meterSuppliesInfo


And about method msrFormBB.reOrderDetails

above method will get the reorder numbers based the serail numbers entered in equipment section will add them to sortoptions list which i have populated in supplies section ..(code in JSF <f:selectItems value="#{msrFormBB.sortOptions}")


So finally when user enters serial numbers in equipment section....supplies sections supplyreordernumber should populate in dropdown.


if you need more details let me know.thanks in advance for your help.


Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
sorry i forgot to post my reorderdetails code.


here we go
------------
/*
* getting Re order numbers based on the serial numbers entered by the user
* in the equipment section and adding them to the sort options list.
*/
public void reOrderDetails() {
List<MeterSuppReorder> updates = new Vector<MeterSuppReorder>();
List<MeterSuppReorder> prodList = new Vector<MeterSuppReorder>();

StringBuffer inProdList = new StringBuffer("");
sortOptions = new Vector<SelectItem>();
meterReOrderNums = new Vector<MeterSuppReorder>();

if ((meterEquipmentInfo == null) || (meterEquipmentInfo.size() == 0)) {
meterEquipmentInfo = new Vector<MeterSuppReorder>();
}

if ((meterSuppliesInfo == null) || (meterSuppliesInfo.size() == 0)) {
meterSuppliesInfo = new Vector<MeterSuppReorder>();
}

try {

int count = 0;
for (int i = 0; i < meterEquipmentInfo.size(); i++) {
MeterSuppReorder inv = meterEquipmentInfo.get(i);

if (!MeterSuppReorderUtil.isEmptyString(inv.getSerialNumber())) {
count++;
}
}
String[] params = new String[count];

// ArrayList<String> params = new ArrayList<String>();
int m = 0;
for (int i = 0; i < meterEquipmentInfo.size(); i++) {
MeterSuppReorder inv = meterEquipmentInfo.get(i);

if (!MeterSuppReorderUtil.isEmptyString(inv.getSerialNumber())) {
String prodCode = inv.getSerialNumber().substring(0, 3)
.toUpperCase();
params[m] = prodCode;
m++;
} else {
updates.add(inv);
}

}
if (updates.size() == meterEquipmentInfo.size()) {
this.noValuesEnteredMsg = "emptySerialReadMsg";

}

try {

// Call to DB to get re order numbers

if (params.length != 0) {
meterReOrderNums = MeterSuppReorderDAO.getRONumbers(params);
}
System.out.println("successfully calling the re order details method");
// Adding re order number list to sortOptions
if ((meterReOrderNums.size() != 0)
&& (meterReOrderNums != null)) {
for (int i = 0; i < meterReOrderNums.size(); i++) {
MeterSuppReorder rec = meterReOrderNums.get(i);
sortOptions.add(new SelectItem(rec.getReOrderNumber(),
rec.getReOrderNumber() + " - "
+ rec.getDescription()));
}
} else {
if (meterSuppliesInfo.size() != 0) {
this.noReorderNumMsg = "noReorderNumMsg";
}
}
} catch (SQLException e) {
log.debug("error occured while getting the reorder number list from DB");
e.printStackTrace();

}
Abhishk Gupta
Greenhorn

Joined: Oct 08, 2008
Posts: 22
Frankly speaking I could not find anything wrong with the code. Moreover there is no validation in the page(atleast in the code shared).
But as we know the unpredictable behavior of ajax4jsf, try this:

<a4j:support event="onblur" action="#{msrFormBB.reOrderDetails}" reRender="myInput" immediate="true "></a4j:support>
instead of
<a4j:support event="onblur" action="#{msrFormBB.reOrderDetails}" reRender="myInput"></a4j:support>.

Please note, this is not a solution but just a workaround.
To check what's happening here, put it in your jsp
<a4jutputPanel ajaxRendered="true">
<h:messages />
</a4jutputPanel>

cheers
Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
Hi

I did not understand the below part.

Please note, this is not a solution but just a workaround.
To check what's happening here, put it in your jsp
<a4jutputPanel ajaxRendered="true">
<h:messages />
</a4jutputPanel>



could you please give more details where to include above code to track any errors?
Abhishk Gupta
Greenhorn

Joined: Oct 08, 2008
Posts: 22
did immmediate=true didn't work
anyways,

reloads the page and display error messages, if any
Mallika gowd
Greenhorn

Joined: Sep 28, 2009
Posts: 26
I did try immediate="true" but it didnt work...


any further help will be highly appreciated.
 
 
subject: onblur is not called in inputText ...please help me if any body had same situation or aware of issue