我有一个 JSF2 表单,其中一些字段定义为只读,尽管用户无法访问,但必须提交。我面临的问题是,当我提交表单时,只读字段评估为空。我阅读了 <h:inputText readonly="true"> 中的线程数据在单击命令按钮时消失了一些建议,但要么我不明白它们是如何工作的,要么我的表单有问题。
这是我的表格中的内容:
<h:inputTextarea  id="attLFld" value="#{cc.attrs.inc.attL}" rows="8" cols="40" 
         onblur="lookupL(this.value)" >
    <rich:validator/>
</h:inputTextarea>
<h:inputText  id="attLIFld" value="#{cc.attrs.inc.attLI}"   size="14"  readonly="true" />
<a4j:jsFunction name="lookupL" execute="attLFld"
        render="attLFld,attLIFld" 
        action="#{incController.lookupL}">        
</a4j:jsFunction>
这是我的控制器方法
public void lookupL()
{
   newInc.setAttLI("1234");
}
我尝试按照上面线程中的建议将带有只读标签的 inputText 字段设置为
<h:inputText  id="attLIFld" value="#{cc.attrs.inc.attLI}"   size="14"  readonly="#{facesContext.renderResponse}" />
但这对我不起作用。
不幸的是,这个建议对我不起作用。我认为我的表格有问题,但我看不出是什么。任何帮助都会非常受欢迎。
这是 xhtml 提取(我使用 Richfaces 4,顺便说一句)
<composite:implementation>
<h:panelGrid columns="3"   border="0">
<h:panelGrid columns="1" border="0">   
    <rich:panel id="rpA"> 
        <f:facet name="header">
            <h:outputText value="Field Group A"/>
        </f:facet>  
        <h:panelGrid columns="2" columnClasses="titleCell"   border="0">    
            <h:outputLabel for="fldA1" value="Field A1:" />
            <h:inputTextarea  id="fldA1" value="#{cc.attrs.mybean.fldA1}" rows="8" cols="40" immedite="true" onblur="lookup(this.value)" >
                <rich:validator/>
            </h:inputTextarea>              
            <h:outputLabel for="fldA2" value="Field A2:" />
            <h:inputText  id="fldA2" value="#{cc.attrs.mybean.fldA2}"   size="14"  readonly="true" />                       
            <h:outputLabel for="fldA3" value="Field A3:"/>
            <h:inputText  id="fldA3" value="#{cc.attrs.mybean.fldA3}"  readonly="#{facesContext.renderResponse}" size="14"/>            
        </h:panelGrid>           
    </rich:panel>    
</h:panelGrid>
<h:panelGrid id="pgButtons" columns="1" border="0">
    <a4j:commandButton type="button"  value=">>>>"  action="#{myBeanController.copyFields}"  immediate="true"
    execute="fldA1,fldA2,fldA2H,fldA3,fldA3H" 
    render="fldB1,fldB2,fldB3"/> 
 </h:panelGrid>
<rich:panel id="rpB"> 
        <f:facet name="header">
            <h:outputText value="Field Group B"/>
        </f:facet>  
        <h:panelGrid columns="2" columnClasses="titleCell"   border="0">    
            <h:outputLabel for="fldB1" value="Field B1:" />
            <h:inputTextarea  id="fldB1" value="#{cc.attrs.mybean.fldB1}" rows="8" cols="40" immediateue="true"  >
                <rich:validator/>
            </h:inputTextarea>              
            <h:outputLabel for="fldB2" value="Field B2:" />
            <h:inputText  id="fldB2" value="#{cc.attrs.mybean.fldB2}"   size="14"  readonly="true" />      
            <h:outputLabel for="fldB3" value="Field B3:"/>
            <h:inputText  id="fldB3" value="#{cc.attrs.mybean.fldB3}"  readonly="#{facesContext.renderResponse}" size="14"/>
        </h:panelGrid>           
    </rich:panel>    
</h:panelGrid>      
<div id="hiddenFields">
     <h:inputHidden value="#{cc.attrs.mybean.fldA2H}" id="fldA2H" />
     <h:inputHidden value="#{cc.attrs.mybean.fldA3H}" id="fldA3H"/>  
</div>
<a4j:jsFunction name="lookup" execute="fldA1"
    render="fldA1,fldA2,fldA3,,fldA2H,fldA3H" 
    action="#{myBeanController.lookup}">
  <a4j:param name="loc" assignTo="#{cc.attrs.mybean.fldA1}" />
</a4j:jsFunction>
</composite:implementation>
我在这里要做的是在字段 A1 中输入一些内容,然后填充 A2 和 A3 字段,然后单击按钮将所有这些 Ax 字段复制到 Bx 字段中。我可以做第一部分,但是当我单击按钮时,在控制器方法 copyFields 中,可见(但只读)和隐藏字段都评估为 null
@Model
public class MyBeanController {
  private MyBean newMBean;
   private MyBean mBean;
   @Produces
   @Named
   public MyBean getNewMBean()  {
      return newMBean;
   }
    @Produces
    @Named
    public MyBean getMBean() {
        return mBean;
    }
    public void setNewMBean(MyBean mBean) {
        this.mBean = mBean;
    }
    @PostConstruct
    public void initNewMBean() {
        newMBean = new MyBean();        
    }
    public void lookup()    {
        newMBean.setFldA2("boo");
        newMBean.setFldA2H("boo");
        newMBean.setFldA3("hoo");
        newMBean.setFldA3H("hoo");
    }
    public String copyFields()  {
        newMBean.setFldB1(newMBean.getFldA1());
        newMBean.setFldB2(newMBean.getFldA2H());
        newMBean.setFldB3(newMBean.getFldA3H());
        return null;
    }