How to execute code after JSF startup?
Hello,
I need to execute some initialization code after JSF startup, so I cannot do the usual ServletContextListener trick, as that runs before JSF is completely initialized. Any ideas?
Kind regards,
Ulrich
I can think of one way to do this (which might be a bit cumbersome for what you are trying to do) : use the Spring framework's web integration classes.
You can specifiy a context listener in your web.xml :
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
That way, Spring will load an ApplicationContext, and in that context you can specify a Spring bean that will be instantiated at application startup, which will perform whatever logic you need to do.
More info here :
http://static.springframework.org/spring/docs/2.0.x/reference/webintegration.html
Similar Messages
-
Adf valueChangeListener autosubmit=true, execute code after update model
Hello.
I'm working with the valueChangeListener and autosubmit="true". I'll try to explain my situation
with an example.
jsp:
<af:form>
<af:panelForm>
<af:inputText
id="value1"
label="Value1"
value="#{index.myObject.value1}"
autoSubmit="true"
valueChangeListener="#{index.changeListener1}"/>
<af:inputText
id="value2"
label="Value2"
value="#{index.myObject.value2}"/>
</af:panelForm>
</af:form>
backing:
public class Index {
private MyObject myObject;
public Index() {
myObject = new MyObject();
public void changeListener1(ValueChangeEvent valueChangeEvent){
doSomethingWithMyObject(myObject);
// ... get/set of myObject
MyObject:
public class MyObject {
private String value1;
private String value2;
public MyObject() {}
//getters/setters...
}In the line doSomethingWithMyObject(myObject) i need myObject with the actual values in the user form.
in the example above, the first time the page is rendered and shows the inputs
if the user captures something in the 1st input and then hits the tab to go to the other input
the valueChangeEvent is fired, and the code in "index.changeListener1" executed, but at this moment
the model (myObject) hasn't been updated with the data that the user entered (Validation Phase).
So i need a way to execute my code called from the "valueChangeEvent" but after the model has been updated
Some notes about my problem:
- The doSomethingWithMyObject(myObject) could update data in myObject
- About binding="#{x.y}":
I know i can use the binding attribute in the tag <af:inputText binding="#{x.y}"> and then in the code of
the changelistener the binded component always have the most recent value from the user,
but i cant' use that, the method needs a MyObject instance.
- I don't think create a new instance of MyObject and populate it every time the event fires is a good way
- doSomethingWithMyObject" is a black box, so i don't know what is going to do with myObject
- In my problem there are more than 2 inputs there will be N components M listeners.
What I'm trying:
PhaseListener:
I have been implementing a solution with a PhaseListener like
public void afterPhase(PhaseEvent phaseEvent) {
// just after UPDATE_MODEL_VALUES phase
FacesContext f = FacesContext.getCurrentInstance();
Index i = (Index) f.getApplication().createValueBinding("#{index}").getValue(f);
// at this point the model is updated
doSomethingWithMyObject(i.getMyObject);
public PhaseId getPhaseId() {
return PhaseId.UPDATE_MODEL_VALUES;
this works but i don't know if this is the answer according to this post (unanswered at this time):
http://forums.oracle.com/forums/thread.jspa?threadID=611643
says something about that PhaseListener is not thread safe and blocks the application with more
than 1 user.
A wrapper:
using the controls binded to the backing
public class Index {
private MyObject myObject;
private CoreInputText inputValue1;
private CoreInputText inputValue2;
//listener
//getters/setters
} make a wraper like
public class MyObjectW {
private Index index; // wrap the backing index
public MyObjectW(Index index) {
this.index = index;
public String getValue1(){
return (String) index.getInputValue1().getValue();
public String getValue2(){
return (String) index.getInputValue2().getValue();
public void setValue1(Object v){
index.getInputValue1().setValue(v);
public void setValue2(Object v){
index.getInputValue2().setValue(v);
}and then call in the index backing:
doSomethingWithMyObject( new MyObjectW(this)); so it will access to the most actual values from user at the valueChangeEvent
But i really would like some way to execute my code called from the "valueChangeEvent" but after the model has been updated
so i dont need to wrap or implement PhaseListener
what do you think, what do you suggest, have any solution or a way to do what I'm trying?
thank you for your help...
Message was edited by:
akanewstedHello Frank, thanks for the response.
When you say
"If you need an updated object in this listener then you can update it from the value change listener as well"
you mean i can update the object by myself with the value from getNewValue()? or is there another way
to call to update the models at this time ?
I know i have the methods "getOldValue()" and "getNewValue()" in the "ValueChangeEvent" but what if i need
the actual value from the user in other control than the one that fires the event
example
Two inputs:
in the input1 the user enters some data
in the input2 when some data is entered it fires valueChangeListener (autosubmit=true)
in that case what if i need the value the user just entered in the input1 in the valueChangeListener of
the input2.
In general the app I'm working must do:
dynamically generate the controls in the form (inputs, selects etc)
Attach the control values to a model ( <af:inputText value=#{model.x}"/>
sometimes execute some script when a value change in a control (valueChangeListener)
those scripts uses the model (and needs to be an updated model)
script = " if (value2 = 'xyz') then value1='abc'; return true;";
if the model is not updated
the script will use old values and will be wrong
or if the script change some value in the model, when the update model phase occurs the value from
the script is lost.
that's why i need to work directly with the model and not the values in the ValueChangeEvent
Is there a way to use something like an action in the change of a control value?
that way the code will execute in the invoke application phase, can this be done ?
how i can execute code in the invoke application when a valueChangeEvent occurs ?
hope this help to explain more my situation.
Thank you for your help and time. -
How to execute code from a text file?
Hello all!
How to execute some code lines from a text file? For example my file is:
String varname = "somecontents";
JFrame frame = new JFrame();
frame.setVisible(true);How can I get contents of this file and parse them if I want get new JFrame and access to the variable varname?I mean the PHP would generate a readable Java source,
for example some variables with some data, and I just
dont know what to do with file if I want generate the
xls file from my saved data, could You help? :)Some variables, some data, PHP, Java, XLS file??? Al rather vague.
You need to explain in more detail what it is you're trying to do if you want an answer to your question! -
Execute code after show() in a Modal JDialog
Is there any way of executing a piece of code after a Modal JDialog's show() method ? I tried to run the code using SwingUtilities.invokeLater to no use. Any ideas ?
Thanks !Thanks Jamie !
Adding a new thread wasn't required. I found the solution in some forum. The main issue was to get focus to a textfield in JDialog along with displaying a JPopupMenu against it. I could get the focus in but the popup wasn't showing. In brief this is what solved it.
Assuming JTextField is testField. I add this listener to the textField just before calling JDialog.show().
<code>
private FocusListener fListen = new FocusListener()
public void focusGained(FocusEvent e)
// showPop() logic
public void focusLost(FocusEvent e)
testField.removeFocusListener(fListen);
testField.requestFocus();
</code> -
How to run code after each other?
Hi there, a little question.
I call a function that returns the path of a new saved image as a string.
In that function I use a loader to load the image. After the image is loaded I set the url of the saved image and return it.
Next = id of the new saved image
Imageurl = the url of the image to load.
thumborfull = an indication to see if the thumb needs to be saved or the full image, so the thumb can be saved in a different folder than the full image.
My problem: when I call this function.. the return goes first, and then the loader complete. In the loader complete I set the new path of the image which i want to return.
So, my code runs synchronal, and not synchronic.. How do you get it to run synchronic?
Please some help.
code:
public var myimageurl:String;
public function saveImageFromInternet(next:Number, imageurl:String, thumborfull:String):String
var imgClass:Class;
//the second way
var loader:Loader;
//source code of the second way
loader = new Loader();
//notice: NOT _loader.addEventListener,is _loader.contentLoaderInfo.addEventListener
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(event:Event):void
var loader:Loader = Loader(event.target.loader);
// width and heigt of selected image
var originalimgwidth:Number=event.target.width;
var originalimgheight:Number=event.target.height;
//put original image into bitmapdata
var bitmapje:BitmapData;
bitmapje=new BitmapData(originalimgwidth, originalimgheight, false, 0xFFFFFFFF );
bitmapje.draw(loader.content,null,null,null,null,true);
var newimagefile:File=new File();
if(thumborfull=="thumb")
newimagefile=docsDir.resolvePath("Tmtp/I"+next+".mtp"); //image path
myimageurl=newimagefile.nativePath;
else
newimagefile=docsDir.resolvePath("Fmtp/I"+next+".mtp"); //image path
myimageurl=newimagefile.nativePath;
var stream:FileStream = new FileStream; // create new filestream
stream.open(newimagefile, FileMode.WRITE); // open filestream
var data:ByteArray = encodeToJpg(bitmapje); // convert bitmapdata to a jpg bytearry
stream.writeBytes(data, 0, data.length); // writing the image
stream.close();
loader.load(new URLRequest(encodeURI(imageurl)));
return myimageurl;If you are concerned that you are losing the url as it is not available from the complete event, you could use a custom event, which allows you to pass your own data into the custom event. Then in your custom complete event object you will still have the url.
http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_1.html -
Execute code after Spry region redrawn / added to DOM
Hi,
I'm integrating my Spry event data with a YUI calendar.
Everything is working and event dates are highlighted on the YUI calendar. There is one last thing I wish to do which is to update the YUI calendar with a Spry Tooltip. The div regions for the tooltip text are generated dynamically by via a Spry repeating region. What I am failing to do is attach the tooltips to the YUI calendar after the Spry repeating region has been added to the docuement DOM. So the Spry Tooltip function cannot find the ID of the tooltips.
I have a dataset observer "onpostload" which seems to fire when the data is loaded but before the document dom has been updated by Spry. How can I ensure I wait for Spry to update the region and hence DOM with the new data before triggering the tooltip code?
Cheers
PhilYou got different kind of observers in Spry Data.
- Dataset observers:
datasetname.addObserver( observer )
- Spry Region Observers:
Spry.Data.Region.addObserver( 'region-id', observer );
The dataset observers send out notifications when there is a event happening inside the Spry Data Sets. The one you mentioned is part of this (onPostLoad). These are great to monitor your data changes, but in your case. You don't want to use these.
The Spry region observers respond to events that are happening in side the region. For example onPreUpdate, this event is called when the region is about to generate / insert new markup in to your region. But you also got the onPostUpdate. This is the observer you are looking for, it gets called once the region has re-generated its code / html. It gets fired directly after the new HTML has been inserted.
Small note about the region observers, these require a id= attribute. This id attribute must be placed on the same element as the spry:region. To learn, and read more about the observers i would like to referrer you to this article:
Data Set and Region Overview
Its rather large, but using the browser build in find function you should be able to locate the sections about the observers
Hopes this helps, -
Executing code after a transition has finished
Hi,
Is there any kind of language construct in JavaFX to allow a certain block of code to be executed after a transition has finished? Or do I have to pause the current thread with sleep() or similar?
The ideal would be something like this, but of course such a thing like onComplete does not exist AFAIK:
FadeTransition {node: selectedNode duration: 1s fromValue: 1 toValue: 0 onComplete: executeThis()}.play();Hello,
By "delete node" you mean delete it from scene? This example works for me:
var stage: Stage = Stage {
width: 250
height: 250
scene: Scene {
content: [
text = Text {
layoutY: 30
opacity: 0.0
content: "Example transition"
Button {
layoutY: 70
text: "Click me"
action: function() {
FadeTransition {
node: text
fromValue: 0.0
toValue: 1.0
duration: 200ms
action: function() {
delete text from stage.scene.content;
}.play();
}Saa -
Execute code at system startup in 11gR1
Hi gurus,
I need to execute some Java code once when the system starts. What are my options?
Regards,
VladimirBefore you do, check htpdate from freshmeat, it is very good, uses http calls to get the time. I run this in /etc/rc.local
Now how to make a script
#!/bin/sh
your code
more
your code
And that is it.
If you call one script from another and you want to pass values via the environment, then
#!/bin/sh
. your code
is the thingto do, and not get caught with lost environments. The '.' runs your code using the current shell, otherwise it launches a new shell.
Keeping the same shell can be useful, e.g. I call a script I call connect at the beginning of all my web sucker scripts, this limits the speed for wget and rsynch to make it friendly for other users on the net. So, is have to set a variable and export it.
connect:
#!/bin/sh
export WGspeed=10k
export RSspeed=30 -
How to execute code when press the ENTER key
Hello,
I've write the code in Key-ENTER trigger, but it doesn't work when I press ENTER key.
Best Regards
JoeMatth M
Thank you.
The following msg. from help system shows that key-enter trigger will execute when the ENTER pressing event occurs. Need your more help.
Regards
Joe
>
(index: "DO_KEY" )
Executes the key trigger that corresponds to the specified built-in subprogram. If no such key trigger exists, then the specified subprogram executes. This behavior is analogous to pressing the corresponding function key.
Built-in............Key Trigger............Associated Function Key
ENTER............Key-ENTER............[Enter] -
How to execute code written in java before javascript?
Hello,
is there any way to call the action or actionlistener method of a commandbutton (for instance, or any other component), before javascript is executed? (jsf 1.2_09, glassfish v2.1)
Eg: I want to open a new window with javascript for the details/editing of a row in a data table. To do so I use a request scoped backing bean for the new window, and in its constructor I pass the rowdata through the session map where I put the object beforehand using an actionlistener/action.
But this won't work, because the script happens before I can put the variable in the session map...
Is there an other way?
thanks
davidonly thing I can come up with is to submit the data using Ajax. So do an Ajax call (for example using JQuery) to submit an asynchronous request to some servlet that will put the data in the session bean, then when the Ajax call finishes open the window.
-
How to execute query after login?
Hi Gurus,
I'm developing nowadays a small system,that shows every employee his data( attendance time,vacations,execuses..etc),I just want to execute query (pop up data) once the employee logged in,as I get his login name and sysdate and execute the query.
how could this happen? do I need a process ? what is it?
How to get the system date?
thanks in advance
Pardon me,am just new here and still my terms for Developer 2000.You can do it with a process (call it onload) or with a simple sql query mapped to a region in the home page of your application.
hope this helps -
How to execute code saved in string variable??
Hello experts,
I need to execute a select which I obtain concatenating several fields into string variable.
So the select is saved in a string:
var = 'select... from ... where...'.
There is any way to execute that select? ("exec var." or similar??)
thanksHello Illie
Would it not be possible to use a simple dynamic SELECT, e.g.:
DATA:
ldo_data TYPE REF TO data.
FIELD-SYMBOLS:
<lt_itab> TYPE TABLE.
CREATE DATA ldo_data TYPE TABLE OF (ld_tabname).
ASSIGN ldo_data->* TO <lt_itab>.
SELECT * from (ld_tabname) INTO TABLE <lt_itab>
WHERE (ld_clause_string).
Regards
Uwe -
Executing code on EXIT_ON_CLOSE
I was wondering how you execute code when a JFrame closes using the X button (ie, without using a menu). Because you don't attach an ActionListener to it, I am unsure as to where I would place code that I would like to execute before the program exits.
Thanksadd a WindowListener to the JFrame; windowClosing() will be called when the X is clicked (setDefaultAction is more or less just a convenience method for this)
-
Dear friends,
I would like to know how to execute code on closing the frame.JFrame frame = new JFrame();
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// Do here what you want ... }
frame.addWindowListener(l); -
How to execute Update Module FM after final commit work for a T-code.
Hello Folks,
I have a bit complex issue with my current object.
We have modified MM41/MM42 transactions and added a subscreen to fulfill the requirement.
We have designed the subscreen and embedded the same to MM41/MM42 through SPRO configuration.
Now for update business logic,i am trying to execute one Function module(Update Module) in update Task...so that it will be executed once after the final commit work will be done for MM41/MM42.
But its not executing.
To fulfill my requirement i need to execute the FM only after Final Commit work for MM41/MM42.
Please suggest in this regard.
Even i can see few BADI's which are triggering through MM01/MM02 but not through MM41/MM42.
BADI_ARTICLE_REF_RT
BADI_MATERIAL_CHECK
BADI_MAT_F_SPEC_SEL
Code with which i am trying is given below.
After PAI event of the subscreen---
1: MODULE USER_COMMAND_9001.
2: MODULE user_command_9001 INPUT.
PERFORM sub_save_mara ON COMMIT.
ENDMODULE.
3: FORM sub_save_mara.
CALL FUNCTION 'ZMMUPDATE_MARA_APPEND_STRUCT' "IN UPDATE TASK
EXPORTING
materialno = gv_matnr
appendmara = ty_zzmara.
ENDFORM. "sub_save_mara
4: FUNCTION zmmupdate_mara_append_struct.
""Update Function Module:
""Local Interface:
*" IMPORTING
*" VALUE(MATERIALNO) TYPE MATNR
*" VALUE(APPENDMARA) TYPE ZZMARA
Data Declaration for Local use
DATA : w_mara TYPE mara.
Selecting the latest values for the material.
SELECT SINGLE * FROM mara INTO w_mara WHERE matnr = materialno.
IF sy-subrc = 0.
Move the ZZMARA values to structure MARA
MOVE-CORRESPONDING appendmara TO w_mara.
Update the values in table MARA.
MODIFY mara FROM w_mara.
ENDIF.
ENDFUNCTION.
Kindly suggest.Thanks in advance.
Regards
AnsumeshHi..
The code given by me will work fine provided the Final commit should happen.
Because to execute FM with update task,final commit work should happen which is mandatory and after that it will call the update task.
In my case final commit work was not happeneing because..SAP standard program was not able to detect wether there is any change in my sub-screen or not as the standard program & my custom program,subscreens are different.
As it was not able to detect the change,so final commit was not happening and hence update task also.
To provide the reference of change in my subscreen to standard program ,i set a flag as per the change in the subscreen
And exported the same to memory.
Then Implemented one enhacement spot in MATERIAL_CHANGE_CHECK_RETAIL Fm where i have Imported the flag value.
Based on my custom flag value,i have set one standard flag FLG_AENDERUNG_GES which tells SAP standard program for MM42 wether any change has happened or not.
The above solved my purpose.
Regards
Ansumesh
Maybe you are looking for
-
Error when running a very simple java program
java.lang.NoClassDefFoundError: HelloWorldApp Exception in thread "main" Tool completed successfully I am getting the above error. I just downloaded java standard edition 1.4 sdk. I compiled the program with no errors. But when I run it . I get the a
-
LTE coverage Rockville, MD??
Recently moved to Rockville, MD and signed up for the iPhone 5c with Verizon. We'd been living overseas for a couple years so I was excited about my first spin on LTE. Unfortunately, so far I've been very disappointed in the coverage. Most places
-
Reg : HRA and PF Eligibility
Hello friends, We are implementing indian payroll. I got few doubts during configuring. can you please help me out. 1. Where should we ristrict PF eligibility = 6500? 2. If HRA = 40% of basic + 1000. Does it require to maintain Rs. 1000/- in raps tab
-
What I can do with this problem with wifi ?
If you can change or upgrade this script to solve this problem
-
Ship-to Address" screen in SRM browser need to change to display only
Hi Freinds, Ship-To Address" screen in SRM browser needs to change to "Display" only. The users shouldn´t have the possibility to change the delivery address in the screen to their own private address. Is it possbile to do any changes in SRM itself o