[Help] Upload File Component Problem

View: New views
5 Messages — Rating Filter:   Alert me  

[Help] Upload File Component Problem

by dodgers188 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear gurus,
I tried to follow example given in netbeans 6.0 kb about file upload component.
I have an error on line:
ServletContext theApplicationsServletContext = (ServletContext) this.getExternalContext().getContext();
it says cannot find symbol getContext();
I tried to remove the getContext() but it says inconvertible types.
Anybody can please help me?

/*
* Page1.java
*
* Created on Mar 27, 2008, 12:55:24 PM
*/

package uploadfile;

import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Body;
import com.sun.webui.jsf.component.Button;
import com.sun.webui.jsf.component.Form;
import com.sun.webui.jsf.component.Head;
import com.sun.webui.jsf.component.Html;
import com.sun.webui.jsf.component.Link;
import com.sun.webui.jsf.component.MessageGroup;
import com.sun.webui.jsf.component.Page;
import com.sun.webui.jsf.component.StaticText;
import com.sun.webui.jsf.component.Upload;
import javax.faces.FacesException;
import javax.servlet.ServletContext;

/**
*

Page bean that corresponds to a similarly named JSP page. This
* class contains component definitions (and initialization code) for
* all components that you have defined on this page, as well as
* lifecycle methods and event handlers where you may add behavior
* to respond to incoming events.
*
* @author Dwi Pamudji Soetedjo
*/
public class Page1 extends AbstractPageBean {
// <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

/**
*

Automatically managed component initialization. WARNING:
* This method is automatically generated, so any user-specified code inserted
* here is subject to being replaced.
*/
private void _init() throws Exception {
}

private Page page1 = new Page();

public Page getPage1() {
return page1;
}

public void setPage1(Page p) {
this.page1 = p;
}

private Html html1 = new Html();

public Html getHtml1() {
return html1;
}

public void setHtml1(Html h) {
this.html1 = h;
}

private Head head1 = new Head();

public Head getHead1() {
return head1;
}

public void setHead1(Head h) {
this.head1 = h;
}

private Link link1 = new Link();

public Link getLink1() {
return link1;
}

public void setLink1(Link l) {
this.link1 = l;
}

private Body body1 = new Body();

public Body getBody1() {
return body1;
}

public void setBody1(Body b) {
this.body1 = b;
}

private Form form1 = new Form();

public Form getForm1() {
return form1;
}

public void setForm1(Form f) {
this.form1 = f;
}
private Upload fileUpload1 = new Upload();

public Upload getFileUpload1() {
return fileUpload1;
}

public void setFileUpload1(Upload u) {
this.fileUpload1 = u;
}
private Button button1 = new Button();

public Button getButton1() {
return button1;
}

public void setButton1(Button b) {
this.button1 = b;
}
private StaticText staticText1 = new StaticText();

public StaticText getStaticText1() {
return staticText1;
}

public void setStaticText1(StaticText st) {
this.staticText1 = st;
}
private StaticText staticText2 = new StaticText();

public StaticText getStaticText2() {
return staticText2;
}

public void setStaticText2(StaticText st) {
this.staticText2 = st;
}
private StaticText staticText3 = new StaticText();

public StaticText getStaticText3() {
return staticText3;
}

public void setStaticText3(StaticText st) {
this.staticText3 = st;
}
private MessageGroup messageGroup1 = new MessageGroup();

public MessageGroup getMessageGroup1() {
return messageGroup1;
}

public void setMessageGroup1(MessageGroup mg) {
this.messageGroup1 = mg;
}

// </editor-fold>

/**
*

Construct a new Page bean instance.
*/
public Page1() {
}

/**
*

Callback method that is called whenever a page is navigated to,
* either directly via a URL, or indirectly via page navigation.
* Customize this method to acquire resources that will be needed
* for event handlers and lifecycle methods, whether or not this
* page is performing post back processing.
*
*

Note that, if the current request is a postback, the property
* values of the components do not represent any
* values submitted with this request. Instead, they represent the
* property values that were saved for this view when it was rendered.
*/

private String realImageFilePath;
private static final String IMAGE_URL = "/resources/image-file";
@Override
public void init() {
// Perform initializations inherited from our superclass
super.init();
// Perform application initialization that must complete
// before managed components are initialized
// TODO - add your own initialiation code here

// <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
// Initialize automatically managed components
// Note - this logic should NOT be modified
try {
_init();
} catch (Exception e) {
log("Page1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}

// </editor-fold>
// Perform application initialization that must complete
// after managed components are initialized
// TODO - add your own initialization code here
ServletContext theApplicationsServletContext = (ServletContext) this.getExternalContext().getContext();
this.realImageFilePath = theApplicationsServletContext.getRealPath(IMAGE_URL);

}

Re: [Help] Upload File Component Problem

by avbravo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

. You add import statements to fix these errors Right-click in the Java Editor and choose Fix Imports , you can press Ctrl-Shift-F to reformat the code.
dodgers188 wrote:
Dear gurus, I tried to follow example given in netbeans 6.0 kb about file upload component. I have an error on line: ServletContext theApplicationsServletContext = (ServletContext) this.getExternalContext().getContext(); it says cannot find symbol getContext(); I tried to remove the getContext() but it says inconvertible types. Anybody can please help me? /* * Page1.java * * Created on Mar 27, 2008, 12:55:24 PM */ package uploadfile; import com.sun.rave.web.ui.appbase.AbstractPageBean; import com.sun.webui.jsf.component.Body; import com.sun.webui.jsf.component.Button; import com.sun.webui.jsf.component.Form; import com.sun.webui.jsf.component.Head; import com.sun.webui.jsf.component.Html; import com.sun.webui.jsf.component.Link; import com.sun.webui.jsf.component.MessageGroup; import com.sun.webui.jsf.component.Page; import com.sun.webui.jsf.component.StaticText; import com.sun.webui.jsf.component.Upload; import javax.faces.FacesException; import javax.servlet.ServletContext; /** * Page bean that corresponds to a similarly named JSP page. This * class contains component definitions (and initialization code) for * all components that you have defined on this page, as well as * lifecycle methods and event handlers where you may add behavior * to respond to incoming events. * * @author Dwi Pamudji Soetedjo */ public class Page1 extends AbstractPageBean { // /** * Automatically managed component initialization. WARNING: * This method is automatically generated, so any user-specified code inserted * here is subject to being replaced. */ private void _init() throws Exception { } private Page page1 = new Page(); public Page getPage1() { return page1; } public void setPage1(Page p) { this.page1 = p; } private Html html1 = new Html(); public Html getHtml1() { return html1; } public void setHtml1(Html h) { this.html1 = h; } private Head head1 = new Head(); public Head getHead1() { return head1; } public void setHead1(Head h) { this.head1 = h; } private Link link1 = new Link(); public Link getLink1() { return link1; } public void setLink1(Link l) { this.link1 = l; } private Body body1 = new Body(); public Body getBody1() { return body1; } public void setBody1(Body b) { this.body1 = b; } private Form form1 = new Form(); public Form getForm1() { return form1; } public void setForm1(Form f) { this.form1 = f; } private Upload fileUpload1 = new Upload(); public Upload getFileUpload1() { return fileUpload1; } public void setFileUpload1(Upload u) { this.fileUpload1 = u; } private Button button1 = new Button(); public Button getButton1() { return button1; } public void setButton1(Button b) { this.button1 = b; } private StaticText staticText1 = new StaticText(); public StaticText getStaticText1() { return staticText1; } public void setStaticText1(StaticText st) { this.staticText1 = st; } private StaticText staticText2 = new StaticText(); public StaticText getStaticText2() { return staticText2; } public void setStaticText2(StaticText st) { this.staticText2 = st; } private StaticText staticText3 = new StaticText(); public StaticText getStaticText3() { return staticText3; } public void setStaticText3(StaticText st) { this.staticText3 = st; } private MessageGroup messageGroup1 = new MessageGroup(); public MessageGroup getMessageGroup1() { return messageGroup1; } public void setMessageGroup1(MessageGroup mg) { this.messageGroup1 = mg; } // /** * Construct a new Page bean instance. */ public Page1() { } /** * Callback method that is called whenever a page is navigated to, * either directly via a URL, or indirectly via page navigation. * Customize this method to acquire resources that will be needed * for event handlers and lifecycle methods, whether or not this * page is performing post back processing. * * Note that, if the current request is a postback, the property * values of the components do not represent any * values submitted with this request. Instead, they represent the * property values that were saved for this view when it was rendered. */ private String realImageFilePath; private static final String IMAGE_URL = "/resources/image-file"; @Override public void init() { // Perform initializations inherited from our superclass super.init(); // Perform application initialization that must complete // before managed components are initialized // TODO - add your own initialiation code here // // Initialize automatically managed components // Note - this logic should NOT be modified try { _init(); } catch (Exception e) { log("Page1 Initialization Failure", e); throw e instanceof FacesException ? (FacesException) e: new FacesException(e); } // // Perform application initialization that must complete // after managed components are initialized // TODO - add your own initialization code here ServletContext theApplicationsServletContext = (ServletContext) this.getExternalContext().getContext(); this.realImageFilePath = theApplicationsServletContext.getRealPath(IMAGE_URL); }

Re: [Help] Upload File Component Problem

by dodgers188 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I did fix imports and it says nothing to imports
What I don't get is reformat, I tried Ctrl + Shift + F but it will display Find Dialog Box..

. You add import statements to fix these errors
Right-click in the Java Editor and choose Fix Imports
, you can press Ctrl-Shift-F to reformat the code.

dodgers188 wrote:
Dear gurus,
I tried to follow example given in netbeans 6.0 kb about file upload component.
I have an error on line:
ServletContext theApplicationsServletContext = (ServletContext) this.getExternalContext().getContext();
it says cannot find symbol getContext();
I tried to remove the getContext() but it says inconvertible types.
Anybody can please help me?

/*
* Page1.java
*
* Created on Mar 27, 2008, 12:55:24 PM
*/

package uploadfile;

import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Body;
import com.sun.webui.jsf.component.Button;
import com.sun.webui.jsf.component.Form;
import com.sun.webui.jsf.component.Head;
import com.sun.webui.jsf.component.Html;
import com.sun.webui.jsf.component.Link;
import com.sun.webui.jsf.component.MessageGroup;
import com.sun.webui.jsf.component.Page;
import com.sun.webui.jsf.component.StaticText;
import com.sun.webui.jsf.component.Upload;
import javax.faces.FacesException;
import javax.servlet.ServletContext;

/**
*

Page bean that corresponds to a similarly named JSP page. This
* class contains component definitions (and initialization code) for
* all components that you have defined on this page, as well as
* lifecycle methods and event handlers where you may add behavior
* to respond to incoming events.
*
* @author Dwi Pamudji Soetedjo
*/
public class Page1 extends AbstractPageBean {
// <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

/**
*

Automatically managed component initialization. WARNING:
* This method is automatically generated, so any user-specified code inserted
* here is subject to being replaced.
*/
private void _init() throws Exception {
}

private Page page1 = new Page();

public Page getPage1() {
return page1;
}

public void setPage1(Page p) {
this.page1 = p;
}

private Html html1 = new Html();

public Html getHtml1() {
return html1;
}

public void setHtml1(Html h) {
this.html1 = h;
}

private Head head1 = new Head();

public Head getHead1() {
return head1;
}

public void setHead1(Head h) {
this.head1 = h;
}

private Link link1 = new Link();

public Link getLink1() {
return link1;
}

public void setLink1(Link l) {
this.link1 = l;
}

private Body body1 = new Body();

public Body getBody1() {
return body1;
}

public void setBody1(Body b) {
this.body1 = b;
}

private Form form1 = new Form();

public Form getForm1() {
return form1;
}

public void setForm1(Form f) {
this.form1 = f;
}
private Upload fileUpload1 = new Upload();

public Upload getFileUpload1() {
return fileUpload1;
}

public void setFileUpload1(Upload u) {
this.fileUpload1 = u;
}
private Button button1 = new Button();

public Button getButton1() {
return button1;
}

public void setButton1(Button b) {
this.button1 = b;
}
private StaticText staticText1 = new StaticText();

public StaticText getStaticText1() {
return staticText1;
}

public void setStaticText1(StaticText st) {
this.staticText1 = st;
}
private StaticText staticText2 = new StaticText();

public StaticText getStaticText2() {
return staticText2;
}

public void setStaticText2(StaticText st) {
this.staticText2 = st;
}
private StaticText staticText3 = new StaticText();

public StaticText getStaticText3() {
return staticText3;
}

public void setStaticText3(StaticText st) {
this.staticText3 = st;
}
private MessageGroup messageGroup1 = new MessageGroup();

public MessageGroup getMessageGroup1() {
return messageGroup1;
}

public void setMessageGroup1(MessageGroup mg) {
this.messageGroup1 = mg;
}

// </editor-fold>

/**
*

Construct a new Page bean instance.
*/
public Page1() {
}

/**
*

Callback method that is called whenever a page is navigated to,
* either directly via a URL, or indirectly via page navigation.
* Customize this method to acquire resources that will be needed
* for event handlers and lifecycle methods, whether or not this
* page is performing post back processing.
*
*

Note that, if the current request is a postback, the property
* values of the components do not represent any
* values submitted with this request. Instead, they represent the
* property values that were saved for this view when it was rendered.
*/

private String realImageFilePath;
private static final String IMAGE_URL = "/resources/image-file";
@Override
public void init() {
// Perform initializations inherited from our superclass
super.init();
// Perform application initialization that must complete
// before managed components are initialized
// TODO - add your own initialiation code here

// <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
// Initialize automatically managed components
// Note - this logic should NOT be modified
try {
_init();
} catch (Exception e) {
log("Page1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}

// </editor-fold>
// Perform application initialization that must complete
// after managed components are initialized
// TODO - add your own initialization code here
ServletContext theApplicationsServletContext = (ServletContext) this.getExternalContext().getContext();
this.realImageFilePath = theApplicationsServletContext.getRealPath(IMAGE_URL);

}


Re: [Help] Upload File Component Problem

by avbravo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

can you used the fileupload without:

ServletContext theApplicationsServletContext = (ServletContext) this.getExternalContext().getContext();
this.realImageFilePath = theApplicationsServletContext.getRealPath(IMAGE_URL);

Re: [Help] Upload File Component Problem

by dodgers188 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I tried not to use it but it won't display the image I uploaded.
I guess this servlet has something to do with showing the image.
Anything I can do?
avbravo wrote:
can you used the fileupload without:

ServletContext theApplicationsServletContext = (ServletContext) this.getExternalContext().getContext();
this.realImageFilePath = theApplicationsServletContext.getRealPath(IMAGE_URL);