Paint from a paint(Component) method? Is it possible?
Hi all
Here's my deal: I'd like to make a Paint (http://java.sun.com/javase/6/docs/api/java/awt/Paint.html) out of a component or even better, just something with a paint(Graphics) method. I looked into implementing my own Paint, but it looks very foreboding, esp the requirement to be able to get the Raster in the PaintContext object which I think I'd have to implement too.
Any advice?
Here's my attempt at it...
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.PaintContext;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.Raster;
import javax.swing.JComponent;
import javax.swing.JFrame;
import java.lang.reflect.Method;
public class ImagePaint implements Paint {
Object paintable;
Method paintMethod;
BufferedImage paint;
public ImagePaint(Object paintable) {
this.paintable = paintable;
try{
paintMethod =
paintable.getClass().getMethod("paint",Graphics.class);
}catch(java.lang.NoSuchMethodException e) {
throw new IllegalArgumentException("Paintable object does " +
"not have paint method!");
public java.awt.PaintContext createContext(ColorModel cm,
Rectangle deviceBounds,
Rectangle2D userBounds,
AffineTransform xform,
RenderingHints hints) {
/*the bounds being passed to this method is the bounding rectangle
*of the shape being filled or drawn*/
paint = new BufferedImage(deviceBounds.width,
deviceBounds.height,
BufferedImage.TYPE_3BYTE_BGR);
/*note: if translucent/transparent colors are used in the
*paintable object's "paint" method then the BufferedImage
*type will need to be different*/
Graphics2D g = paint.createGraphics();
/*set the clip size so the paintable object knows the
*size of the image/shape they are dealing with*/
g.setClip(0,0,paint.getWidth(),paint.getHeight());
//call on the paintable object to ask how to fill in/draw the shape
try {
paintMethod.invoke(paintable, g);
} catch (Exception e) {
throw new RuntimeException(
"Could not invoke paint method on: " +
paintable.getClass(), e);
return new ImagePaintContext(xform,
(int) userBounds.getMinX(),
(int) userBounds.getMinY());
public int getTransparency() {
/*Technically the transparency returned should be whatever colors are
*used in the paintable object's "paint" method. Since I'm just
*drawing an opaque cross with this aplication, I'll return opaque.*/
return java.awt.Transparency.OPAQUE;
public class ImagePaintContext implements PaintContext {
AffineTransform deviceToUser;
/*the upper left x and y coordinate of the where the shape is (in
*user space)*/
int minX, minY;
public ImagePaintContext(AffineTransform xform, int xCoor,
int yCoor){
try{
deviceToUser = xform.createInverse();
}catch(java.awt.geom.NoninvertibleTransformException e) {}
minX = xCoor;
minY = yCoor;
public Raster getRaster(int x, int y, int w, int h) {
/*find the point on the image that the device (x,y) coordinate
*refers to*/
java.awt.geom.Point2D tmp =
new java.awt.geom.Point2D.Double(x,y);
if(deviceToUser != null) {
deviceToUser.transform(tmp,tmp);
}else{
tmp.setLocation(0,0);
tmp.setLocation(tmp.getX()-minX,tmp.getY()-minY);
/*return the important portion of the image/raster in the
* coordinate space of the device.*/
return paint.getRaster().createChild((int) tmp.getX(),
(int) tmp.getY(),
w,h,x,y,null);
public ColorModel getColorModel() {
return paint.getColorModel();
public void dispose() {
paint = null;
public static void main(String[] args) {
/*as of java 1.6.10 d3d is enabled by default. The fillRect
* commands are significantly slower with d3d. I think this is
* a known bug. Also, with d3d enabled I get all sort
* weird painting artificats for this particular demonstration*/
System.setProperty("sun.java2d.d3d","false");
final ImagePaint paint = new ImagePaint(new Object() {
public void paint(Graphics g) {
Rectangle r = g.getClipBounds();
g.setColor(Color.white);
g.fillRect(r.x,r.y,r.width,r.height);
//draw a red cross
g.setColor(Color.red);
g.fillRect(r.width/2-20,0,40,r.height);
g.fillRect(0,r.height/2-20,r.width,40);
g.dispose();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent p = new JComponent() {
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(paint);
g2d.fillOval(getWidth()/3,getHeight()/3,
getWidth()/3,getHeight()/3);
g2d.dispose();
p.setPreferredSize(new Dimension(500,500));
f.setContentPane(p);
f.pack();
f.setVisible(true);
}I don't think the unresponsiveness from larger areas is necessarily due to your code. For all of my GUI applications, resizing an
already large frame tends to be prety sucky while resizing an already small frame tends to be pretty smooth.
Similar Messages
-
hi i have 2 classes one is my main and the other is the paint class with void paintcomponent() inside
how do i pass the x variable inside main class so i can use it inside the Map class
i know you can use scope e.g. Map map = new Map(x,y); but then i have to use a constructor with
its own repaint(); method inside but it does not work.
i was thinking of overloading a constructor aswell so inside one constructor is nothing and in the other with the (x, y) has
the repaint method inside but that doesn't work either.
main class
public class Main
public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
class MainFrame extends JFrame
private int x;
private int y;
// map class with paint component
Map map = new Map(x,y);
public MainFrame(){
this.add(map);
}paint class
public class Map extends JPanel {
private int x;
private int y;
public Map(){}
public Map(int x, int y){
this.x = x;
this.y = y;
repaint();
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}this does not work, any ideas?
Edited by: nicchick on Nov 25, 2008 1:00 AMum that wasnt exactly what i was looking for i have a better example
what im trying to do is pass/scope private varibles from the main class to the map class
but since you use repaint(); to call the paintcomponent override method theres no way to scope varibles like
x and y to panel?
this example shows what im trying to do with a mouselistener
main
public class Main
public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
class MainFrame extends JFrame
private int x;
private int y;
// map class with paint component
Map map = new Map();
// handler
HandlerMotion handler = new HandlerMotion();
public MainFrame(){
this.add(map);
map.addMouseMotionListener(handler);
private class HandlerMotion implements MouseMotionListener
public void mouseDragged(MouseEvent e) {
public void mouseMoved(MouseEvent e) {
x = e.getX();
y = e.getY();
new Map(x,y);
repaint();
}map
public class Map extends JPanel {
private int x;
private int y;
public Map(){}
public Map(int x, int y)
this.x = x;
this.y = y;
System.out.println("this is map" + x);
System.out.println("this is map" + y);
repaint();
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.drawLine(0, 0, x, y);
System.out.println("this is panel" + x);
System.out.println("this is panel" + y);
} -
Hi all
i have four classes plot , plot3d, plotsurface and test
plot is derived from JPanel and plot3d and plotsurface extend plot class
i am trying to do a very simple operation . just making a tool bar with 2 buttons to switch between plots .
the 2 plot classes plot3d and plotsurface just draw a line on the screen
problem is that when the user clicks one button it doesnot show up on the screen but when the window is resized it does call paint component of the corresponding class
can Any one explain why this is happening......
package test;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
public abstract class plot extends JPanel {
plot()
public void paintComponent(Graphics g)
Graphics2D graphics2D=(Graphics2D)g;
super.paintComponent(g);
package test;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
public class plot3d extends plot {
plot3d(boolean resizable)
public void paintComponent(Graphics g)
Graphics2D graphics2D=(Graphics2D)g;
super.paintComponent(g);
graphics2D.drawLine(200,200,320,320);
package test;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
public class plotsurface extends plot {
plotsurface(boolean resizable)
public void paintComponent(Graphics g)
Graphics2D graphics2D=(Graphics2D)g;
super.paintComponent(g);
graphics2D.drawLine(120,120,140,140);
package test;
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics2D.*;
import java.applet.*;
public class Test extends javax.swing.JApplet {
private Container container;
public Rectangle rect;
JPanel toolBar;
JButton contourButton;
JButton surfaceButton;
JPanel toolPanel;
public Graphics g;
public test.plot3d graph3D;
public test.plotsurface graphSurface;
private int plotType=0;
private void graph3D(Graphics2D g2)
graph3D=new plot3d(false);
public void graphSurface(Graphics2D g2)
graphSurface=new plotsurface(false);
private void changeplottoContour()
if(plotType==0)
return;
plotType=0;
g=container.getGraphics();
Graphics2D g2=(Graphics2D)g;
container.removeAll();
repaint();
graphSurface=null;
System.gc();
graph3D(g2);
container.add(toolPanel,BorderLayout.NORTH);
container.add(graph3D,BorderLayout.CENTER);
private void changeplottoSurface()
if(plotType==1)
return;
plotType=1;
g=container.getGraphics();
Graphics2D g2=(Graphics2D)g;
container.removeAll();
repaint();
graph3D=null;
System.gc();
graphSurface(g2);
container.add(toolPanel,BorderLayout.NORTH);
container.add(graphSurface,BorderLayout.CENTER);
private void surfaceButtonActionPerformed(java.awt.event.ActionEvent evt)
changeplottoSurface();
repaint();
private void contourButtonActionPerformed(java.awt.event.ActionEvent evt)
changeplottoContour();
repaint();
public void init()
container=getContentPane();
g=container.getGraphics();
Graphics2D g2=(Graphics2D)g;
Rectangle r1= new Rectangle();
rect=new Rectangle();
//r1=container.getBounds();
toolPanel= new JPanel(new BorderLayout());
toolBar = new JPanel();
contourButton = new JButton("Contour");
toolBar.add(contourButton);
contourButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
contourButtonActionPerformed(evt);
surfaceButton = new JButton("Surface Plot");
toolBar.add(surfaceButton);
surfaceButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
surfaceButtonActionPerformed(evt);
toolBar.setBackground(Color.white);
toolPanel.add(toolBar,BorderLayout.NORTH);
container.add(toolPanel,BorderLayout.NORTH);
Rectangle r2= toolPanel.getBounds();
Dimension appletSize = this.getSize();
int appletHeight= appletSize.height;
int appletWidth= appletSize.width;
rect.setBounds(0,(int)r2.getHeight(),appletWidth,appletHeight-(int)r2.getHeight());
plotType=0;
graph3D(g2);
container.add(graph3D,BorderLayout.CENTER);in your button action listeneres (e.g. contourButtonActionPerformed()) don't only call repaint(), but update(this.getGraphics());
this should help in most cases. other refreshing methods are:
java -Dsun.java2d.noddraw=true HelloWorld
java.awt.Component.repaint()
java.awt.Component.update(Graphics) (e.g. c.update(c.getGraphics());)
java.awt.Component.validate()
javax.swing.JComponent.revalidate()
javax.swing.JComponent.updateUI()
javax.swing.SwingUtilities.updateComponentTreeUI(java.awt.Component) -
Hi guys,
I will start with the original problem and get to the only option that seems possible before hardcoding everything.
I need to draw something like a binary tree. Jtree doesn't fall into binary because it does not have the root in the center. <1;2;6;8;9>, where 6 is the root, and 1,2 are its left child's children and 8,9 are right child's children. Since I couldn't find any possible solution of customizing JTree to draw it in binary format, I am left with the following option that is a step towards hardcoding.
Create a subclass of JPanel and paint inside it. The full hardcode method would be to draw everything right here, ie the lines and the boxes.
But since I need to listen to box selections using mouse, I was hoping to draw the boxes using JPanel/JLabel and override their paint() method.
So is there a way to paint components(JLabel/JPanel and lines) into a painted component (JPanel)? Note, the container JPanel is not using any layout. everything is being drawn using paint method.You are probably going to want to create smaller objects that handle their own painting. For example... Create an extension of JComponent that handles painting a single node. Then create the JPanel to add those to. You can even go as far as writing your own LayoutManager to handle laying the Components out in your binary layout. This is really the most effective way to do it, especially if you want to be able to detect clicks and what not. You can just add MouseListener's to the individual components than.
Hope this helps,
Josh Castagno
http://www.jdc-software.com -
Cross-component: Call method of using component from within used component?
Hi,
I began diving into cross-component programming.
Meanwhile after having digged into some scenarios some questions came up to my mind that I am not able to answer myself. I would appreciate your help here!
Say we have to components. Comp A uses Comp B (hence, B is a component usage in A)
1) How to make them communicate not on a data level (via context binding) but on a process level, thus...
a) can I call A's method from within B? How is the approach on a general level? - as B can be used from totally different components (like A, A1, A2 ...)
b) perhaps the only way to do this is by firing events? If so, how can I react in A when an event in B (marked as interface event) gets fired? As it seems they do not get registered within A directly...
I guess the question seems to be a bit tricky. Nevertheless, I think there will be plenty of you out there who used to asked them the same questions before and came up with an approach. Would be nice to hear from you.
Best wishes,
Marc @sap1Hi,
thanks for your reply!
Indeed, I think the nature of WDA would be just to somehow map the context from the used component to the other back and forth.
Nevertheless, what if I would like to invoke a method of the using component from inside the used component.
One sample for this requirement could be e.g.:
Component B offers a tree item and a send/verify button.
Component A uses B and has some restraints regarding what the selection should look like.
The user taps the button in B (at runtime in the view container of A), the context gets updated in A and B and in Component A the verifyWithOwnConstraints() method gets called (through B).
Thanks again,
Marc -
Issue with "firstRecord" Business Component method of JAVA Data bean API.
Hi,
Following is my use-case scenario:
I have to add or associate child MVG business component (CUT_Address)
with the parent business component (Account) using JAVA Data bean API.
My requirement is: first to check whether child business component(i.e. CUT_address) exists. If it exists then associate it with parent business component (Account)
otherwise create new CUT_address and associate it with account.
Code (using JAVA Data bean APIs) Goes as follows:
SiebelBusObject sBusObj = connBean.getBusObject("Account");
parentBusComp = sBusObj.getBusComp("Account");
SiebelBusComp parentBusComp;
SiebelBusComp childBusComp;
// retrieve required account.. Please assume Account1 exists
parentBusComp.activateField("Name");
parentBusComp.clearToQuery();
parentBusComp.setSearchSpec("Name", "Account1");
sBusComp.executeQuery2(true, true);
sBusComp.firstRecord();
Counter = 0;
while (counter < Number_Of_Child_Records_To_Insert)
childBusComp = parentBusComp.getMVGBusComp("City");
associatedChildBusComp = childBusComp.getAssocBusComp();
childBusComp.activateField("City");
childBusComp.clearToQuery();
childBusComp.setSearchSpec("City", Vector_of_city[counter]);
sBusComp.executeQuery2(true, true);
if( sBusComp.firstRecord() )
// Child already exist and do processing accordingly
else
// Child does not exist and do processing accordingly
childBusComp.release();
childBusComp = null;
associatedChildBusComp.release();
associatedChildBusComp=null;
Now the issue with this code is: For the first iteration, SbusComp.firstRecord returns 0 if records does not exist. However from the second iteration, SbusComp.firstRecord returns 1 even if there is no record matching the search specification.
Any input towards the issue is highly appreciable.
Thanks,
Rohit.Setting the view mode to "AllView" helped.
Thanks for the lead!
In the end, I also had to invoke the business component method SetAdminMode with "true" as the argument so that I could also modify the records from my script. -
Updating UI from outside SwingWorker-doInBackground() method
Good day!
I've a problem using SwingWorker class. I need to update user interface but not directly from doInBackground() method (a method is called from doInBackground() and this method should be able to update my UI). However, the only method offered by SwingWorker to update UI is publish() and it can't be used outside doInBackground(). Is there a way to solve my problem by using only SwingWorker methods or need I resort to invokeLater()/invokeAndWait() methods?
I'd appreciate any help.nice day,
for example:
invoke void or class from SwingWorker done() {} method
* Change the LAF and recreate the UIManagerDefaults so that the properties
* of the new LAF are correctly displayed.
class ChangeLookAndFeelAction extends AbstractAction {
private String laf;
protected ChangeLookAndFeelAction(String laf, String name) {
this.laf = laf;
putValue(Action.NAME, name);
putValue(Action.SHORT_DESCRIPTION, getValue(Action.NAME));
public void actionPerformed(ActionEvent e) {
try {
JMenuItem mi = (JMenuItem) e.getSource();
JPopupMenu popup = (JPopupMenu) mi.getParent();
JRootPane rootPane = SwingUtilities.getRootPane(popup.getInvoker());
Component c = rootPane.getContentPane().getComponent(0);
rootPane.getContentPane().remove(c);
UIManager.setLookAndFeel(laf);
KeyBindings bindings = new KeyBindings();
rootPane.getContentPane().add(bindings.getContentPane());
SwingUtilities.updateComponentTreeUI(rootPane);
rootPane.requestFocusInWindow();
} catch (Exception ex) {
System.out.println("Failed loading L&F: " + laf);
System.out.println(ex);
}maybe just enough to ... SwingUtilities.updateComponentTreeUI(), packed to the SwingUtilities.invokeLater(Runable run); -
How to get the string value from the RichSelectBooleanCheckBox component?
I added a validator to a RichSelectBooleanCheckBox component which is binded to a String attribute of a View Object.
I defined the mapping of boolean value to corresponding String value in the corresponding attribute binding in the page definition.
When the validate() method of my validator was invoked, the new value passed to the validate method() was a Boolean value instead of the converted String value.
I need to write validate() method generically so that it can handle more than one way of mapping boolean values to String values.
How can I get the converted String value in my validator method() from the RichBooleanCheckBox component that was also passed to the validate() method as a parameter?use:
int num = Integer.parseInt(s); -
Calling repricing from a global component
Hi ,
I want to invoke repricing from my global component,how should i do it.whatever way i found , it required some or other parameters which are not available globally.
Scenario :
In my requirement i need to remove some items from order using global components like Droplets,Processors etc.
I have extended CommerceItemManager's removeItemFromOrder method to suit my needs , the issue is that after remove item from order , i need to invoke repricing (which is automatically invoked when we use form handlers, but here this is not the case ).
i was thinking of calling :
getPurchaseProcessHelper().runProcessRepriceOrder(pPricingOperation, pOrder, pPricingModels, pLocale, pProfile, pExtraParameters, pErrorHandler)
how should i get pPricingModels, pLocale, pProfile, pExtraParameters, pErrorHandler params in my global components.
Note - I dont want to use RepriceOrderDroplet, i want to do it programatically.
Please suggest.
Thanks
~PraveerThis may help you.
================================================================
DynamoHttpServletRequest dynReq = ServletUtil.getCurrentRequest();
OrderHolder shoppingCart = (OrderHolder) dynReq.resolveName(getShoppingCartCompPath());
Profile profile = (Profile)dynReq.resolveName(getProfilePath());
OrderManager orderManager = (OrderManager)dynReq.resolveName(COMPPATH_ORDERMANAGER);
Locale localeVal = getLocale2reprice(shoppingCart.getCurrent(), dynReq);
PricingModelHolder userPricingModels = (PricingModelHolder) dynReq.resolveName(COMPPATH_PRICING_MODELS);
Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put(PRICING_OP, ORDER_TOTAL);
parameterMap.put(PRICING_MODELS, userPricingModels);
parameterMap.put(LOCALE, locale);
parameterMap.put(PROFILE, profile);
parameterMap.put(ORDER, shoppingCart.getCurrent());
parameterMap.put(COMPNAME_ORDERMANAGER, orderManager);
PipelineResult result = getPurchaseProcessHelper().getPipelineManager().runProcess(repriceChainIdName, parameterMap);
if(pipelineResult != null && pipelineResult.hasErrors()){
Object[] errors = pipelineResult.getErrors();
for (Object currError : errors){
//you would collect errors here; which can be passed to the invoker
private Locale getLocale2reprice(Order orderVal, DynamoHttpServletRequest dynReq){
Locale locale2reprice = null;
String localeVal = orderVal.getLocale();
if (localeVal == null){
RequestLocale reqLocaleVal = dynReq.getRequestLocale();
if (reqLocaleVal != null && reqLocaleVal.getLocaleString() != null){
localeVal = reqLocaleVal.getLocaleString();
if (localeVal != null){
locale2reprice = new Locale(localeVal);
return locale2reprice;
================================================================
NOTE: The respective profile & order components will be loaded for the logged-in customer.
So, dynReq.resolveName(profile/shoppingCart) will get the right values in the global scoped component.
Edited by: user1697061 on May 13, 2012 3:59 PM -
Reading/Setting Process Data Objects from Java Spring Component or XSLT
I have a BPMN process that references a Spring Component service.
The Spring service has a Java class and within that class I'd like to be able to reference process data objects of the BPMN process.
Ideally, I'd like to simply read and write to those objects within the Java class.
However, if that's not possible, I don't I can set input parameters on the Java class and have it return an object.
If I go that route, how can I pass in or return an object of a type other than your standard types (string, int, boolean)?
For example, I have a data object that is a type I created based on a schema.
How would I refer to that in a Java class?
Hope that makes sense.
Thanks,
MikeHi Adam.
I'm a little confused on the order of operations.
Here are the steps I took:
1. In JDeveloper, I created two Java classes: one interface and one class that implements it. Initially, the one method takes parameters that are Strings. I want it to also take a data type that's defined in a schema.
2. In the composite, drag Spring Context component onto screen. This opens the XML and here I define the <bean> that points to the two Java classes I just created.
3. In the composite, I create a pointer from the Spring component to Exposed Services and I create a new service, which creates the WSDL.
4. Now I edit the WSDL to import the schema that defines the type I want.
5. In my BPMN process, I add a call to the service I just created. For Data Associations, it recognizes the changes I made to the WSDL and I can map input variables to the new type added in step 4.
Here's where I'm stuck. In the actual Java class, I don't know how to add the parameter for the data type I created. Where is this Java object created?
Thanks,
Mike -
Not able to reload the data from DB using finder methods
Hi all,
<p>
I am facing a weird problem while using finder methods.
I am using weblogic 8.1 SP3 and entity beans are CMP with DB concurrency.DB is oracle
</p>
<h4>Problem Description</h4>
<p>
I am having one session bean which internally interacts with my entity beans,
Now say my transaction is getting initiated in one of the session bean and I use some finder in it.
</p>
<p>
To make the problem more clear lets say my entity bean is loanBean with loanId as primary key.
Now say method A of session bean initiates the transaction and I use something like
<br>
LoanLocal loanLocal =loanLocalHome.findByLoanId(loanId);
<br>
<b>Note that I am not using findByPrimaryKey method</b>
<br>
now this method A calls some other method B on some session bean which is having Required as its transaction attribute.
<br>
But before the call of B some other thread or background process updates the DB for this loanId and commits,
<br>
now when I fire the same finder in method B I am still getting the old data, ie I am not getting the data which has been modified in DB and committed by some other thread, I still get the old data and when I tried to generate the SQL queries which weblogic is firing, I see
it fires the SQL for every finder other that findByPrimaryKey.
<br>
<b>
Now my problem is I am getting the old data only and I need the new updated data of DB. isolation-level of DB and beans is READCOMMITTED.
Note:: I cant use new transaction to read the data.
</b>
<br>
And I couldn't understand that when weblogic is firing query for every finder then why it should not refresh the data in its cache. Is there any way to disable this kind of caching and say that everytime when i use finder just go to DB and get me the last committed data.
</p>
<br>
Any help in this regard would be very helpful to me.
<br>
Thanks and Regards
<br>
Manish Garg.
</p>Hi,
In my understanding, cache is not involved in this scenario. As you
observed, the container fires sql every time when you invoke this finder.
So, it should just give the result that it got from the DB. Is there a
possibility that the DB is using repeatable_read or serializable for
isolation level?
You can debug further by doing couple of things -
1. Instrument the code in the generated RDBMS java file for the entity bean
(if you use -keepgenerated option for weblogic.ejbc, u can get the source of
this file). This class will have the implementation for ejbFindByLoanId. You
can just print the result set data after the query is fired.
2. Try the same scenario without the ejb container. Like, write a jsp which
will start a user tx and fire the query twice such that there is an update
between the two queries. Note that, you need to use a TxDataSource to get
the JDBC connection so that it will be tx aware.
--Sathish
<Manish Garg> wrote in message news:[email protected]...
Hi all,
<p>
I am facing a weird problem while using finder methods.
I am using weblogic 8.1 SP3 and entity beans are CMP with DB
concurrency.DB is oracle
</p>
<h4>Problem Description</h4>
<p>
I am having one session bean which internally interacts with my entity
beans,
Now say my transaction is getting initiated in one of the session bean and
I use some finder in it.
</p>
<p>
To make the problem more clear lets say my entity bean is loanBean with
loanId as primary key.
Now say method A of session bean initiates the transaction and I use
something like
<br>
LoanLocal loanLocal =loanLocalHome.findByLoanId(loanId);
<br>
<b>Note that I am not using findByPrimaryKey method</b>
<br>
now this method A calls some other method B on some session bean which is
having Required as its transaction attribute.
<br>
But before the call of B some other thread or background process updates
the DB for this loanId and commits,
<br>
now when I fire the same finder in method B I am still getting the old
data, ie I am not getting the data which has been modified in DB and
committed by some other thread, I still get the old data and when I tried
to generate the SQL queries which weblogic is firing, I see
it fires the SQL for every finder other that findByPrimaryKey.
<br>
<b>
Now my problem is I am getting the old data only and I need the new
updated data of DB. isolation-level of DB and beans is READCOMMITTED.
Note:: I cant use new transaction to read the data.
</b>
<br>
And I couldn't understand that when weblogic is firing query for every
finder then why it should not refresh the data in its cache. Is there any
way to disable this kind of caching and say that everytime when i use
finder just go to DB and get me the last committed data.
</p>
<br>
Any help in this regard would be very helpful to me.
<br>
Thanks and Regards
<br>
Manish Garg.
</p> -
How to email text from a text component in my applet on a the host server ?
How to email text from a text component in my applet on a the host server, back to my email address ?
Assuming I have Email Form on the host server.
Help will be appreciated.You can do like below
=REPLACE(Fields!Column.Value," " & Parameters!ParameterName.value & " ","<b>" & Parameters!ParameterName.value & "</b>")
The select the expression and right click and choose placeholder properties
Inside that set Markup type as HTML
then it will highlight the passed parameter value in bold within the full xml string
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How can i redirect to my jsp page from servlet in init() method..Becoz that servlet is calling while server startsup..so im writing some piece of code in init() method..after that i want to redirect to some jsp page ...is it possible?
using RequestDispatcher..its not possible..becoz
RequestDispatcher rd = sc.getRequestDispatcher("goto.jsp");
rd.foward(req,res);
Here the request and response are null objects..
So mi question can frame as how can i get request/response in servlet's init method()..Hi guys
did any one get a solution for this issue. calling a jsp in the startup of the servlet, i mean in the startup servlet. I do have a same req like i need to call a JSP which does some data reterival and calculations and i am putting the results in the cache. so in the jsp there in no output of HTML. when i use the URLConnection i am getting a error as below.
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:707)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:705)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:519)
at com.toysrus.fns.alphablox.Startup.callJSP(Unknown Source)
at com.toysrus.fns.alphablox.Startup.init(Unknown Source)
at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
so plz do let me know how to call a jsp in the start up of a servlet.
Thanks
Vidya -
Changing states from within a component
Let's say that I have a TileList that is rendering data in a
VBox. Eventually the TileList fills up and starts scrolling. I want
to change states when clicking on item in the TileList.
I don't want to place the click-attribute in the TileList,
because it will change states when I am scrolling the list without
actually selecting anything.
I want to say click="currentState='state2'" inside the VBox,
but that does not work because state2 is at the root level, and I
don't know how to get to the root-level (in lack of a better word)
from withing the component.
This is not the proper syntax, so misunderstand me the right
way here... Is there an equivallence to
click="currentState='_root.state2'" in mxml?
Thanks for any suggestions or best practices. I want the easy
way out.
This is the general structure...
<mx:Application>
<mx:states>
<mx:State id="state1"/>
<mx:State id="state2"/>
<mx:State id="state3"/>
</mx:states>
<mx:TileList dataprovider="{...}">
<mx:itemRenderer>
<mx:component>
<mx:VBox id="ClickThisBoxToChangeStates">
<mx:Image/>
<mx:Label/>
</mx:Vbox>
</mx:component>
</mx:itemRenderer>
</mx:TileList>
</mx:Application>Your assumption is right.
It doesn't work because there is no state2-state defined
within the mx:component.
In the documentation about changing states it says that I can
go from application level and change states within a component;
like this: click="currentState='mycomponent.anotherstate'" but not
how I can change a state at application level from within a state.
When I try, it says (at runtime) that the state is not defined.
So I don't know why <mx:VBox
click="currentState='state2'"/> doesn't work.
I apprechiate your expertese a lot. -
How can I include a javaScript files from within jsf component
Is there any way using which I can include javascript files from my jsf component. Because otherwise I have to write all the javascript commands using writer.write which is very tedious rather than this I just want to include the javascript file which contains all the functions required. Also I want that this file should be included only once irrespective of the number of components included.
Thanx in advanceThis doesn't depend on JSF. You need to include a script tag, like:
<script src="/path/script.js"
language="JavaScript" type="text/javascript"></script>
If you want to include this only once, make a file included into every page, into which you can put other resources to be included along with this script.
HTH,
rs.
Maybe you are looking for
-
Can i email invoice to multiple customers who has email with bursting
Hi, I have a requirement that user will run range of invoices report thru Print invoice and email should be sent to only those customers which has email in customer profile and invoices related to only that customer. I have a XML publisher report dev
-
Too big a file???
My daughter is doing an anthology for her school. There is a page for each student. For each page she scans a writing sample, a drawing and a photo, saves them as TIFFs, and then puts them in the template she has made up. It's been saved as a continu
-
A/C Power Adapter for EUROPE
Hi All, Can anyone recommend an A/C Power adapter for my IBM Thinkpad T60, which I can plug into the European 2-Pin A/C outlet? I don't want to use converters because the A/C outlets where I am staying are recessed and the pins are not long enough t
-
How do I Programatically Check or Uncheck a Check Box
Hello, Could anyone help me with the code necessary to uncheck or check a checkbox on a form? Let's say there is a button, and I want that button when clicked to automatically check a check box. My actual goal is to have code that loops through all
-
Hello: I want to know if there is some way to see the temporal data that is store during the synchornization. The flow of the data when is store in the MI Server. It´s possible? Thanks Regards Mario