FacesContext can't display error msg !
Hi guys,
I got this problem. For this function:
public User saveUser(User user) throws DBException {
try {
User newUser = this.userDao.saveUser(user);
return newUser;
} catch (DataIntegrityViolationException di) {
String msg = "duplicate user id";
this.logger.error(msg, de);
throw new DuplicateUserIdException(msg);
=======================================
then the below function is to execute when user click the submit button
public String submitAction() {.....
catch (DuplicateUserIdException de) {
String msg = "Username already exists";
this.logger.info(msg);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage( FacesMessage.SEVERITY_INFO, msg, msg));
return QueryResults.RETRY;
========================================
public class DuplicateUserIdException extends DBException {
private String username;
public DuplicateUserIdException(String newUsername) {
super("Username " + newUsername + " already exist");
this.username = newUsername;
public String getUsername() {
return this.username;
====================================
So when I click on the submit button after entering a duplicate username, it will just go back to the same page and no error message display. Username is a primary key and email address is set to UNIQUE in MySQL DB. I read the log file and indeed all the error messages can be catched. The registration.jsp page is like:
<h:inputText value="#{userBean.username}" id="username" required="true">
<f:validateLength maximum="20" minimum="5"/>
</h:inputText>
<h:message for="username"/>
but I got my login page also the same h:inputText as above.
I am using JSF + Spring + Hibernate.
I hv tried to fix it a few time but failed !
Appreciate any help here.
K> then the below function is to execute when user click
K> the submit button
K>
K> public String submitAction() {.....
K>
K> catch (DuplicateUserIdException de) {
K> String msg = "Username already exists";
K> this.logger.info(msg);
K> FacesContext.getCurrentInstance().addMessage(null,
K> l, new FacesMessage( FacesMessage.SEVERITY_INFO,
K> msg, msg));
K> return QueryResults.RETRY;
K> }
K> }
K> So when I click on the submit button after entering a
K> duplicate username, it will just go back to the same
K> page and no error message display. Username is a
K> primary key and email address is set to UNIQUE in
K> MySQL DB. I read the log file and indeed all the
K> error messages can be catched. The registration.jsp
K> page is like:
K>
K> <h:inputText value="#{userBean.username}"
K> id="username" required="true">
K> <f:validateLength maximum="20" minimum="5"/>
K> </h:inputText>
K> <h:message for="username"/>
K>
K> but I got my login page also the same h:inputText as
K> above.
K>
K> I am using JSF + Spring + Hibernate.
K>
K> I hv tried to fix it a few time but failed !
K> Appreciate any help here.
Ok, we have to keep in mind the request processing lifecycle here. Your
submitAction() method is called after conversion and validation have
already occurred. Therefore, you can never queue an error from an
action handler. Here's why.
When your submitAction() is called, you queue a message into the faces
context. Whatever you return from submitAction(), it's ultimately going
to cause a requestDispatcher.forward() or
httpServletRespones.sendRedirect(). Both of these cause a new
FacesContext instance to be created, obliterating your carefully queued
message.
The best practice I've seen used is to handle the validation as close to
the component in which the validation error occured as possible. I
recommend creating a custom validator method binding, that does the
trick. This is really easy to do. Just add a method to your bean:
public void validate(FacesContext context,
UIComponent component,
Object value) throws ValidatorException {
// queue the message here, make sure to call component.setValid(false)
Then, in your inputText, you say:
<h:inputText value="#{userBean.username}" validator="#{userBean.validate}
id="username" required="true">
<f:validateLength maximum="20" minimum="5"/>
</h:inputText>
And you're done.
Ed (JSR-252 Spec co-lead)
Similar Messages
-
hi,
how i display error msg on page by using af:message from beans, based on some processing? i tried , but error msg is not coming on af:message?
i m using jdv10g. i checked by system.out.println(errormsg), & it displaying in console, but not on af:message.
thankshi thanks,
it is showing the message on af:messages on top of page. i want to display it on af:message fm bean.
i dragged a af:message fm components palette. i associated its value attribute to errormsg property in bean like this-
<af:message id="m1" message="#{xxbean.errormsg}"
inlineStyle="color:rgb(255,0,0);"/>
//in bean
private String errormsg = "";
based on some processing i filled the 'errormsg' property with desirable error string, by this.errormsg="error....." .
& getter method is there for returing the value, on page.
GlobalOnly= true for af:messages.
i m using 10gdev
Edited by: user78995 on Apr 7, 2010 2:44 AM -
My fully charged iPhone has a black screen and is not responding but has Siri and sound. I connected to laptop and iTunes gives error msg indicating phone is locked and I to enter passcode. but I can't enter the passcode because the screen is black. I have never syncd with iTunes. What can I do to get my phone back?
First thing to try is to reset your device. Press and hold the Home and Sleep buttons simultaneously until the Apple logo appears. Let go of the buttons and let the device restart. See if that fixes your problem.
-
Hi,
I try to create 2013 FY in "Setting for Each FY" in OKEQ - Maintain Versions unfortunately I have created Null FY, try to delete Null FY on the time it will ask Job schedule, I have cancelled the job & reopen Maintain Versions (OKEQ) screen on the time system populated the msg "Background Job still running - Data can be displayed only"
In Settings for Each FY screen there is no New Entries button, all FY are blocked status, changes was not allowed.
How can I resolve it.
Waiting for your valuable suggestions.
Regards,
Nageswar.Dear Rajneesh Saxena
Thanks for your prompt reply.
Yes you are correct, on the time of deletion it will ask Background Job Process, for immediate deletion must & should select "NO".
While "Settings for Each FY" screen populates message "Background Job Still Running - Data Can Be Displayed Only" open screen in display mode enter the command "=KILL" in command bar press enter, then you will allow to changes get New Entries button also.
Problem is solved
Regards,
Nageswar. -
Problm in displaying error msg
hi
i hav written error message for production sheduler...
if the input is wrong i want the errror to be displayed as invalid input...
if they dnt enter any data then no need to display any error msg i hav written this below code...
here im getting error if i dont enter account group and if i enter correct group also it is giving error msg...
wt is wrong in my code?
AT SELECTION-SCREEN on s_fevor.
s_fevor-sign = 'I'.
s_fevor-option = 'EQ'.
s_fevor-low = s_fevor.
s_fevor-high = s_fevor.
APPEND s_fevor.
CLEAR s_fevor.
IF not s_fevor-low in s_fevor.
SELECT fevor
from afko
INTO TABLE t_fevor
WHERE fevor in s_fevor.
IF sy-subrc ne 0.
MESSAGE e001.
ENDIF.
ENDIF.Hello
Please modify your code as below .WHICH WIll work for all scenarios i mean even if you give Option as EXCLUSIVE also .....
AT SELECTION-SCREEN on s_fevor.
DATA : l_t_fevor TYPE TABLE OF afko-fevor WITH HEADER LINE.
SELECT fevor INTO TABLE l_t_fevor FROM afko.
LOOP AT s_fevor.
IF NOT s_fevor-low IS INITIAL.
READ TABLE l_t_fevor WITH KEY = s_fevor-low.
IF sy-subrc <> 0.
SET CURSOR FIELD 'S_FEVOR-LOW'.
MESSAGE e<> ENDIF.
ENDIF.
IF NOT s_FEVOR-high IS INITIAL.
READ TABLE l_t_fevor WITH KEY = s_fevor-high.
IF sy-subrc <> 0.
SET CURSOR FIELD 'S_FEVOR-HIGH'.
MESSAGE e<> ENDIF.
ENDIF.
ENDLOOP.
Regards -
Restarting the software and/or the computer do not fix the error. I have installed the new firmware in my CP2025dn Color Laser it now has version 20110212 firmware. The error msg reports: windows version Win32NT-6.0.6002.131072 and HP Toolbox FX version 004.012.00146. I am running the printer on my wireless router. My computer is a Dell Studio with Vista Home Premium Service Pack 2 - 64 bit OS. My wife's older laptop with WIN XP is not having a problem with Toolbox. I have uninstalled and reinstalled Toolbox on my computer today also. Where do I look next? Thank you!!!
Hi
Please find the link given below might help you to fix your issue.
Link
Let us know how it goes!
"I work for HP."
****Click the (purple thumbs up icon in the lower right corner of a post) to say thanks****
****Please mark Accept As Solution if it solves your problem****
Regards
Manjunath -
How can I display error log of a standard program in my custom program?
Hello Experts,
I have a requirement where I submit a standard program from my custom module pool program as a background job. I use the TO SAP-SPOOL and thus the log is available when I go to SM37 and check the spool list. I have a requirement that I display this log in a tab within my module pool after the completion of the program. I am unable to fins a proper solution to this. I have both the spool number & the log number but I am unable to find function modules which will help me print them within my program. I found many ways to display it but as full screen and not with in my program.
Could someone please help me with this.
Thank YouHi,
FM to read a spool request is "RSPO_RETURN_ABAP_SPOOLJOB".
If the error log is displayed as a list output in the standard program, you can also use the syntax SUBMIT Program... and RETURN with export to memory addition.
Then you will be able to read the list output from memory.
Regards,
Munesh. -
How to make a field editable again after displaying error msg (validation)
Dear All,
In dialog programming, I have written a validation on a text field that it should not be left blank by the user, but after displaying the message the field becomes gray (non-editable). How can I make it editable once again after displaying the error message.
My code is as following:
***INCLUDE MZFBPS1_SAVE_DATAF01 .
*& Form save_data
text
--> p1 text
<-- p2 text
FORM save_data .
****************Check For Empty Fields Start
if ZFBPS_GATE_IN-truck_code is INITIAL
or ZFBPS_GATE_IN-truck_no is INITIAL
or ZFBPS_GATE_IN-transporter_code is INITIAL.
MESSAGE e020(zmatlist).
endif.
****************Check For Empty Fields Start
Regards,
Alok.hi,
u can do it in chanin end chain.
For example if there are 10 fields in the screen and for 5 fields whenever the user enters wrong values u like to give some error message. You can declare that fields in the chain enchain so that only those fields will be input enabled and all other fields will disabled.
CHAIN.
FIELD chk_connobj.
FIELD chk_inst.
FIELD chk_devloc.
FIELD ehaud-haus.
FIELD eanl-anlage.
MODULE modify_screenfields.
ENDCHAIN.
*& Module modify_screenfields INPUT
* text
MODULE modify_screenfields INPUT.
CLEAR okcode.
okcode = sy-ucomm.
CASE okcode.
WHEN 'ENTER' OR 'EXECUTE'.
IF chk_connobj IS INITIAL AND chk_inst EQ c_x AND
chk_devloc EQ c_x. -----------> ur condition
IF ehaud-haus IS INITIAL.
SET CURSOR FIELD 'EHAUD-HAUS'.
MESSAGE e000(zo_spa) WITH text-017. " message obj
ELSE
loop at screen.
if screen-name = 'FIELD_NAME'.
field-name-input = 1. -----------> chnges to non-edit mod
modify screen.
endloop.
ENDIF.
ENDIF.
ENDMODULE.
Rgds
Anver
if hlped pls mark points -
In Ztable creation, How can we display error message for a 'To date' field.
Hi all,
I have a requirement like this.
There r two fields in ztable. From date and To date.
The field 'To date' in table ZKM007 is taking before date than From date field.
To date should always be greater than from date i need to throw an error or don't allow to enter date if date is less than From date.
How can we do this?
Can any one help on this?
Rewards to all.
Thanks & Regards,
Anu.I have written below code at event "Creating a new entry" (05) in table maintainance generator.But it is not working. If we give the to date < From date ,
it is saving.
Can any one help on this code? Pls Give me code And which event i have to put this?
***INCLUDE LZEXE3F01 .
FORM AT_entry.
IF ZEXE3-TODATE LT ZEXE3-FROMDATE.
MESSAGE I001(0) WITH 'ENTER TO DATE GREATER THAN FROM DATE'.
ENDIF.
ENDFORM.
Rewards to all.
thanks
Anu. -
Code to display error msg if duplicate entry
I have an upload program to upload csv file to itab, and i need a sample code for the employee id to give me an error message if a duplicate employee id is found during execution.
After Upload you can delete the Duplicates comparing the employee Id.
It Will be Possible only when you use OLE and read the file records line by Line. I am not sure of the error Handling with OLE control. It may lead to some performance issues.. -
Can we display error messages inline for components used with iteration
Hi
While using form components in a table or any some iteration like making use of forEach, I am unable to render the error messages inline. Can someone help me in achieving this?
Regards
HoneyHere's a snippet:
<af:table var="row" rowBandingInterval="0" id="t1"
partialTriggers=":cb1"
value="#{viewScope.table.dataList}">
<af:column sortable="false" headerText="Name" id="c2">
<af:inputText value="#{row.name}" id="it2" required="true"/>
<af:message id="m1" for="it2"/>
</af:column>
<af:column sortable="false" headerText="Address" id="c1">
<af:inputText value="#{row.address}" id="it1"
required="true"/>
<af:message id="m2" for="it1"/>
</af:column>
</af:table>
required true would act the same way as a validator. When using the validator, it is placed as a child component of the inputText.
Regards
Honey -
How can I display error if the input is not a number?
I thought I knew how, but I am not sure on what is what in the ASCII character list.
I need check for errors if the user inputs anything except a positive integer. How could I do that? I had something like this:
int number;
if ((number<0)||(number>80))
System.out.println(Error please enter a new value
}But that only filters out negatives, I have tried a few different ways but I cant get it. I dont know why I cant figure it out, its easy, but either way what would I put on the if () line?http://asciitable.com
Wait so I would do
if ((number<=48)||(number>=57)
statements......
}I thought I tried that and it didnt work, but I will try again. Since number is an int, will it still work? And do I need to do '48' with the ' around it?
Thanks -
Upgrade from RH8 to RH9 displays error msg for images/hyperlinks
We imported a RH8 project into RH9 on another computer. For the most part, it went smoothly; however, for some images and hyperlinks, we get the message: The image file "___.jpg" used in "______.htm" is outside of the current project and will not be shown in Project Manager.
Additionally, there are approximately 20 broken links displayed in the Broken Links tab.
Your suggestions would be appreciated as we have multple huge projects we need to upgrade. ThanksHi there
For each of the messages about the image being outside the project, you will need to carefully note the image file name, the topic and the location it is reporting. Then you will need to edit the topic and click on the image icon and browse to the image to choose it. That action should correct the link and copy the image into your project.
Broken links will have to be resolved on a "link by link" basis. I was assisting someone else in a different thread and it may be of use to you. Click the link below to view that thread.
Click here to view
Cheers... Rick -
Displaying error messages in table...
Hi All,
How can we display error messages in a table in a bsp page.
I am filling an internal table in OnInputProcessing on some event with all the error messages to be displayed.
Table sould have two columns
1)Graphic depending on error type.
2)Error message.
Thanks,
Anubhav.Hi Graham,
The solution is perfect!
One more thing...when the page is displayed with errors table , i need to set focus on the table.
My code is:
<htmlb:gridLayoutCell columnIndex="1" rowIndex="1" id="fourthmain">
<% if itab_message is not initial .%>
<table class=""urGridLayout" border="1" cellpadding="2" id="err_tab">
<%
loop at itab_message into wa_message.
%>
<tr>
<td class="urCoB2Whl">
<% case wa_message-typ.
when 'S'. %>
<htmlb:image src = "ICON_MESSAGE_INFORMATION" />
<% when 'error'. %>
<htmlb:image src = "ICON_MESSAGE_ERROR" tooltip="Error" />
<% when 'W'. %>
<htmlb:image src = "ICON_MESSAGE_WARNING" />
<% when 'I'. %>
<htmlb:image src = "ICON_MESSAGE_INFORMATION" />
<% when 'A'. %>
<htmlb:image src = "ICON_MESSAGE_CRITICAL" />
<% endcase. %>
</td>
<td><font size="2" face="Times">
<%= wa_message-msg%>
</font>
</td >
</tr>
<%
endloop.
%>
</table>
<% refresh itab_message. %>
<% endif. %>
</htmlb:gridLayoutCell>
I tried using
<phtmlb:focusRect focusElementId="err_tab"/>
and also:
<s cript="text/javascript">
daument.farm.elementid.focus();
</s cript>
But failed...pls help me out.
Thanks,
Anubhav. -
HP photos art C5240 aii in one error msg pertaining to ink cartridges
Can not print error msg: remove cardboard or tape that is preventing the print carriage from moving
Hi @Suggs77,
Welcome to the HP Forums!
I understand that you cannot print with your HP Photosmart c5240 due to the error message remove cardboard or tape that is preventing the print carriage from moving. I am happy to help you with this error!
Please see the following guides:
HP Photosmart C5200 All-in-One Printer Series- Setting up the All-in-One (Hardware).
A 'Carriage Jam' or 'Carriage Blocked' Message Displays for HP Photosmart C5200 and C5500 All-in-One....
Hope these guides help and have a great day!
RnRMusicMan
I work on behalf of HP
Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
Click the “Kudos Thumbs Up" to say “Thanks” for helping!
Maybe you are looking for
-
OS: Ubuntu 9.0.4 Browser: Firefox 3.6.10 upon updating to firefox 3.6.10, java does not work at all. websites that use java do not work at all anymore, when they worked just fine before the updating thru update manager. e.g. hulu website cannot play
-
[FB:Mobile]Delete item form s:list
Is possible to delete an item in s: list, moving your finger on as usual in the iPhone?
-
Screen shots for creating Stock transport order
hi, Can anyone send me the screen shots for creating Stock transport order between plants within company code? Regards, Swathi
-
NW2004s ABAP Trial Version ' error code = 601 '
Due to a timing problem it is possible that an installation error ' Expected service (SAPNSP_00) is not currently running... error code = 601 , services failed to start ' occurs. In that case there remain some entries in the registry that don't allo
-
They kept me on the phone for 2 hours, never fixed the problem and then tried to SELL me support. I think this is a rip off or scam of some sort.