把Action.equals("Edit")判断放入
getTxt_Id();getTxt_Name();中

解决方案 »

  1.   

    怪就怪jsf 的ispostback不好用
      

  2.   

    /**
     * 
     */
    package pagecode.PoliticalRegion;import java.util.Map;import pagecode.PageCodeBase;
    import com.ibm.faces.component.html.HtmlScriptCollector;
    import javax.faces.component.html.HtmlForm;
    import com.ibm.faces.component.html.HtmlCommandExButton;
    import javax.faces.context.FacesContext;
    import javax.faces.component.html.HtmlInputText;
    import iTms.ModuleLogic.Region.*;
    import java.lang.*;/**
     * @author Administrator
     *
     */
    public class ProvinceAddEdit extends PageCodeBase { protected HtmlScriptCollector scriptCollector1;
    protected HtmlForm form1;
    protected HtmlCommandExButton btn_Add;
    protected HtmlCommandExButton btn_Edit;
    protected HtmlInputText txt_Id;
    protected HtmlInputText txt_Name;
    protected HtmlScriptCollector getScriptCollector1() {
    if (scriptCollector1 == null) {
    scriptCollector1 = (HtmlScriptCollector) findComponentInRoot("scriptCollector1");
    }
    return scriptCollector1;
    } protected HtmlForm getForm1() {
    if (form1 == null) {
    form1 = (HtmlForm) findComponentInRoot("form1");
    }
    return form1;
    } protected HtmlCommandExButton getBtn_Add() {
    if (btn_Add == null) {
    btn_Add = (HtmlCommandExButton) findComponentInRoot("btn_Add");
    }
    return btn_Add;
    } public void onPageLoadBegin(FacesContext facescontext) throws Throwable {
    /*
     * onPageLoadBegin事件中无法找到页面控件
    */
    } protected void ButtonSetUp(String action,FacesContext facescontext)
    {
    HtmlCommandExButton obtn_Add = getBtn_Add();
    HtmlCommandExButton obtn_Edit = getBtn_Edit();

    if (action=="Edit")
    {
    obtn_Add.setDisabled(false);
    obtn_Edit.setDisabled(true);
    }
    else
    {
    obtn_Add.setDisabled(true);
    obtn_Edit.setDisabled(false);
    }

    /*更新上下文*/
    obtn_Add.processUpdates(facescontext);
    obtn_Edit.processUpdates(facescontext);
    }

    protected void InitEditPage(FacesContext facescontext) throws Throwable
    {
    FacesContext Response = getFacesContext(); 

    HtmlInputText otxt_Id = getTxt_Id();
    HtmlInputText otxt_Name = getTxt_Name();

                      //能够取到数据库中的数据
    Province oProvince = Province.GetProvinceById(db, Long.parseLong(Id));

    if (oProvince != null)
    {
    otxt_Id.setValue(new Long(oProvince.getId()));
    otxt_Name.setValue(oProvince.getName());
    }

                      //打印出来数据完全正确
    facescontext.getResponseWriter().write("["+otxt_Id.getValue().toString()+","+otxt_Name.getValue().toString()+"]");
    }

    protected void InitAddPage(FacesContext facescontext) throws Throwable
    {
    HtmlInputText otxt_Id = getTxt_Id();
    HtmlInputText otxt_Name = getTxt_Name();

    otxt_Id.setValue("0");
    otxt_Name.setValue(""); facescontext.getResponseWriter().write("["+otxt_Id.getValue().toString()+","+otxt_Name.getValue().toString()+"]");
    }

    protected HtmlCommandExButton getBtn_Edit() {
    if (btn_Edit == null) {
    btn_Edit = (HtmlCommandExButton) findComponentInRoot("btn_Edit");
    }
    return btn_Edit;
    } protected HtmlInputText getTxt_Id() {
    if (txt_Id == null) {
    txt_Id = (HtmlInputText) findComponentInRoot("txt_Id");
    }
    return txt_Id;
    } protected HtmlInputText getTxt_Name() {
    if (txt_Name == null) {
    txt_Name = (HtmlInputText) findComponentInRoot("txt_Name");
    }
    return txt_Name;
    } public String doBtn_AddAction() {
    // 输入要在单击组件时运行的 Java 代码
    SaveData("Add");
    // TODO: 返回与导航规则相对应的结果
    HtmlInputText otxt_Id = getTxt_Id();
    HtmlInputText otxt_Name = getTxt_Name();

    otxt_Id.setValue("Add-Id");
    otxt_Name.setValue("Add-Name");
    return "";
    } public String doBtn_EditAction() {
    // 输入要在单击组件时运行的 Java 代码
    SaveData("Edit");
    // TODO: 返回与导航规则相对应的结果
    HtmlInputText otxt_Id = getTxt_Id();
    HtmlInputText otxt_Name = getTxt_Name();

    otxt_Id.setValue("Edit-Id");
    otxt_Name.setValue("Edit-Name");

    return "";
    } private void SaveData(String action)
    {
    HtmlInputText txt_Name = getTxt_Name();
    HtmlInputText txt_Id = getTxt_Id();

    Province oProvince = null;
    if (action.equals("Edit"))
    oProvince = Province.GetProvinceById(db, Long.parseLong((String)txt_Id.getValue()));
    else
    oProvince = new Province();

    long newId;
    oProvince.setName(txt_Name.getValue().toString());
    db.set(oProvince);

    if (action.equals("Add"))
    {
    newId = db.ext().getID(oProvince);
    oProvince.setId(newId);
    db.set(oProvince);
    }

    db.commit();
    } public void onPagePost(FacesContext facescontext) throws Throwable 
    {
    // 输入 Java 代码以在此处理页面记入事件
    } public void onPageLoadEnd(FacesContext facescontext) throws Throwable {

    //按钮安装
    ButtonSetUp(Action,facescontext);

    //初始化控件
    if (Action.equals("Edit"))
    InitEditPage(facescontext) ;
    else
    InitAddPage(facescontext) ;
    }
    }
    完整代码如上,实际显示出来的页面上的控件并无值。
      

  3.   

    估计是你的jsf配置有问题,要设置为客户端驻留信息才行
      

  4.   

    web.xml中已经是如下配置
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
      

  5.   

    看楼主的代码好吓人啊,JSF如果这么用,就失去了它的简单的原意了,
    没仔细分析楼主的代码,所以瞎说一句,你是不是没用页面元素和backbean的绑定啊?
      

  6.   

    你用的是IBM WebSphere框架啊我没用过不过你的情况应该是初始化时值还没有赋上去的缘故  
      

  7.   

    我看更像RAD也这个问题没有研究过