小编csh*_*arp的帖子

价值与约束力的区别

使用值和JavaServer Faces绑定有什么区别,什么时候使用一个而不是另一个?为了更清楚我的问题,这里给出了几个简单的例子.

通常使用XHTML代码中的JSF,您可以使用"value",如下所示:

<h:form> 
  <h:inputText value="#{hello.inputText}"/>
  <h:commandButton value="Click Me!" action="#{hello.action}"/>
  <h:outputText value="#{hello.outputText}"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)

然后豆子是:

// Imports
@ManagedBean(name="hello")
@RequestScoped
public class Hello implements Serializable {

private String inputText;
private String outputText;

public void setInputText(String inputText) {
    this.inputText = inputText;
}

public String getInputText() {
    return inputText;
}

// Other getters and setters etc.

// Other methods etc.

public String action() {

    // Do other things

    return "success";
}
}
Run Code Online (Sandbox Code Playgroud)

但是,使用"绑定"时,XHTML代码是:

<h:form> 
  <h:inputText binding="#{backing_hello.inputText}"/>
  <h:commandButton value="Click Me!" action="#{backing_hello.action}"/>
  <h:outputText value="Hello!" binding="#{backing_hello.outputText}"/>
</h:form> …
Run Code Online (Sandbox Code Playgroud)

jsf

25
推荐指数
2
解决办法
4万
查看次数

<f:ajax render ="someId">不更新目标组件,但<f:ajax render ="@ form">工作正常

我在让Ajax正常工作时遇到问题.在我在这里的xhtml文件中,我使用Ajax来渲染某些输入被启用或禁用,并且它可以正常工作.但是,我还使用Ajax渲染一个包含xhtml文件,其中包含一个其他控件,并标记为id ="photoEnabled".如果未选中该复选框,则会在其位置显示由id ="photoDisabled"标记的虚拟显示,仅用于在页面上进行整洁的演示,并且已禁用.

由于某种原因,这不起作用,我不明白为什么.但是,如果我更换:

<h:selectBooleanCheckbox id="photometry" value="#{option1.photometry}">   
  <f:ajax event="click" render="photoEnabled photoDisabled" listener="# {option1.updateCheck}"/>   
</h:selectBooleanCheckbox>   

<!-- by -->   

<h:selectBooleanCheckbox id="photometry" value="#{option1.photometry}">   
  <f:ajax event="click" render="@form" listener="#{option1.updateCheck}"/>   
</h:selectBooleanCheckbox>  
Run Code Online (Sandbox Code Playgroud)

它确实工作正常,但问题是在页面上更进一步,这里没有显示,我有一些其他输入字段,当复选框的状态改变时,字段被清除,因为整个表单被渲染,我不要.

相关的xhtml代码在这里,显示了两个Ajax标签,一个工作,另一个没工作.

 <p:fieldset id="chooseOutput" legend="and choose your output:" style="text-align:left">   
    <h:commandButton id="popupChooseOutput" type="button" value="?" onclick="openPopup(420,370,'popups/helpOpt12')"  
                     styleClass="queryButton"/>   
    <p:panelGrid id="specphot" styleClass="textCentered" style="margin-left:auto; margin-right:auto">   
      <p:row>   
        <p:column colspan="2">   
          <span></span>   
        </p:column>   
        <p:column>   
          <h:outputText value="?<sub>1</sub>(Å)" escape="false"/>   
        </p:column>   
        <p:column>   
          <p:spacer width="2" height="0"/>   
        </p:column>   
        <p:column>   
          <h:outputText value="?<sub>2</sub>(Å)" escape="false"/>   
        </p:column>   
        <p:column>   
          <p:spacer width="2" height="0"/>   
        </p:column>   
        <p:column>   
          <h:outputText value="??(Å)" escape="false"/>   
        </p:column>   
        <p:column>   
          <p:spacer width="2" height="0"/>   
        </p:column> …
Run Code Online (Sandbox Code Playgroud)

ajax jsf

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

jsf ×2

ajax ×1